<?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>8-bit MicrocontrollersのトピックRe: SG8 capture,compare module query</title>
    <link>https://community.nxp.com/t5/8-bit-Microcontrollers/SG8-capture-compare-module-query/m-p/169606#M11253</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;Hi,&lt;/DIV&gt;&lt;DIV&gt;I took your code and rewrote some parts of it.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;1) You should never reset the TPMCNT. It is only reset when coming out of reset.&lt;/DIV&gt;&lt;DIV&gt;This means that all the timing parameter that you enter should be relative, not absolute.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;2) Your application, if&amp;nbsp;I have understood it, only requiers 1 interrupt. It is the interrupt from the falling 100 Hz input signal.&lt;/DIV&gt;&lt;DIV&gt;In this interrupt , there are two ways of setting the desired pulse width.&lt;/DIV&gt;&lt;DIV&gt;Either the outgoing pulse width is important, then read the TPMCNT, add 0x18 and store it in the TPM1C1V register.&lt;/DIV&gt;&lt;DIV&gt;Or if the time from the falling edge to the trailing edge of the pulse width is vital, then read the TPM1C0V, add 0x18 and store it in TPMC1V.&lt;/DIV&gt;&lt;DIV&gt;Use the&amp;nbsp;PULSEHIGHTIME macro to select either method.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;3) The interrupt at the trailing edge of the outgoing pulse is not important.&lt;/DIV&gt;&lt;DIV&gt;You can select to have them with the code using the CH1INTERRUPT macro.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;4) Sorry, I did not have the time to make a beautiful source code. Hope it is readable anyhow.&lt;/DIV&gt;&lt;DIV&gt;I ran the code on a DEMO9S08SH8, which is slightly different than&amp;nbsp; the 9S08SG8. I think that the code will run just the same on a 9S08SG8 MCU.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Regards,&lt;/DIV&gt;&lt;DIV&gt;Ake&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 02 Jul 2008 18:55:36 GMT</pubDate>
    <dc:creator>Ake</dc:creator>
    <dc:date>2008-07-02T18:55:36Z</dc:date>
    <item>
      <title>SG8 capture,compare module query</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/SG8-capture-compare-module-query/m-p/169605#M11252</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt; &lt;/DIV&gt;&lt;DIV&gt;Dear Sir,&lt;BR /&gt;I am using SG8 device 16-PIN(TSSOP),CW 6.2v. In my application i want use capture,compare module.&lt;BR /&gt;So pin no 16 (PTA0/TPM1CH0) is used for capture i/p , the square wave (50 Hz,5v amplitude) is given to this pin &amp;amp; TPM1CH1 is used only&lt;BR /&gt;for output compare. Once the capture is happened i am reseting TPM1 &amp;amp; putting some value in channel 1 valure register (TPM1C1V) &amp;amp; making&lt;BR /&gt;PTBD_PTBD1 = 1.So once the TPM1 matched with channel 1 value register (TPM1C1V) interrupt will getnerate &amp;amp; in ISR&lt;BR /&gt;i am making PTBD_PTBD1 = 0;&lt;BR /&gt;This is happening if i enabled TPM1 (TPM1SC_CLKSA = 1) in "main()" function.But if i disabled it no capture or compare is happened.&lt;BR /&gt;&amp;amp; in my applicationi want to start TPM1 timer after capture happened.&lt;BR /&gt;Please tell me the solution to overcome this.Below is my source code.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;DIV class="msg_source_code"&gt;&lt;DIV class="text_smallest"&gt;Code:&lt;/DIV&gt;&lt;PRE&gt;#include &amp;lt;hidef.h&amp;gt; /* for EnableInterrupts macro */#include "derivative.h" /* include peripheral declarations */void MCU_init(void);unsigned char flag;interrupt 26 void MTIM_ISR(void) {MTIMSC_TOF = 0;}interrupt 11 void Timovr(void){&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; TPM1SC_TOF=0;}interrupt 6 void TPM1CH1(void){&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; TPM1C1SC_CH1F=0;&amp;nbsp;&amp;nbsp;&amp;nbsp; PTBD_PTBD1 = 0;&amp;nbsp;&amp;nbsp; // Make pin output low once Compare happened.}interrupt 5 void TPM1CH0(void){ // ISR for TPM1 channel 0TPM1SC_CLKSA =0;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // Stop TPM1 Counter incrementing(void)TPM1C0SC;TPM1C0SC_CH0F=0;TPM1CNT = 0x0000;TPM1SC_CLKSA = 1;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // Start TPM1 Counter incrementingTPM1C1V = 100;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // Put value in compare register.PTBD_PTBD1 = 1;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // Make pin output high once Capture happened.PTBD_PTBD2 = ~PTBD_PTBD2; // Check capture is happened.flag = 1;}void main(void) {MCU_init();TPM1SC_CLKSA = 1; flag = 0;&amp;nbsp; EnableInterrupts; /* enable interrupts */&amp;nbsp; /* include your code here */&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for(;;) {&amp;nbsp; while(flag == 0) ;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; flag = 0;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; } /* loop forever */&amp;nbsp; /* please make sure that you never leave main */}void MCU_init(void) {/******************** LVI**************************/SPMSC1 = 0b00110100; //0x34=&amp;gt; Enable LVISPMSC2 = 0x00;//0b00100000;//0x20 =&amp;gt;LVDV = 1;LVWV = 0; LVD Trip Point = 4.0vSOPT1 = 0x04; // COP Disabled,STOP mode Disabled,SDA on PTB6, SCL on PTB7.SOPT2 = 0x00; //TPM1CH1 on PTB5.TPM1CH0 on PTA0./******************** PORT A ********************/PTAD = 0x00;&amp;nbsp; // Port A Data register&amp;nbsp; (PTAD_PTAD&amp;nbsp; _PTAD.MergedBits.grpPTAD)PTADD = 0x02; // 0b00000010 =&amp;gt;Port A Data Direction register ,I/P= PTA1/PTA2/PTA3,O/P = PTA0PTAPE = 0x00; // Internal pull-up register disabled/******************** PORT B ********************/PTBD = 0x54;&amp;nbsp; // Port B Data registerPTBDD = 0xD6; //0b11010110 =&amp;gt; Port B Data Direction register, I/P= PTA1/PTA2/PTA3,O/P = PTA0PTBPE = 0x00; // Port B Data Direction register ,I/P= PTB0/PTB3/PTB5,O/P = PTB1/PTB2/PTB4/PTB6/PTB7PTBD_PTBD6 = 1; //Discharge the Ign coil./************* Analog Comparator ***************************/ACMPSC = 0x00;//Analog Comparator Disabled/************* Analog To Digital Conversion ***************************/ ADCCFG = 0xD8; //Clock Divide by 4,MODE=&amp;gt;10-bit conversion,Input Clock=&amp;gt;Bus clock. ADCSC2 = 0x00; ADCSC1 = 0x1F;//ADC Module disabled,Interrupt disable APCTL1 = 0x9c; // Analog I/p =&amp;gt; PTA2,PTA3,PTB0,PTB3/*************** Internal Clock Source Select *************************/ICSSC = *(unsigned char*)0xFFAE;&amp;nbsp;&amp;nbsp;&amp;nbsp; ICSTRM = *(unsigned char*)0xFFAF;ICSC1 = 0x04; //Output of FLL is selected.ICSC2 = 0x00;while(!ICSSC_IREFST) {&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* Wait until the source of reference clock is internal clock */&amp;nbsp; }/****I2C ***********/// IICC1 = 0x00; /**************** Modulo Timer *********************************************************///Reset clears TOIE. Do not set TOIE if TOF = 1. Clear TOF first, then set TOIE.MTIMSC = 0x70;&amp;nbsp; //MTIM Status and Control Register//MTIM Overflow Interrupt Enable,MTIM counter is reset to $00,MTIM counter is stopped,MTIMCLK = 0x08; //MTIM Clock Configuration Register //Bus Clock Source Select,Clock Source Prescaler=&amp;gt; ÷ 256 //1 tik count = 16 usec,So MTIM will overflow after 4.096 msecMTIMMOD = 0x00;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; //MTIM Modulo Register/*************** Timer/PWM Module **********************************************************/TPM1SC&amp;nbsp; = 0x46; //TPM counter disable,TPM/64 = 16MHz/64 = 250 KHz,So 1 Count = 4 usec. TPM2SC&amp;nbsp; = 0x46; //TPM counter disable,TPM/64 = 16MHz/64 = 250 KHz,So 1 Count = 4 usec. TPM2MOD = 0x18;// TPM2 will overflow every 100 usec overflow.TPM1C0SC = 0x48;//Channel 0 for capture on falling edge.TPM1C1SC = 0x50;}&lt;/PRE&gt;&lt;/DIV&gt;&lt;BR /&gt;&amp;nbsp;&lt;BR /&gt;&lt;/DIV&gt;&lt;DIV&gt;Regards,&lt;/DIV&gt;&lt;DIV&gt;Deepak.&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 29 Oct 2020 09:17:41 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/SG8-capture-compare-module-query/m-p/169605#M11252</guid>
      <dc:creator>Deepak1</dc:creator>
      <dc:date>2020-10-29T09:17:41Z</dc:date>
    </item>
    <item>
      <title>Re: SG8 capture,compare module query</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/SG8-capture-compare-module-query/m-p/169606#M11253</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;Hi,&lt;/DIV&gt;&lt;DIV&gt;I took your code and rewrote some parts of it.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;1) You should never reset the TPMCNT. It is only reset when coming out of reset.&lt;/DIV&gt;&lt;DIV&gt;This means that all the timing parameter that you enter should be relative, not absolute.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;2) Your application, if&amp;nbsp;I have understood it, only requiers 1 interrupt. It is the interrupt from the falling 100 Hz input signal.&lt;/DIV&gt;&lt;DIV&gt;In this interrupt , there are two ways of setting the desired pulse width.&lt;/DIV&gt;&lt;DIV&gt;Either the outgoing pulse width is important, then read the TPMCNT, add 0x18 and store it in the TPM1C1V register.&lt;/DIV&gt;&lt;DIV&gt;Or if the time from the falling edge to the trailing edge of the pulse width is vital, then read the TPM1C0V, add 0x18 and store it in TPMC1V.&lt;/DIV&gt;&lt;DIV&gt;Use the&amp;nbsp;PULSEHIGHTIME macro to select either method.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;3) The interrupt at the trailing edge of the outgoing pulse is not important.&lt;/DIV&gt;&lt;DIV&gt;You can select to have them with the code using the CH1INTERRUPT macro.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;4) Sorry, I did not have the time to make a beautiful source code. Hope it is readable anyhow.&lt;/DIV&gt;&lt;DIV&gt;I ran the code on a DEMO9S08SH8, which is slightly different than&amp;nbsp; the 9S08SG8. I think that the code will run just the same on a 9S08SG8 MCU.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Regards,&lt;/DIV&gt;&lt;DIV&gt;Ake&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 02 Jul 2008 18:55:36 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/SG8-capture-compare-module-query/m-p/169606#M11253</guid>
      <dc:creator>Ake</dc:creator>
      <dc:date>2008-07-02T18:55:36Z</dc:date>
    </item>
  </channel>
</rss>

