<?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>S12 / MagniV MicrocontrollersのトピックRe: Arduino TMILLIS() similar function?</title>
    <link>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/Arduino-TMILLIS-similar-function/m-p/1257001#M17795</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;Two things:&lt;/P&gt;
&lt;P&gt;1) you have not mentioned MCU type&lt;/P&gt;
&lt;P&gt;2) Such function is neither a part of the standard C language package nor assembler.&lt;/P&gt;
&lt;P&gt;You can use ProcessorExpert&amp;nbsp; (pat of the CodeWarrior) for such purpose which enables you to set the timer on the base of your requirements and use some implemented higher level functions.&lt;/P&gt;
&lt;P&gt;Otherwise, you should know what is a timer, how it depends on bus clock, how to set it, whether and how to use interrupt functions from it, program backup millisecond timer routine or only flag ms has gone. This is, however, application problem.&lt;/P&gt;
&lt;P&gt;Short example follows which presents period generator which generates 3 periods by 3 different peripherals inside the S12XEP100 device and toggles pins each time when period finishes.&lt;/P&gt;
&lt;P&gt;Best regards, Ladislav&lt;/P&gt;
&lt;P&gt;//******************************************************************************&lt;BR /&gt;// periodic interrupt generator 1 : uses MDDC - modulus down counter &lt;BR /&gt;// Modulus down counter counts once with given period.&lt;BR /&gt;// The periodic interrupt is started by function StartMDC&lt;BR /&gt;// The periodic interrupt can be stopped by function StopMDC&lt;BR /&gt;// The pin PB0 toggled within interrupt.&lt;BR /&gt;//-----------&lt;BR /&gt;// periodic interrupt generator 2 : uses a timer&lt;BR /&gt;// interval = TCx * dt = TCx * (prescaler/fbus)&lt;BR /&gt;// TCx = interval / (prescaller/fbus) = interval * fbus / prescaler&lt;BR /&gt;// When 50MHz BUSCLK is used then we are able to set by means of standard prescaller:&lt;BR /&gt;// dt = 1/50,000,000 * prescaller&lt;BR /&gt;// let select prescaller = 8 and required internval is 0.01s =&amp;gt; &lt;BR /&gt;// =&amp;gt; TCx = 0.01*50,000,000/8 = 62500&lt;BR /&gt;// Channel 4 is used to catch period. The timer is disconnected from PT4 pin. &lt;BR /&gt;// The interrupt is launched periodically each 10ms.&lt;BR /&gt;// The periodic interrupt is started by function StartTIM&lt;BR /&gt;// The periodic interrupt can be stopped by function StopTIM&lt;BR /&gt;// The pin PB1 toggled within interrupt.&lt;BR /&gt;//-----------&lt;BR /&gt;// periodic interrupt generator 3: uses a PIT - periodic interrupt timer&lt;BR /&gt;// Periodic Interrupt Timer 0 is used to generate 10ms periodic interrupt.&lt;BR /&gt;// time-out period0 = (PITMTLD + 1) * (PITLD + 1) / fBUS = (199+1)* (2499+1) / 50,000,000 = 0.01s&lt;BR /&gt;// The periodic interrupt is started by function StartPIT0&lt;BR /&gt;// The periodic interrupt can be stopped by function StopPIT0&lt;BR /&gt;// The pin PB2 toggled within interrupt.&lt;/P&gt;
&lt;P&gt;//******************************************************************************&lt;/P&gt;
&lt;P&gt;//******************************************************************************&lt;BR /&gt;#include &amp;lt;hidef.h&amp;gt; /* common defines and macros */&lt;BR /&gt;#include &amp;lt;mc9s12xep100.h&amp;gt; /* derivative information */&lt;BR /&gt;//******************************************************************************&lt;BR /&gt;#pragma LINK_INFO DERIVATIVE "mc9s12xep100"&lt;BR /&gt;//******************************************************************************&lt;BR /&gt;#define UBYTE unsigned char&lt;BR /&gt;#define UWORD unsigned int&lt;BR /&gt;#define ULONG unsigned long&lt;BR /&gt;//******************************************************************************&lt;BR /&gt;//******************************************************************************&lt;BR /&gt;// local function prototypes&lt;BR /&gt;//******************************************************************************&lt;BR /&gt;static void PLL_Init(unsigned char synr, unsigned char refdv, unsigned char postdiv);&lt;BR /&gt;//--------------------------&lt;BR /&gt;static void MDC_Init(void);&lt;BR /&gt;static void StartMDC(void);&lt;BR /&gt;static void StopMDC(void);&lt;BR /&gt;//--------------------------&lt;BR /&gt;static void TIM_Init(void);&lt;BR /&gt;static void StartTIM(void);&lt;BR /&gt;static void StopTIM(void);&lt;BR /&gt;//--------------------------&lt;BR /&gt;static void PIT0_Init(void);&lt;BR /&gt;static void StartPIT0(void);&lt;BR /&gt;static void StopPIT0(void);&lt;BR /&gt;//******************************************************************************&lt;BR /&gt;#pragma CODE_SEG DEFAULT&lt;BR /&gt;//------------------------------------------------------------------------------&lt;BR /&gt;static void MDC_Init(void)&lt;BR /&gt;{&lt;BR /&gt;// Time interval = Tbus / Prescaller {1;4;8;16} * MCCNT&lt;BR /&gt;// Enable ISR from MDC, Continue MDC when reaches 0, prescaler 8, &lt;BR /&gt;ECT_MCCTL = ECT_MCCTL_MCZI_MASK | ECT_MCCTL_MODMC_MASK | 2;&lt;BR /&gt;}&lt;BR /&gt;//------------------------------------------------------------------------------&lt;BR /&gt;static void StartMDC(void) // interval [us] Modullus Down Counter&lt;BR /&gt;{ &lt;BR /&gt;ECT_MCFLG_MCZF = 1; // clear interrupt flag&lt;BR /&gt;ECT_MCCTL_MCEN = 1;&lt;BR /&gt;ECT_MCCNT = 62500; // 10ms period at 50MHz BUSCLK&lt;BR /&gt;ECT_MCCTL_FLMC = 1;&lt;BR /&gt;}&lt;BR /&gt;//------------------------------------------------------------------------------&lt;BR /&gt;static void StopMDC(void) // interval [us] Modullus Down Counter&lt;BR /&gt;{ &lt;BR /&gt;ECT_MCCTL_MCEN = 0; // stop MDC&lt;BR /&gt;}&lt;BR /&gt;//------------------------------------------------------------------------------&lt;BR /&gt;#pragma CODE_SEG NON_BANKED&lt;BR /&gt;//------------------------------------------------------------------------------&lt;BR /&gt;interrupt 26 void ModulusDownCounterIsr(void)&lt;BR /&gt;{&lt;BR /&gt;ECT_MCFLG_MCZF = 1; // clear interrupt flag&lt;BR /&gt;PORTB_PB0 = ~PORTB_PB0; &lt;BR /&gt;}&lt;BR /&gt;//******************************************************************************&lt;BR /&gt;#pragma CODE_SEG DEFAULT&lt;BR /&gt;//------------------------------------------------------------------------------&lt;BR /&gt;static void TIM_Init(void)&lt;BR /&gt;{&lt;BR /&gt;TIM_TSCR2 = 0x03; // prescaller = 8&lt;BR /&gt;//--- channel 4 setup ---------------&lt;BR /&gt;TIM_TIOS_IOS4 = 1; // channel 4 is output compare &lt;BR /&gt;TIM_TCTL1 = 0x00; // no output compare action at channel 4 on compare&lt;BR /&gt;TIM_OCPD_OCPD4 = 1; // channel 4 disconnected from output pin logic&lt;BR /&gt;//-----------------------------------&lt;BR /&gt;TIM_TIE_C4I = 0; // disable interrupt from channel 4&lt;BR /&gt;//-----------------------------------&lt;BR /&gt;TIM_TSCR1 = 0xE0; // enable timer,stop in wait,stop in freeze, no fast flag clear&lt;BR /&gt;}&lt;BR /&gt;//------------------------------------------------------------------------------&lt;BR /&gt;static void StartTIM(void) // 10ms period at 50MHz BUSCLK&lt;BR /&gt;{ &lt;BR /&gt;TIM_TFLG1 = 0x10; // clear interrupt flag from channel 4&lt;BR /&gt;TIM_TC4 = TIM_TCNT + 62500; // set new value and clear interrupt flag &lt;BR /&gt;TIM_TIE_C4I = 1; // enable interrupt from channel 4&lt;BR /&gt;}&lt;BR /&gt;//------------------------------------------------------------------------------&lt;BR /&gt;static void StopTIM(void) //&lt;BR /&gt;{ &lt;BR /&gt;TIM_TIE_C4I = 0; // disable interrupt from channel 4&lt;BR /&gt;}&lt;BR /&gt;//------------------------------------------------------------------------------&lt;BR /&gt;#pragma CODE_SEG NON_BANKED&lt;BR /&gt;//------------------------------------------------------------------------------&lt;BR /&gt;interrupt 89 void TC4_Isr(void)&lt;BR /&gt;{ // 10ms period at 50MHz BUSCLK&lt;BR /&gt;TIM_TFLG1 = 0x10; // clear interrupt flag from channel 4&lt;BR /&gt;TIM_TC4 = TIM_TCNT + 62500; // set new value and clear interrupt flag &lt;BR /&gt;PORTB_PB1 = ~PORTB_PB1; &lt;BR /&gt;}&lt;BR /&gt;//******************************************************************************&lt;BR /&gt;#pragma CODE_SEG DEFAULT&lt;BR /&gt;//------------------------------------------------------------------------------&lt;BR /&gt;static void PIT0_Init(void)&lt;BR /&gt;{&lt;BR /&gt;//--- PIT0 -------------------------------&lt;BR /&gt;// clock period is set 10ms&lt;BR /&gt;// time-out period0 = (PITMTLD + 1) * (PITLD + 1) / fBUS = (199+1)* (2499+1) / 50,000,000 = 0.01s&lt;BR /&gt;PITMUX_PMUX0 = 0; // microtimer 0 for PIT0&lt;BR /&gt;PITMTLD0 = 199; // microtimer (prescaller) value&lt;BR /&gt;PITLD0 = 2499; // PIT0 timer interval&lt;BR /&gt;PITCFLMT = 0xE0; // Enable PIT module,stop in wait,stop in freeze&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;PITINTE_PINTE0 = 0; // Disable PIT0 interrupt to generate 10 ms&lt;BR /&gt;PITCE_PCE0 = 1; // Enable PIT0&lt;BR /&gt;}&lt;BR /&gt;//------------------------------------------------------------------------------&lt;BR /&gt;static void StartPIT0(void) &lt;BR /&gt;{ &lt;BR /&gt;PITTF = PITTF_PTF0_MASK; // Clear interrupt flag from PIT0 &lt;BR /&gt;PITCFLMT_PFLMT0 = 1; // reload microtimer 0&lt;BR /&gt;PITFLT_PFLT0 = 1; // reload PIT0 counter&lt;BR /&gt;PITINTE_PINTE0 = 1; // Enable PIT0 interrupt to generate 10 ms&lt;BR /&gt;}&lt;BR /&gt;//------------------------------------------------------------------------------&lt;BR /&gt;static void StopPIT0(void) &lt;BR /&gt;{ &lt;BR /&gt;PITINTE_PINTE0 = 0; // Disable PIT0 interrupt to generate 10 ms&lt;BR /&gt;}&lt;BR /&gt;//------------------------------------------------------------------------------&lt;BR /&gt;#pragma CODE_SEG NON_BANKED&lt;BR /&gt;//------------------------------------------------------------------------------&lt;BR /&gt;interrupt 66 void PIT0_Isr(void)&lt;BR /&gt;{&lt;BR /&gt;PORTB_PB2 = ~PORTB_PB2; &lt;BR /&gt;PITTF = PITTF_PTF0_MASK; // Clear interrupt flag PIT0 &lt;BR /&gt;}&lt;BR /&gt;//******************************************************************************&lt;BR /&gt;#pragma CODE_SEG DEFAULT&lt;BR /&gt;//------------------------------------------------------------------------------&lt;BR /&gt;static void PLL_Init(unsigned char synr, unsigned char refdv, unsigned char postdiv)&lt;BR /&gt;{&lt;BR /&gt;PLLCTL = 0B00000001; // CME=0,PLLON=0,FM1=0,FM2=0,FSTWKP=0,PRE=0,PCE=0,SCME=1&lt;BR /&gt;CLKSEL = 0B00000011; // PLLSEL=0,PSTP=0,PLLWAI=0,RTIWAI=1,COPWAI=1&lt;BR /&gt;SYNR = synr; // Set the multiplier register&lt;BR /&gt;REFDV = refdv; // Set the divider register&lt;BR /&gt;POSTDIV = postdiv; // Set the post divider register&lt;BR /&gt;PLLCTL_PLLON = 1; // Enable the Phase Lock Loop&lt;BR /&gt;while(!CRGFLG_LOCK); // Wait till the PLL VCO is within tolerance&lt;BR /&gt;CLKSEL_PLLSEL = 1; // Select clock source from PLLCLK&lt;BR /&gt;//ECLKCTL_NECLK=0; // Enable the BusClk output at ECLK pin&lt;BR /&gt;}&lt;BR /&gt;//******************************************************************************&lt;/P&gt;
&lt;P&gt;void main(void) &lt;BR /&gt;{&lt;BR /&gt;ULONG i;&lt;BR /&gt;//..................................&lt;BR /&gt;PLL_Init(0xC4,0x80,0x00);&lt;BR /&gt;//..................................&lt;BR /&gt;DDRB = 0x07; // PB0,1,2 an output&lt;BR /&gt;PORTB = 0x00; // inactive state of PB0 &lt;BR /&gt;//..................................&lt;BR /&gt;MDC_Init();&lt;BR /&gt;TIM_Init();&lt;BR /&gt;PIT0_Init();&lt;BR /&gt;//..................................&lt;BR /&gt;EnableInterrupts;&lt;BR /&gt;//..................................&lt;BR /&gt;StartMDC();&lt;BR /&gt;// StopMDC();&lt;BR /&gt;StartTIM();&lt;BR /&gt;// StopTIM();&lt;BR /&gt;StartPIT0();&lt;BR /&gt;// StopPIT0();&lt;BR /&gt;for(;;)&lt;BR /&gt;{&lt;BR /&gt;for(i=0;i&amp;lt;1000000UL;i++) // SW delay&lt;BR /&gt;{&lt;BR /&gt;asm nop;asm nop;asm nop;asm nop;asm nop;asm nop;asm nop;asm nop;asm nop;asm nop; &lt;BR /&gt;}&lt;BR /&gt;StopMDC();&lt;BR /&gt;StopTIM();&lt;BR /&gt;StopPIT0();&lt;/P&gt;
&lt;P&gt;for(i=0;i&amp;lt;1000000UL;i++) // SW delay&lt;BR /&gt;{&lt;BR /&gt;asm nop;asm nop;asm nop;asm nop;asm nop;asm nop;asm nop;asm nop;asm nop;asm nop; &lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;StartMDC();&lt;BR /&gt;StartTIM();&lt;BR /&gt;StartPIT0();&lt;BR /&gt;}&lt;BR /&gt;//........................................&lt;BR /&gt;}&lt;BR /&gt;//******************************************************************************&lt;BR /&gt;// Services performed by FREESCALE in this matter are performed AS IS and without any warranty. CUSTOMER retains&lt;BR /&gt;// the final decision relative to the total design and functionality of the end product. FREESCALE neither&lt;BR /&gt;// guarantees nor will be held liable by CUSTOMER for the success of this project.&lt;BR /&gt;// FREESCALE DISCLAIMS ALL WARRANTIES, EXPRESSED, IMPLIED OR STATUTORY INCLUDING, BUT NOT LIMITED TO, IMPLIED&lt;BR /&gt;// WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE ON ANY HARDWARE, SOFTWARE ORE ADVISE SUPPLIED&lt;BR /&gt;// TO THE PROJECT BY FREESCALE, AND OR NAY PRODUCT RESULTING FROM FREESCALE SERVICES . IN NO EVENT SHALL FREESCALE&lt;BR /&gt;// BE LIABLE FOR INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT.&lt;BR /&gt;//&lt;BR /&gt;// CUSTOMER agrees to hold FREESCALE harmless against any and all claims demands or actions by anyone on account of&lt;BR /&gt;// any damage, or injury, whether commercial, contractual, or tortuous, rising directly or indirectly as a result of&lt;BR /&gt;// the advise or assistance supplied CUSTOMER in connection with product, services or goods supplied under this Agreement.&lt;BR /&gt;//******************************************************************************&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;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 06 Apr 2021 06:16:53 GMT</pubDate>
    <dc:creator>lama</dc:creator>
    <dc:date>2021-04-06T06:16:53Z</dc:date>
    <item>
      <title>Arduino TMILLIS() similar function?</title>
      <link>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/Arduino-TMILLIS-similar-function/m-p/1256506#M17791</link>
      <description>&lt;P&gt;Hi.&lt;BR /&gt;Just wondering if there is a similar function to the TMILLIS() function or how to create one so I can do tasks on a millisecond basis timer. Even if its a 3.25ms counter it would work rather well.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Sun, 04 Apr 2021 22:00:19 GMT</pubDate>
      <guid>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/Arduino-TMILLIS-similar-function/m-p/1256506#M17791</guid>
      <dc:creator>highlander</dc:creator>
      <dc:date>2021-04-04T22:00:19Z</dc:date>
    </item>
    <item>
      <title>Re: Arduino TMILLIS() similar function?</title>
      <link>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/Arduino-TMILLIS-similar-function/m-p/1257001#M17795</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;Two things:&lt;/P&gt;
&lt;P&gt;1) you have not mentioned MCU type&lt;/P&gt;
&lt;P&gt;2) Such function is neither a part of the standard C language package nor assembler.&lt;/P&gt;
&lt;P&gt;You can use ProcessorExpert&amp;nbsp; (pat of the CodeWarrior) for such purpose which enables you to set the timer on the base of your requirements and use some implemented higher level functions.&lt;/P&gt;
&lt;P&gt;Otherwise, you should know what is a timer, how it depends on bus clock, how to set it, whether and how to use interrupt functions from it, program backup millisecond timer routine or only flag ms has gone. This is, however, application problem.&lt;/P&gt;
&lt;P&gt;Short example follows which presents period generator which generates 3 periods by 3 different peripherals inside the S12XEP100 device and toggles pins each time when period finishes.&lt;/P&gt;
&lt;P&gt;Best regards, Ladislav&lt;/P&gt;
&lt;P&gt;//******************************************************************************&lt;BR /&gt;// periodic interrupt generator 1 : uses MDDC - modulus down counter &lt;BR /&gt;// Modulus down counter counts once with given period.&lt;BR /&gt;// The periodic interrupt is started by function StartMDC&lt;BR /&gt;// The periodic interrupt can be stopped by function StopMDC&lt;BR /&gt;// The pin PB0 toggled within interrupt.&lt;BR /&gt;//-----------&lt;BR /&gt;// periodic interrupt generator 2 : uses a timer&lt;BR /&gt;// interval = TCx * dt = TCx * (prescaler/fbus)&lt;BR /&gt;// TCx = interval / (prescaller/fbus) = interval * fbus / prescaler&lt;BR /&gt;// When 50MHz BUSCLK is used then we are able to set by means of standard prescaller:&lt;BR /&gt;// dt = 1/50,000,000 * prescaller&lt;BR /&gt;// let select prescaller = 8 and required internval is 0.01s =&amp;gt; &lt;BR /&gt;// =&amp;gt; TCx = 0.01*50,000,000/8 = 62500&lt;BR /&gt;// Channel 4 is used to catch period. The timer is disconnected from PT4 pin. &lt;BR /&gt;// The interrupt is launched periodically each 10ms.&lt;BR /&gt;// The periodic interrupt is started by function StartTIM&lt;BR /&gt;// The periodic interrupt can be stopped by function StopTIM&lt;BR /&gt;// The pin PB1 toggled within interrupt.&lt;BR /&gt;//-----------&lt;BR /&gt;// periodic interrupt generator 3: uses a PIT - periodic interrupt timer&lt;BR /&gt;// Periodic Interrupt Timer 0 is used to generate 10ms periodic interrupt.&lt;BR /&gt;// time-out period0 = (PITMTLD + 1) * (PITLD + 1) / fBUS = (199+1)* (2499+1) / 50,000,000 = 0.01s&lt;BR /&gt;// The periodic interrupt is started by function StartPIT0&lt;BR /&gt;// The periodic interrupt can be stopped by function StopPIT0&lt;BR /&gt;// The pin PB2 toggled within interrupt.&lt;/P&gt;
&lt;P&gt;//******************************************************************************&lt;/P&gt;
&lt;P&gt;//******************************************************************************&lt;BR /&gt;#include &amp;lt;hidef.h&amp;gt; /* common defines and macros */&lt;BR /&gt;#include &amp;lt;mc9s12xep100.h&amp;gt; /* derivative information */&lt;BR /&gt;//******************************************************************************&lt;BR /&gt;#pragma LINK_INFO DERIVATIVE "mc9s12xep100"&lt;BR /&gt;//******************************************************************************&lt;BR /&gt;#define UBYTE unsigned char&lt;BR /&gt;#define UWORD unsigned int&lt;BR /&gt;#define ULONG unsigned long&lt;BR /&gt;//******************************************************************************&lt;BR /&gt;//******************************************************************************&lt;BR /&gt;// local function prototypes&lt;BR /&gt;//******************************************************************************&lt;BR /&gt;static void PLL_Init(unsigned char synr, unsigned char refdv, unsigned char postdiv);&lt;BR /&gt;//--------------------------&lt;BR /&gt;static void MDC_Init(void);&lt;BR /&gt;static void StartMDC(void);&lt;BR /&gt;static void StopMDC(void);&lt;BR /&gt;//--------------------------&lt;BR /&gt;static void TIM_Init(void);&lt;BR /&gt;static void StartTIM(void);&lt;BR /&gt;static void StopTIM(void);&lt;BR /&gt;//--------------------------&lt;BR /&gt;static void PIT0_Init(void);&lt;BR /&gt;static void StartPIT0(void);&lt;BR /&gt;static void StopPIT0(void);&lt;BR /&gt;//******************************************************************************&lt;BR /&gt;#pragma CODE_SEG DEFAULT&lt;BR /&gt;//------------------------------------------------------------------------------&lt;BR /&gt;static void MDC_Init(void)&lt;BR /&gt;{&lt;BR /&gt;// Time interval = Tbus / Prescaller {1;4;8;16} * MCCNT&lt;BR /&gt;// Enable ISR from MDC, Continue MDC when reaches 0, prescaler 8, &lt;BR /&gt;ECT_MCCTL = ECT_MCCTL_MCZI_MASK | ECT_MCCTL_MODMC_MASK | 2;&lt;BR /&gt;}&lt;BR /&gt;//------------------------------------------------------------------------------&lt;BR /&gt;static void StartMDC(void) // interval [us] Modullus Down Counter&lt;BR /&gt;{ &lt;BR /&gt;ECT_MCFLG_MCZF = 1; // clear interrupt flag&lt;BR /&gt;ECT_MCCTL_MCEN = 1;&lt;BR /&gt;ECT_MCCNT = 62500; // 10ms period at 50MHz BUSCLK&lt;BR /&gt;ECT_MCCTL_FLMC = 1;&lt;BR /&gt;}&lt;BR /&gt;//------------------------------------------------------------------------------&lt;BR /&gt;static void StopMDC(void) // interval [us] Modullus Down Counter&lt;BR /&gt;{ &lt;BR /&gt;ECT_MCCTL_MCEN = 0; // stop MDC&lt;BR /&gt;}&lt;BR /&gt;//------------------------------------------------------------------------------&lt;BR /&gt;#pragma CODE_SEG NON_BANKED&lt;BR /&gt;//------------------------------------------------------------------------------&lt;BR /&gt;interrupt 26 void ModulusDownCounterIsr(void)&lt;BR /&gt;{&lt;BR /&gt;ECT_MCFLG_MCZF = 1; // clear interrupt flag&lt;BR /&gt;PORTB_PB0 = ~PORTB_PB0; &lt;BR /&gt;}&lt;BR /&gt;//******************************************************************************&lt;BR /&gt;#pragma CODE_SEG DEFAULT&lt;BR /&gt;//------------------------------------------------------------------------------&lt;BR /&gt;static void TIM_Init(void)&lt;BR /&gt;{&lt;BR /&gt;TIM_TSCR2 = 0x03; // prescaller = 8&lt;BR /&gt;//--- channel 4 setup ---------------&lt;BR /&gt;TIM_TIOS_IOS4 = 1; // channel 4 is output compare &lt;BR /&gt;TIM_TCTL1 = 0x00; // no output compare action at channel 4 on compare&lt;BR /&gt;TIM_OCPD_OCPD4 = 1; // channel 4 disconnected from output pin logic&lt;BR /&gt;//-----------------------------------&lt;BR /&gt;TIM_TIE_C4I = 0; // disable interrupt from channel 4&lt;BR /&gt;//-----------------------------------&lt;BR /&gt;TIM_TSCR1 = 0xE0; // enable timer,stop in wait,stop in freeze, no fast flag clear&lt;BR /&gt;}&lt;BR /&gt;//------------------------------------------------------------------------------&lt;BR /&gt;static void StartTIM(void) // 10ms period at 50MHz BUSCLK&lt;BR /&gt;{ &lt;BR /&gt;TIM_TFLG1 = 0x10; // clear interrupt flag from channel 4&lt;BR /&gt;TIM_TC4 = TIM_TCNT + 62500; // set new value and clear interrupt flag &lt;BR /&gt;TIM_TIE_C4I = 1; // enable interrupt from channel 4&lt;BR /&gt;}&lt;BR /&gt;//------------------------------------------------------------------------------&lt;BR /&gt;static void StopTIM(void) //&lt;BR /&gt;{ &lt;BR /&gt;TIM_TIE_C4I = 0; // disable interrupt from channel 4&lt;BR /&gt;}&lt;BR /&gt;//------------------------------------------------------------------------------&lt;BR /&gt;#pragma CODE_SEG NON_BANKED&lt;BR /&gt;//------------------------------------------------------------------------------&lt;BR /&gt;interrupt 89 void TC4_Isr(void)&lt;BR /&gt;{ // 10ms period at 50MHz BUSCLK&lt;BR /&gt;TIM_TFLG1 = 0x10; // clear interrupt flag from channel 4&lt;BR /&gt;TIM_TC4 = TIM_TCNT + 62500; // set new value and clear interrupt flag &lt;BR /&gt;PORTB_PB1 = ~PORTB_PB1; &lt;BR /&gt;}&lt;BR /&gt;//******************************************************************************&lt;BR /&gt;#pragma CODE_SEG DEFAULT&lt;BR /&gt;//------------------------------------------------------------------------------&lt;BR /&gt;static void PIT0_Init(void)&lt;BR /&gt;{&lt;BR /&gt;//--- PIT0 -------------------------------&lt;BR /&gt;// clock period is set 10ms&lt;BR /&gt;// time-out period0 = (PITMTLD + 1) * (PITLD + 1) / fBUS = (199+1)* (2499+1) / 50,000,000 = 0.01s&lt;BR /&gt;PITMUX_PMUX0 = 0; // microtimer 0 for PIT0&lt;BR /&gt;PITMTLD0 = 199; // microtimer (prescaller) value&lt;BR /&gt;PITLD0 = 2499; // PIT0 timer interval&lt;BR /&gt;PITCFLMT = 0xE0; // Enable PIT module,stop in wait,stop in freeze&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;PITINTE_PINTE0 = 0; // Disable PIT0 interrupt to generate 10 ms&lt;BR /&gt;PITCE_PCE0 = 1; // Enable PIT0&lt;BR /&gt;}&lt;BR /&gt;//------------------------------------------------------------------------------&lt;BR /&gt;static void StartPIT0(void) &lt;BR /&gt;{ &lt;BR /&gt;PITTF = PITTF_PTF0_MASK; // Clear interrupt flag from PIT0 &lt;BR /&gt;PITCFLMT_PFLMT0 = 1; // reload microtimer 0&lt;BR /&gt;PITFLT_PFLT0 = 1; // reload PIT0 counter&lt;BR /&gt;PITINTE_PINTE0 = 1; // Enable PIT0 interrupt to generate 10 ms&lt;BR /&gt;}&lt;BR /&gt;//------------------------------------------------------------------------------&lt;BR /&gt;static void StopPIT0(void) &lt;BR /&gt;{ &lt;BR /&gt;PITINTE_PINTE0 = 0; // Disable PIT0 interrupt to generate 10 ms&lt;BR /&gt;}&lt;BR /&gt;//------------------------------------------------------------------------------&lt;BR /&gt;#pragma CODE_SEG NON_BANKED&lt;BR /&gt;//------------------------------------------------------------------------------&lt;BR /&gt;interrupt 66 void PIT0_Isr(void)&lt;BR /&gt;{&lt;BR /&gt;PORTB_PB2 = ~PORTB_PB2; &lt;BR /&gt;PITTF = PITTF_PTF0_MASK; // Clear interrupt flag PIT0 &lt;BR /&gt;}&lt;BR /&gt;//******************************************************************************&lt;BR /&gt;#pragma CODE_SEG DEFAULT&lt;BR /&gt;//------------------------------------------------------------------------------&lt;BR /&gt;static void PLL_Init(unsigned char synr, unsigned char refdv, unsigned char postdiv)&lt;BR /&gt;{&lt;BR /&gt;PLLCTL = 0B00000001; // CME=0,PLLON=0,FM1=0,FM2=0,FSTWKP=0,PRE=0,PCE=0,SCME=1&lt;BR /&gt;CLKSEL = 0B00000011; // PLLSEL=0,PSTP=0,PLLWAI=0,RTIWAI=1,COPWAI=1&lt;BR /&gt;SYNR = synr; // Set the multiplier register&lt;BR /&gt;REFDV = refdv; // Set the divider register&lt;BR /&gt;POSTDIV = postdiv; // Set the post divider register&lt;BR /&gt;PLLCTL_PLLON = 1; // Enable the Phase Lock Loop&lt;BR /&gt;while(!CRGFLG_LOCK); // Wait till the PLL VCO is within tolerance&lt;BR /&gt;CLKSEL_PLLSEL = 1; // Select clock source from PLLCLK&lt;BR /&gt;//ECLKCTL_NECLK=0; // Enable the BusClk output at ECLK pin&lt;BR /&gt;}&lt;BR /&gt;//******************************************************************************&lt;/P&gt;
&lt;P&gt;void main(void) &lt;BR /&gt;{&lt;BR /&gt;ULONG i;&lt;BR /&gt;//..................................&lt;BR /&gt;PLL_Init(0xC4,0x80,0x00);&lt;BR /&gt;//..................................&lt;BR /&gt;DDRB = 0x07; // PB0,1,2 an output&lt;BR /&gt;PORTB = 0x00; // inactive state of PB0 &lt;BR /&gt;//..................................&lt;BR /&gt;MDC_Init();&lt;BR /&gt;TIM_Init();&lt;BR /&gt;PIT0_Init();&lt;BR /&gt;//..................................&lt;BR /&gt;EnableInterrupts;&lt;BR /&gt;//..................................&lt;BR /&gt;StartMDC();&lt;BR /&gt;// StopMDC();&lt;BR /&gt;StartTIM();&lt;BR /&gt;// StopTIM();&lt;BR /&gt;StartPIT0();&lt;BR /&gt;// StopPIT0();&lt;BR /&gt;for(;;)&lt;BR /&gt;{&lt;BR /&gt;for(i=0;i&amp;lt;1000000UL;i++) // SW delay&lt;BR /&gt;{&lt;BR /&gt;asm nop;asm nop;asm nop;asm nop;asm nop;asm nop;asm nop;asm nop;asm nop;asm nop; &lt;BR /&gt;}&lt;BR /&gt;StopMDC();&lt;BR /&gt;StopTIM();&lt;BR /&gt;StopPIT0();&lt;/P&gt;
&lt;P&gt;for(i=0;i&amp;lt;1000000UL;i++) // SW delay&lt;BR /&gt;{&lt;BR /&gt;asm nop;asm nop;asm nop;asm nop;asm nop;asm nop;asm nop;asm nop;asm nop;asm nop; &lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;StartMDC();&lt;BR /&gt;StartTIM();&lt;BR /&gt;StartPIT0();&lt;BR /&gt;}&lt;BR /&gt;//........................................&lt;BR /&gt;}&lt;BR /&gt;//******************************************************************************&lt;BR /&gt;// Services performed by FREESCALE in this matter are performed AS IS and without any warranty. CUSTOMER retains&lt;BR /&gt;// the final decision relative to the total design and functionality of the end product. FREESCALE neither&lt;BR /&gt;// guarantees nor will be held liable by CUSTOMER for the success of this project.&lt;BR /&gt;// FREESCALE DISCLAIMS ALL WARRANTIES, EXPRESSED, IMPLIED OR STATUTORY INCLUDING, BUT NOT LIMITED TO, IMPLIED&lt;BR /&gt;// WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE ON ANY HARDWARE, SOFTWARE ORE ADVISE SUPPLIED&lt;BR /&gt;// TO THE PROJECT BY FREESCALE, AND OR NAY PRODUCT RESULTING FROM FREESCALE SERVICES . IN NO EVENT SHALL FREESCALE&lt;BR /&gt;// BE LIABLE FOR INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT.&lt;BR /&gt;//&lt;BR /&gt;// CUSTOMER agrees to hold FREESCALE harmless against any and all claims demands or actions by anyone on account of&lt;BR /&gt;// any damage, or injury, whether commercial, contractual, or tortuous, rising directly or indirectly as a result of&lt;BR /&gt;// the advise or assistance supplied CUSTOMER in connection with product, services or goods supplied under this Agreement.&lt;BR /&gt;//******************************************************************************&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;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 06 Apr 2021 06:16:53 GMT</pubDate>
      <guid>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/Arduino-TMILLIS-similar-function/m-p/1257001#M17795</guid>
      <dc:creator>lama</dc:creator>
      <dc:date>2021-04-06T06:16:53Z</dc:date>
    </item>
  </channel>
</rss>

