<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic K40 CAN Bus: Help Setting Bit Rate in Kinetis Microcontrollers</title>
    <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/K40-CAN-Bus-Help-Setting-Bit-Rate/m-p/183314#M1863</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi -&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm using CW10.2 w/ProcExp to set-up CAN Bus communications between two processors.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I seem to be having trouble setting up the timing.&amp;nbsp; For example, the 'Bit rate' parameter under 'Timing' only allows two values - 5851.429 bit/s and 1497.9657143 kbit/s.&amp;nbsp; I wish to set the rate to 1Mbit/s.&amp;nbsp; When I try to set it to a value between the two 'ranges', Processer Expert produces the error "Timing setting failed - it is impossible to set the following items: initialization value".&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any ideas?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 25 Jul 2012 23:30:11 GMT</pubDate>
    <dc:creator>sweng</dc:creator>
    <dc:date>2012-07-25T23:30:11Z</dc:date>
    <item>
      <title>K40 CAN Bus: Help Setting Bit Rate</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/K40-CAN-Bus-Help-Setting-Bit-Rate/m-p/183314#M1863</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi -&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm using CW10.2 w/ProcExp to set-up CAN Bus communications between two processors.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I seem to be having trouble setting up the timing.&amp;nbsp; For example, the 'Bit rate' parameter under 'Timing' only allows two values - 5851.429 bit/s and 1497.9657143 kbit/s.&amp;nbsp; I wish to set the rate to 1Mbit/s.&amp;nbsp; When I try to set it to a value between the two 'ranges', Processer Expert produces the error "Timing setting failed - it is impossible to set the following items: initialization value".&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any ideas?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 25 Jul 2012 23:30:11 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/K40-CAN-Bus-Help-Setting-Bit-Rate/m-p/183314#M1863</guid>
      <dc:creator>sweng</dc:creator>
      <dc:date>2012-07-25T23:30:11Z</dc:date>
    </item>
    <item>
      <title>Re: K40 CAN Bus: Help Setting Bit Rate</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/K40-CAN-Bus-Help-Setting-Bit-Rate/m-p/183315#M1864</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I don't know about PE but you can set up the optimal CAN clock in code by using the following formula:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;ptrCAN_control-&amp;gt;CAN_CTRL1 = fnOptimalCAN_clock(pars-&amp;gt;usMode, pars-&amp;gt;ulSpeed);&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Taken from uTasker Kinetis project:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;// The best choice of clock input is from the external crystal (lowest jitter), however this may not always enable the best settings to achieve the required speed.// The choice of clock source is user-defined but this routine tries to achieve best settings using highest time quanta resolution. //// There are up to 25 time quanta in a CAN bit time and the bit frequency is equal to the clock frequency divided by the quanta number (8..25 time quanta range)// There is always a single time quanta at the start of a bit period called the SYNC_SEG which can not be changed (transitions are expected to occur on the bus during this period)// The sampling occurs after time segment 1, which is made up of a propagation segment (1..8 time quanta) plus a phase buffer segment 1 (1..8 time quanta),// followed by time segment 2, made up of phase buffer segment 2 (2..8 time quanta)//// CAN standard compliant bit segment settings give the following ranges (re-synchronisation jump width of 2 is used since it is complient with all))// Time segment 1 should be 5..10 when time segment 2 is 2 (min/max time quanta per bit is 8/13)// Time segment 1 should be 4..11 when time segment 2 is 3 (min/max time quanta per bit is 8/15)// Time segment 1 should be 5..12 when time segment 2 is 4 (min/max time quanta per bit is 10/17)// Time segment 1 should be 6..13 when time segment 2 is 5 (min/max time quanta per bit is 12/19)// Time segment 1 should be 7..14 when time segment 2 is 6 (min/max time quanta per bit is 14/21)// Time segment 1 should be 8..15 when time segment 2 is 7 (min/max time quanta per bit is 16/23)// Time segment 1 should be 9..16 when time segment 2 is 8 (min/max time quanta per bit is 18/25)//static unsigned long fnOptimalCAN_clock(unsigned short usMode, unsigned long ulSpeed){    unsigned long ulClockSourceFlag = EXTAL_CLK_SOURCE;    unsigned long ulClockSpeed;    unsigned long ulLowestError = 0xffffffff;    unsigned long ulCanSpeed;    unsigned long ulError;    unsigned long ulPrescaler;    int iTimeQuanta = 25;                                                // highest value for highest control resolution    int iBestTimeQuanta = 25;    unsigned long ulBestPrescaler;    if (CAN_USER_SETTINGS &amp;amp; usMode) {        return ulSpeed;                                                  // the user is passing optimal configuration settings directly    }    if (CAN_PLL_CLOCK &amp;amp; usMode) {        ulClockSpeed = (BUS_CLOCK);        ulClockSourceFlag = CLK_SRC_PERIPH_CLK;    }    else {        ulClockSpeed = _EXTERNAL_CLOCK;    }    while (iTimeQuanta &amp;gt;= 8) {                                           // test for best time quanta        ulCanSpeed = (ulClockSpeed/iTimeQuanta);                         // speed without prescaler        ulPrescaler = ((ulCanSpeed + (ulSpeed/2))/ulSpeed);              // best prescale value        if (ulPrescaler &amp;gt; 256) {            ulPrescaler = 256;                                           // maximum possible prescale divider        }        ulCanSpeed /= ulPrescaler;        if (ulCanSpeed &amp;gt;= ulSpeed) {                                     // determine the absolute error value with this quanta setting            ulError = (ulCanSpeed - ulSpeed);        }        else {            ulError = (ulSpeed - ulCanSpeed);        }        if (ulError &amp;lt; ulLowestError) {                                   // if this is an improvement            ulLowestError = ulError;            iBestTimeQuanta = iTimeQuanta;                               // best time quanta value            ulBestPrescaler = ulPrescaler;        }        iTimeQuanta--;    }    ulBestPrescaler--;    ulBestPrescaler &amp;lt;&amp;lt;= 24;                                              // move the prescale value into position    if (iBestTimeQuanta &amp;gt;= 18) {                                         // determine the phase buffer length value        ulBestPrescaler |= PHASE_BUF_SEG2_LEN8;        iBestTimeQuanta -= (8 + 1);                                      // remaining time quanta (time segment 1) after removal of the time segment 2 and the SYN_SEG    }    else if (iBestTimeQuanta &amp;gt;= 16) {        ulBestPrescaler |= PHASE_BUF_SEG2_LEN7;        iBestTimeQuanta -= (7 + 1);    }    else if (iBestTimeQuanta &amp;gt;= 14) {        ulBestPrescaler |= PHASE_BUF_SEG2_LEN6;        iBestTimeQuanta -= (6 + 1);    }    else if (iBestTimeQuanta &amp;gt;= 12) {        ulBestPrescaler |= PHASE_BUF_SEG2_LEN5;        iBestTimeQuanta -= (5 + 1);    }    else if (iBestTimeQuanta &amp;gt;= 10) {        ulBestPrescaler |= PHASE_BUF_SEG2_LEN4;        iBestTimeQuanta -= (4 + 1);    }    else {        ulBestPrescaler |= PHASE_BUF_SEG2_LEN3;        iBestTimeQuanta -= (3 + 1);    }    if (iBestTimeQuanta &amp;amp; 0x1) {                                         // odd        iBestTimeQuanta /= 2;                                            // PROP_SEG and PSEG1 to achieve time segment 1        ulBestPrescaler |= iBestTimeQuanta;                              // set propogation bit time (1 more than phase buffer segment 1)        iBestTimeQuanta--;        ulBestPrescaler |= (iBestTimeQuanta &amp;lt;&amp;lt; 19);                      // set phase buffer segment 1    }    else {                                                               // even        iBestTimeQuanta /= 2;                                            // PROP_SEG and PSEG1 to achieve time segment 1 and phase buffer segment 1        iBestTimeQuanta--;        ulBestPrescaler |= ((iBestTimeQuanta &amp;lt;&amp;lt; 19) | (iBestTimeQuanta));// set equal propogation bit times    }    return (RJW_2 | ulClockSourceFlag | ulBestPrescaler);                // initialise the CAN controller with the required speed and parameters}&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Mark&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 29 Oct 2020 09:34:09 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/K40-CAN-Bus-Help-Setting-Bit-Rate/m-p/183315#M1864</guid>
      <dc:creator>mjbcswitzerland</dc:creator>
      <dc:date>2020-10-29T09:34:09Z</dc:date>
    </item>
  </channel>
</rss>

