<?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のトピックGetting the Pulse Accumulator working</title>
    <link>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/Getting-the-Pulse-Accumulator-working/m-p/125247#M287</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;&lt;P class="MsoNormal" style="MARGIN: 0in 0in 0pt;"&gt;&lt;SPAN style="mso-bookmark: OLE_LINK1;"&gt;&lt;SPAN style="mso-bookmark: OLE_LINK2;"&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: red;"&gt;This message contains an entire topic ported from a separate forum. The original message and all replies are in this single message. We have seeded this new forum with selected information that we expect will be of value to you as you search for answers to your questions.&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="MsoNormal" style="MARGIN: 0in 0in 0pt;"&gt;&lt;SPAN style="mso-bookmark: OLE_LINK1;"&gt;&lt;SPAN style="mso-bookmark: OLE_LINK2;"&gt;&lt;NAMESPACE ns="urn:schemas-microsoft-com:office:office" prefix="o"&gt;&lt;/NAMESPACE&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P class="MsoNormal" style="MARGIN: 0in 0in 0pt;"&gt;&lt;FONT size="2"&gt;&lt;SPAN style="mso-bookmark: OLE_LINK1;"&gt;&lt;SPAN style="mso-bookmark: OLE_LINK2;"&gt;&lt;B style="mso-bidi-font-weight: normal;"&gt;Posted: &lt;/B&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;B style="mso-bidi-font-weight: normal;"&gt;Tue Aug 23, 2005&lt;SPAN style="mso-spacerun: yes;"&gt;&amp;nbsp; &lt;/SPAN&gt;6:49 pm &lt;/B&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P class="MsoNormal" style="MARGIN: 0in 0in 0pt;"&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P class="MsoNormal" style="MARGIN: 0in 0in 0pt;"&gt;&lt;FONT size="2"&gt;Hi,&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P class="MsoNormal" style="MARGIN: 0in 0in 0pt;"&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P class="MsoNormal" style="MARGIN: 0in 0in 0pt;"&gt;&lt;FONT size="2"&gt;I would like to have my timers(Ch. 4 -7) interrupt me after a number of seconds have passed. It seems that the only way to do this is to use the Pulse Accumulator's clock PACLK and divide it by 65536 using the CLK1:0 bits in the PACTL.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P class="MsoNormal" style="MARGIN: 0in 0in 0pt;"&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P class="MsoNormal" style="MARGIN: 0in 0in 0pt;"&gt;&lt;FONT size="2"&gt;Currently I have IOC7 through IOC4 tied to GND, and am setting PACTL to 0x7C. But my channel 4 timer isn't getting interrupts. Only when I disable the Pulse Accumulator does the channel 4 timer interrupt.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P class="MsoNormal" style="MARGIN: 0in 0in 0pt;"&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P class="MsoNormal" style="MARGIN: 0in 0in 0pt;"&gt;&lt;FONT size="2"&gt;Can someone make a suggestion as to how to make this work? Or if there is another way to make the counters count for several seconds I would be interested in that too.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P class="MsoNormal" style="MARGIN: 0in 0in 0pt;"&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P class="MsoNormal" style="MARGIN: 0in 0in 0pt;"&gt;&lt;FONT size="2"&gt;Thanks,&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P class="MsoNormal" style="MARGIN: 0in 0in 0pt;"&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P class="MsoNormal" style="MARGIN: 0in 0in 0pt;"&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;HR /&gt;&amp;nbsp;&lt;P&gt;&lt;/P&gt;&lt;P class="MsoNormal" style="MARGIN: 0in 0in 0pt;"&gt;&lt;B style="mso-bidi-font-weight: normal;"&gt;&lt;FONT size="2"&gt;Posted: Tue Aug 23, 2005&lt;SPAN style="mso-spacerun: yes;"&gt;&amp;nbsp; &lt;/SPAN&gt;8:29 pm &lt;/FONT&gt;&lt;/B&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P class="MsoNormal" style="MARGIN: 0in 0in 0pt;"&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P class="MsoNormal" style="MARGIN: 0in 0in 0pt;"&gt;&lt;FONT size="2"&gt;To only count time, you do not have to (and probably should not) use the Pulse Accumulator. All you need to do is keep track of the number of times a timer overflows or times out. Attached are two files showing how the 68HC11 timer (very much like the HC12) making 1 second ticks. I think it could easily be extended to a 9-second period by only changing the 3-byte number representing the timer tics in a period. Beyond that one would have to slow down the timer tics or extend the 3-byte number. &lt;/FONT&gt;&lt;/P&gt;&lt;P class="MsoNormal" style="MARGIN: 0in 0in 0pt;"&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P class="MsoNormal" style="MARGIN: 0in 0in 0pt;"&gt;&lt;FONT size="2"&gt;Another example make long periods is in Han-Way Huang's 68HC12 book on page 307-9. His Example 8.5 has both assembly and C code.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P class="MsoNormal" style="MARGIN: 0in 0in 0pt;"&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P class="MsoNormal" style="MARGIN: 0in 0in 0pt;"&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;HR /&gt;&amp;nbsp;&lt;P&gt;&lt;/P&gt;&lt;P class="MsoNormal" style="MARGIN: 0in 0in 0pt;"&gt;&lt;B style="mso-bidi-font-weight: normal;"&gt;&lt;FONT size="2"&gt;Posted: Tue Aug 23, 2005&lt;SPAN style="mso-spacerun: yes;"&gt;&amp;nbsp; &lt;/SPAN&gt;9:41 pm &lt;/FONT&gt;&lt;/B&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P class="MsoNormal" style="MARGIN: 0in 0in 0pt;"&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P class="MsoNormal" style="MARGIN: 0in 0in 0pt;"&gt;&lt;FONT size="2"&gt;The usual way of doing this is to set the hardware timer for as large a time as possible depending on your clock. Then in the interrupt routine establish a sotware down counter to get to your overall large time. When the SW counts down to 0, reset the down counter and do your thing.&lt;/FONT&gt;&lt;/P&gt;&lt;P class="MsoNormal" style="MARGIN: 0in 0in 0pt;"&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P class="MsoNormal" style="MARGIN: 0in 0in 0pt;"&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;HR /&gt;&amp;nbsp;&lt;P&gt;&lt;/P&gt;&lt;P class="MsoNormal" style="MARGIN: 0in 0in 0pt;"&gt;&lt;B style="mso-bidi-font-weight: normal;"&gt;&lt;FONT size="2"&gt;Posted: Wed Aug 24, 2005&lt;SPAN style="mso-spacerun: yes;"&gt;&amp;nbsp; &lt;/SPAN&gt;9:31 pm &lt;/FONT&gt;&lt;/B&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P class="MsoNormal" style="MARGIN: 0in 0in 0pt;"&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P class="MsoNormal" style="MARGIN: 0in 0in 0pt;"&gt;&lt;FONT size="2"&gt;Hi&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P class="MsoNormal" style="MARGIN: 0in 0in 0pt;"&gt;&lt;FONT size="2"&gt;I managed to get the PA working as a timer by setting up channel 4 to generate a clock and using this clock an an input to the PA. The PA generates an interrupt when it overflows so it is easy to generate a delay by setting the PA counter to (0x0000 - delay). By setting channel 4 to generate a high or a low frequency it is possible to generate very short to quite long and very accurate delays with an interrupt at the end.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P class="MsoNormal" style="MARGIN: 0in 0in 0pt;"&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P class="MsoNormal" style="MARGIN: 0in 0in 0pt;"&gt;&lt;FONT size="2"&gt;Here is a bit of code without great details. It generates 3 PWM outputs from channels 1..3 based on a 3kHz frequency at channel 4. Channel 4 output is turned on when required to drive a buzzer signal at 3kHz and also for use by the PA input to generate the desired delay.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P class="MsoNormal" style="MARGIN: 0in 0in 0pt;"&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P class="MsoNormal" style="MARGIN: 0in 0in 0pt;"&gt;&lt;FONT size="2"&gt;If you would like to see the code in action there is a demo at &lt;A href="https://community.nxp.com/www.mjbc.ch" target="test_blank"&gt;www.mjbc.ch&lt;/A&gt;. You can download a program called 'VIPpanel' and control the contrast and backlight of the LCD (along with other things) via the Internet. The following PWMs are in use. You can also generate variable 'beep' lengths but won't be able hear it of course since the Webcam has no sound. Nevertheless you should get the idea..&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P class="MsoNormal" style="MARGIN: 0in 0in 0pt;"&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P class="MsoNormal" style="MARGIN: 0in 0in 0pt;"&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;&lt;SPAN class="msg_source_code"&gt;&lt;SPAN class="text_smallest"&gt;Code:&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;/***********************/&amp;nbsp; // Initialisation&amp;nbsp; #define CONTRAST_CONTROL TC6_HI&amp;nbsp; #define BACKLIGHT_CONTROL TC4_HI&amp;nbsp; #define LED_CONTROL TC5_HI&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; TIOS = (IOS7 | IOS6 | IOS5 | IOS4); // enable output compare on all&amp;nbsp; channels&amp;nbsp; OC7M = (OC7M6 | OC7M5 | OC7M4); // 3 channels as output (channel&amp;nbsp; 7 (buzzer) not yet)&amp;nbsp; OC7D = (OC7D6 | OC7D5 | OC7D4); // transfer on channel 7 match&amp;nbsp; (for PWM)&amp;nbsp; TSCR1 = TEN; // enable timer&amp;nbsp; TCTL1 = 0x15; // toggle output for 3 channels&amp;nbsp; CONTRAST_CONTROL = (unsigned short)ucContrastSetting; //&amp;nbsp; set default contrast setting&amp;nbsp; LED_CONTROL = 0x00ff; // set max LED intensity&amp;nbsp; BACKLIGHT_CONTROL = 0x0000; // set min backlight intensity&amp;nbsp; (off)&amp;nbsp; TC7_HI = 0x00ff; // basic frequency is 3kHz&amp;nbsp; TSCR2 = 0x0c; // enable timer div = 32&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // generate 3kHz tone for a specified period, interrupt from PA when&amp;nbsp; complete&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; #define FIXED_FREQUENCY 3000 // fixed frequency of buzzer&amp;nbsp; output&amp;nbsp; #define PERIOD_50MS (FIXED_FREQUENCY/20) //&amp;nbsp; ((FIXED_FREQUENCY*50)/1000) // pulses in 50ms&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; static void fnGenerateTone(unsigned char ucLength)&amp;nbsp; {&amp;nbsp; unsigned short usPeriodPulses = 0;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; TCTL1 |= 0x40; // drive buzzer output&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; while (ucLength--) {&amp;nbsp; usPeriodPulses -= PERIOD_50MS;&amp;nbsp; }&amp;nbsp; PACNT_WORD = usPeriodPulses;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; PACTL = (PAEN | PEDGE | PAOVI); // enable interrupt on overflow&amp;nbsp; }&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // Interrupt due to pulse accumulator overflow&amp;nbsp; void Acc_Overflow(void)&amp;nbsp; {&amp;nbsp; PAFLG = PAOVF; // reset interrupt&amp;nbsp; TCTL1 &amp;amp;= ~0x40; // remove buzzer drive&amp;nbsp; PACTL = 0; // stop pulse accumulator activity&amp;nbsp; }&amp;nbsp; /**************************************************/&lt;/PRE&gt;&lt;P class="MsoNormal" style="MARGIN: 0in 0in 0pt;"&gt;&lt;BR /&gt;&amp;nbsp;&lt;BR /&gt;&lt;/P&gt;&lt;HR /&gt;&lt;BR /&gt;&lt;B style="mso-bidi-font-weight: normal;"&gt;&lt;FONT size="2"&gt;Posted: Thu Aug 25, 2005&lt;SPAN style="mso-spacerun: yes;"&gt;&amp;nbsp; &lt;/SPAN&gt;11:12 am &lt;P&gt;&lt;/P&gt;&lt;/FONT&gt;&lt;/B&gt;&lt;P&gt;&lt;/P&gt;&lt;P class="MsoNormal" style="MARGIN: 0in 0in 0pt;"&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P class="MsoNormal" style="MARGIN: 0in 0in 0pt;"&gt;&lt;FONT size="2"&gt;Especially the PWM subsystem is a tricky one to setup due to all the&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P class="MsoNormal" style="MARGIN: 0in 0in 0pt;"&gt;&lt;FONT size="2"&gt;clock configurations. If you'd like to save some time, you can use&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P class="MsoNormal" style="MARGIN: 0in 0in 0pt;"&gt;&lt;FONT size="2"&gt;Driver2Go (http://www.driver2go.net).&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P class="MsoNormal" style="MARGIN: 0in 0in 0pt;"&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P class="MsoNormal" style="MARGIN: 0in 0in 0pt;"&gt;&lt;FONT size="2"&gt;It contains (amongst others) HCS12 drivers for the PWM and ECT,&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P class="MsoNormal" style="MARGIN: 0in 0in 0pt;"&gt;&lt;FONT size="2"&gt;including multimedia tutorials on how to set it up.&lt;/FONT&gt;&lt;/P&gt;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sun, 29 Jan 2006 11:33:24 GMT</pubDate>
    <dc:creator>khumphri</dc:creator>
    <dc:date>2006-01-29T11:33:24Z</dc:date>
    <item>
      <title>Getting the Pulse Accumulator working</title>
      <link>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/Getting-the-Pulse-Accumulator-working/m-p/125247#M287</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;&lt;P class="MsoNormal" style="MARGIN: 0in 0in 0pt;"&gt;&lt;SPAN style="mso-bookmark: OLE_LINK1;"&gt;&lt;SPAN style="mso-bookmark: OLE_LINK2;"&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: red;"&gt;This message contains an entire topic ported from a separate forum. The original message and all replies are in this single message. We have seeded this new forum with selected information that we expect will be of value to you as you search for answers to your questions.&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="MsoNormal" style="MARGIN: 0in 0in 0pt;"&gt;&lt;SPAN style="mso-bookmark: OLE_LINK1;"&gt;&lt;SPAN style="mso-bookmark: OLE_LINK2;"&gt;&lt;NAMESPACE ns="urn:schemas-microsoft-com:office:office" prefix="o"&gt;&lt;/NAMESPACE&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P class="MsoNormal" style="MARGIN: 0in 0in 0pt;"&gt;&lt;FONT size="2"&gt;&lt;SPAN style="mso-bookmark: OLE_LINK1;"&gt;&lt;SPAN style="mso-bookmark: OLE_LINK2;"&gt;&lt;B style="mso-bidi-font-weight: normal;"&gt;Posted: &lt;/B&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;B style="mso-bidi-font-weight: normal;"&gt;Tue Aug 23, 2005&lt;SPAN style="mso-spacerun: yes;"&gt;&amp;nbsp; &lt;/SPAN&gt;6:49 pm &lt;/B&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P class="MsoNormal" style="MARGIN: 0in 0in 0pt;"&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P class="MsoNormal" style="MARGIN: 0in 0in 0pt;"&gt;&lt;FONT size="2"&gt;Hi,&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P class="MsoNormal" style="MARGIN: 0in 0in 0pt;"&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P class="MsoNormal" style="MARGIN: 0in 0in 0pt;"&gt;&lt;FONT size="2"&gt;I would like to have my timers(Ch. 4 -7) interrupt me after a number of seconds have passed. It seems that the only way to do this is to use the Pulse Accumulator's clock PACLK and divide it by 65536 using the CLK1:0 bits in the PACTL.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P class="MsoNormal" style="MARGIN: 0in 0in 0pt;"&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P class="MsoNormal" style="MARGIN: 0in 0in 0pt;"&gt;&lt;FONT size="2"&gt;Currently I have IOC7 through IOC4 tied to GND, and am setting PACTL to 0x7C. But my channel 4 timer isn't getting interrupts. Only when I disable the Pulse Accumulator does the channel 4 timer interrupt.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P class="MsoNormal" style="MARGIN: 0in 0in 0pt;"&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P class="MsoNormal" style="MARGIN: 0in 0in 0pt;"&gt;&lt;FONT size="2"&gt;Can someone make a suggestion as to how to make this work? Or if there is another way to make the counters count for several seconds I would be interested in that too.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P class="MsoNormal" style="MARGIN: 0in 0in 0pt;"&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P class="MsoNormal" style="MARGIN: 0in 0in 0pt;"&gt;&lt;FONT size="2"&gt;Thanks,&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P class="MsoNormal" style="MARGIN: 0in 0in 0pt;"&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P class="MsoNormal" style="MARGIN: 0in 0in 0pt;"&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;HR /&gt;&amp;nbsp;&lt;P&gt;&lt;/P&gt;&lt;P class="MsoNormal" style="MARGIN: 0in 0in 0pt;"&gt;&lt;B style="mso-bidi-font-weight: normal;"&gt;&lt;FONT size="2"&gt;Posted: Tue Aug 23, 2005&lt;SPAN style="mso-spacerun: yes;"&gt;&amp;nbsp; &lt;/SPAN&gt;8:29 pm &lt;/FONT&gt;&lt;/B&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P class="MsoNormal" style="MARGIN: 0in 0in 0pt;"&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P class="MsoNormal" style="MARGIN: 0in 0in 0pt;"&gt;&lt;FONT size="2"&gt;To only count time, you do not have to (and probably should not) use the Pulse Accumulator. All you need to do is keep track of the number of times a timer overflows or times out. Attached are two files showing how the 68HC11 timer (very much like the HC12) making 1 second ticks. I think it could easily be extended to a 9-second period by only changing the 3-byte number representing the timer tics in a period. Beyond that one would have to slow down the timer tics or extend the 3-byte number. &lt;/FONT&gt;&lt;/P&gt;&lt;P class="MsoNormal" style="MARGIN: 0in 0in 0pt;"&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P class="MsoNormal" style="MARGIN: 0in 0in 0pt;"&gt;&lt;FONT size="2"&gt;Another example make long periods is in Han-Way Huang's 68HC12 book on page 307-9. His Example 8.5 has both assembly and C code.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P class="MsoNormal" style="MARGIN: 0in 0in 0pt;"&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P class="MsoNormal" style="MARGIN: 0in 0in 0pt;"&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;HR /&gt;&amp;nbsp;&lt;P&gt;&lt;/P&gt;&lt;P class="MsoNormal" style="MARGIN: 0in 0in 0pt;"&gt;&lt;B style="mso-bidi-font-weight: normal;"&gt;&lt;FONT size="2"&gt;Posted: Tue Aug 23, 2005&lt;SPAN style="mso-spacerun: yes;"&gt;&amp;nbsp; &lt;/SPAN&gt;9:41 pm &lt;/FONT&gt;&lt;/B&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P class="MsoNormal" style="MARGIN: 0in 0in 0pt;"&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P class="MsoNormal" style="MARGIN: 0in 0in 0pt;"&gt;&lt;FONT size="2"&gt;The usual way of doing this is to set the hardware timer for as large a time as possible depending on your clock. Then in the interrupt routine establish a sotware down counter to get to your overall large time. When the SW counts down to 0, reset the down counter and do your thing.&lt;/FONT&gt;&lt;/P&gt;&lt;P class="MsoNormal" style="MARGIN: 0in 0in 0pt;"&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P class="MsoNormal" style="MARGIN: 0in 0in 0pt;"&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;HR /&gt;&amp;nbsp;&lt;P&gt;&lt;/P&gt;&lt;P class="MsoNormal" style="MARGIN: 0in 0in 0pt;"&gt;&lt;B style="mso-bidi-font-weight: normal;"&gt;&lt;FONT size="2"&gt;Posted: Wed Aug 24, 2005&lt;SPAN style="mso-spacerun: yes;"&gt;&amp;nbsp; &lt;/SPAN&gt;9:31 pm &lt;/FONT&gt;&lt;/B&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P class="MsoNormal" style="MARGIN: 0in 0in 0pt;"&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P class="MsoNormal" style="MARGIN: 0in 0in 0pt;"&gt;&lt;FONT size="2"&gt;Hi&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P class="MsoNormal" style="MARGIN: 0in 0in 0pt;"&gt;&lt;FONT size="2"&gt;I managed to get the PA working as a timer by setting up channel 4 to generate a clock and using this clock an an input to the PA. The PA generates an interrupt when it overflows so it is easy to generate a delay by setting the PA counter to (0x0000 - delay). By setting channel 4 to generate a high or a low frequency it is possible to generate very short to quite long and very accurate delays with an interrupt at the end.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P class="MsoNormal" style="MARGIN: 0in 0in 0pt;"&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P class="MsoNormal" style="MARGIN: 0in 0in 0pt;"&gt;&lt;FONT size="2"&gt;Here is a bit of code without great details. It generates 3 PWM outputs from channels 1..3 based on a 3kHz frequency at channel 4. Channel 4 output is turned on when required to drive a buzzer signal at 3kHz and also for use by the PA input to generate the desired delay.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P class="MsoNormal" style="MARGIN: 0in 0in 0pt;"&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P class="MsoNormal" style="MARGIN: 0in 0in 0pt;"&gt;&lt;FONT size="2"&gt;If you would like to see the code in action there is a demo at &lt;A href="https://community.nxp.com/www.mjbc.ch" target="test_blank"&gt;www.mjbc.ch&lt;/A&gt;. You can download a program called 'VIPpanel' and control the contrast and backlight of the LCD (along with other things) via the Internet. The following PWMs are in use. You can also generate variable 'beep' lengths but won't be able hear it of course since the Webcam has no sound. Nevertheless you should get the idea..&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P class="MsoNormal" style="MARGIN: 0in 0in 0pt;"&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P class="MsoNormal" style="MARGIN: 0in 0in 0pt;"&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;&lt;SPAN class="msg_source_code"&gt;&lt;SPAN class="text_smallest"&gt;Code:&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;/***********************/&amp;nbsp; // Initialisation&amp;nbsp; #define CONTRAST_CONTROL TC6_HI&amp;nbsp; #define BACKLIGHT_CONTROL TC4_HI&amp;nbsp; #define LED_CONTROL TC5_HI&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; TIOS = (IOS7 | IOS6 | IOS5 | IOS4); // enable output compare on all&amp;nbsp; channels&amp;nbsp; OC7M = (OC7M6 | OC7M5 | OC7M4); // 3 channels as output (channel&amp;nbsp; 7 (buzzer) not yet)&amp;nbsp; OC7D = (OC7D6 | OC7D5 | OC7D4); // transfer on channel 7 match&amp;nbsp; (for PWM)&amp;nbsp; TSCR1 = TEN; // enable timer&amp;nbsp; TCTL1 = 0x15; // toggle output for 3 channels&amp;nbsp; CONTRAST_CONTROL = (unsigned short)ucContrastSetting; //&amp;nbsp; set default contrast setting&amp;nbsp; LED_CONTROL = 0x00ff; // set max LED intensity&amp;nbsp; BACKLIGHT_CONTROL = 0x0000; // set min backlight intensity&amp;nbsp; (off)&amp;nbsp; TC7_HI = 0x00ff; // basic frequency is 3kHz&amp;nbsp; TSCR2 = 0x0c; // enable timer div = 32&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // generate 3kHz tone for a specified period, interrupt from PA when&amp;nbsp; complete&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; #define FIXED_FREQUENCY 3000 // fixed frequency of buzzer&amp;nbsp; output&amp;nbsp; #define PERIOD_50MS (FIXED_FREQUENCY/20) //&amp;nbsp; ((FIXED_FREQUENCY*50)/1000) // pulses in 50ms&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; static void fnGenerateTone(unsigned char ucLength)&amp;nbsp; {&amp;nbsp; unsigned short usPeriodPulses = 0;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; TCTL1 |= 0x40; // drive buzzer output&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; while (ucLength--) {&amp;nbsp; usPeriodPulses -= PERIOD_50MS;&amp;nbsp; }&amp;nbsp; PACNT_WORD = usPeriodPulses;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; PACTL = (PAEN | PEDGE | PAOVI); // enable interrupt on overflow&amp;nbsp; }&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // Interrupt due to pulse accumulator overflow&amp;nbsp; void Acc_Overflow(void)&amp;nbsp; {&amp;nbsp; PAFLG = PAOVF; // reset interrupt&amp;nbsp; TCTL1 &amp;amp;= ~0x40; // remove buzzer drive&amp;nbsp; PACTL = 0; // stop pulse accumulator activity&amp;nbsp; }&amp;nbsp; /**************************************************/&lt;/PRE&gt;&lt;P class="MsoNormal" style="MARGIN: 0in 0in 0pt;"&gt;&lt;BR /&gt;&amp;nbsp;&lt;BR /&gt;&lt;/P&gt;&lt;HR /&gt;&lt;BR /&gt;&lt;B style="mso-bidi-font-weight: normal;"&gt;&lt;FONT size="2"&gt;Posted: Thu Aug 25, 2005&lt;SPAN style="mso-spacerun: yes;"&gt;&amp;nbsp; &lt;/SPAN&gt;11:12 am &lt;P&gt;&lt;/P&gt;&lt;/FONT&gt;&lt;/B&gt;&lt;P&gt;&lt;/P&gt;&lt;P class="MsoNormal" style="MARGIN: 0in 0in 0pt;"&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P class="MsoNormal" style="MARGIN: 0in 0in 0pt;"&gt;&lt;FONT size="2"&gt;Especially the PWM subsystem is a tricky one to setup due to all the&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P class="MsoNormal" style="MARGIN: 0in 0in 0pt;"&gt;&lt;FONT size="2"&gt;clock configurations. If you'd like to save some time, you can use&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P class="MsoNormal" style="MARGIN: 0in 0in 0pt;"&gt;&lt;FONT size="2"&gt;Driver2Go (http://www.driver2go.net).&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P class="MsoNormal" style="MARGIN: 0in 0in 0pt;"&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P class="MsoNormal" style="MARGIN: 0in 0in 0pt;"&gt;&lt;FONT size="2"&gt;It contains (amongst others) HCS12 drivers for the PWM and ECT,&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P class="MsoNormal" style="MARGIN: 0in 0in 0pt;"&gt;&lt;FONT size="2"&gt;including multimedia tutorials on how to set it up.&lt;/FONT&gt;&lt;/P&gt;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 29 Jan 2006 11:33:24 GMT</pubDate>
      <guid>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/Getting-the-Pulse-Accumulator-working/m-p/125247#M287</guid>
      <dc:creator>khumphri</dc:creator>
      <dc:date>2006-01-29T11:33:24Z</dc:date>
    </item>
  </channel>
</rss>

