<?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 Re: QG8:Vary PWM from ADC reads in 8-bit Microcontrollers</title>
    <link>https://community.nxp.com/t5/8-bit-Microcontrollers/QG8-Vary-PWM-from-ADC-reads/m-p/225728#M19305</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Mac,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you for the explanation, much appreciated. Can you clarify how I calculate the PWM resolution that you mentioned about increasing to Abhijit. My guess is that a TPMMOD value of 255 would deliver an 8 bit resolution or is it not that simple?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Ian&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 20 Jun 2013 07:19:51 GMT</pubDate>
    <dc:creator>iansmusical</dc:creator>
    <dc:date>2013-06-20T07:19:51Z</dc:date>
    <item>
      <title>QG8:Vary PWM from ADC reads</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/QG8-Vary-PWM-from-ADC-reads/m-p/225720#M19297</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt; &lt;/DIV&gt;&lt;P&gt;Hello&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to vary the PWM duty-cycle based on an ADC value.PWM frequency is 16khz&lt;/P&gt;&lt;P&gt;What i am trying to achieve is keep an output current constant by driving MOSFETs through a QG8.An ADC channel measures this current value.&lt;/P&gt;&lt;P&gt;What i see is that the duty-cycle remains unchanged even when ADC values change.&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I think i am doing a very basic mistake , someone please correct me..writing init and ISR codes here&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="color: #0000ff;"&gt;#define TIMER_OVERFLOW&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 60 // us&lt;/STRONG&gt;&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="color: #0000ff;"&gt;interrupt 7 void TimerCH1 (void)&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="color: #0000ff;"&gt;{&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="color: #0000ff;"&gt;&amp;nbsp; // Stops Timer1&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="color: #0000ff;"&gt;&amp;nbsp; TPMSC = TIMER_STOP; &lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; &lt;/P&gt;&lt;P&gt;&lt;STRONG style="color: #0000ff;"&gt;&amp;nbsp;&amp;nbsp; if(current_adjust&amp;gt;512) // 1.5v corresponds to 5A&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="color: #0000ff;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="color: #0000ff;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; duty_cycle_variation--;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="color: #0000ff;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if(duty_cycle_variation&amp;lt;=1)duty_cycle_variation=1;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="color: #0000ff;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&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;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/P&gt;&lt;P&gt;&lt;STRONG style="color: #0000ff;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if(current_adjust&amp;lt;512)&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #0000ff;"&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #0000ff;"&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; duty_cycle_variation++;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #0000ff;"&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if(duty_cycle_variation&amp;gt;=100)duty_cycle_variation=100;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #0000ff;"&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #0000ff;"&gt;&lt;STRONG&gt;&amp;nbsp; TPMC1V = duty_cycle_variation;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #0000ff;"&gt;&lt;STRONG&gt;&amp;nbsp; // Restarts Timer1&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #0000ff;"&gt;&lt;STRONG&gt;&amp;nbsp; TPMSC = TIMER_START;&amp;nbsp; &lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #0000ff;"&gt;&lt;STRONG&gt;}&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #0000ff;"&gt;&lt;STRONG&gt;void Timer1_init(void)&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #0000ff;"&gt;&lt;STRONG&gt;{&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #0000ff;"&gt;&lt;STRONG&gt;&amp;nbsp; // Timer1 period&amp;nbsp; &lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #0000ff;"&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; TPMMOD = TIMER_OVERFLOW; //15ms&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #0000ff;"&gt;&lt;STRONG&gt;//Initial duty cycle&amp;nbsp; &lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #0000ff;"&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; TPMC1V=0;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #0000ff;"&gt;&lt;STRONG&gt;&amp;nbsp; // Selects PWM Low-true pulses in the Timer1 Channel0 (PTA0/TPM1CH0) &lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #0000ff;"&gt;&lt;STRONG&gt;&amp;nbsp; TPMC1SC = 0x028; //flag=0|ch_int_dis=0|MSnBA=10=edge aligned PWM|ELSBA=01=set o/p on compare|00&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #0000ff;"&gt;&lt;STRONG&gt;&amp;nbsp; // Starts Timer1&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;&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;&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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ELSBA=10=clr o/p on compare&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #0000ff;"&gt;&lt;STRONG&gt;&amp;nbsp; //TPMSC = TIMER_START;&amp;nbsp; //0,TOIE=1,CPWMS=0,CLKSAB=01 PS2-0=011(div/8=1us)&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #0000ff;"&gt;&lt;STRONG&gt; }&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Someone please help&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks and regards&lt;/P&gt;&lt;P&gt;&lt;SPAN class="mce_paste_marker"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 18 Jun 2013 10:39:18 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/QG8-Vary-PWM-from-ADC-reads/m-p/225720#M19297</guid>
      <dc:creator>abicash</dc:creator>
      <dc:date>2013-06-18T10:39:18Z</dc:date>
    </item>
    <item>
      <title>Re: QG8:Vary PWM from ADC reads</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/QG8-Vary-PWM-from-ADC-reads/m-p/225721#M19298</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;There are a few factors that you need to take into account -&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;For the 'HCS08 device, PWM mode for the TPM module is buffered.&amp;nbsp; Changes to the TPMC1V register &lt;SPAN style="text-decoration: underline;"&gt;do not&lt;/SPAN&gt; need to occur within an ISR - the duty will be automatically updated just prior to the next TPM overflow.&amp;nbsp; Certainly the TPM module should not be disabled and re-enabled, as you are doing.&lt;/LI&gt;&lt;LI&gt;Since your TPMMOD value is set to 60, this means that the TPMC1V operating range will be 0 to 61.&amp;nbsp; Any value above 60 will result in 100 percent duty.&lt;/LI&gt;&lt;LI&gt;If you require that the update of the PWM duty be synchronised to each new ADC reading, this means that the ADC reading will require to be competed and processed within somewhat less than the PWM period.&amp;nbsp; To achieve this you would need to reduce your PWM frequency (this will also increase the PWM resolution).&amp;nbsp; Presumably the ADC resolution would be 8-bits.&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;One possible approach to synchronise the ADC and PWM operation would be to utilise the TPM overflow interrupt.&amp;nbsp; Within the ISR code, the previous ADC conversion would be read, and a new ADC conversion started.&amp;nbsp; The result just obtained would then be processed to update the TPMC1V register.&amp;nbsp; Since the actual PWM duty would udate just prior to the &lt;SPAN style="text-decoration: underline;"&gt;next&lt;/SPAN&gt; overflow, the control would lag by at least one PWM period.&amp;nbsp; However, you would need substantial filtering, over many PWM periods, to sense the average load current.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Assume you were using a bus frequency of 10 MHz and an ADC clock of 5 MHz.&amp;nbsp; With short sampling interval, the ADC conversion time would be equivalent 45 bus cycles.&amp;nbsp; To this you would need to add the number of cycles required to enter the ISR, plus the cycles for reading of the previous result and starting the new conversion.&amp;nbsp; The minimum PWM period should be somewhat greater than this value, provided the additional cycles to complete and exit the ISR does not exceed 45 cycles.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;It is also possible that the occurrence of other interrupts may affect the stability of your control system.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Mac&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 19 Jun 2013 04:43:53 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/QG8-Vary-PWM-from-ADC-reads/m-p/225721#M19298</guid>
      <dc:creator>bigmac</dc:creator>
      <dc:date>2013-06-19T04:43:53Z</dc:date>
    </item>
    <item>
      <title>Re: QG8:Vary PWM from ADC reads</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/QG8-Vary-PWM-from-ADC-reads/m-p/225722#M19299</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Mac&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks for replying!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have done some changes according to your suggestion.&lt;/P&gt;&lt;P&gt;I am measuring 4 ADC values (8 samples each) a 16x2 LCD and other interrupts as well.So the loop is bound to be sluggish&lt;/P&gt;&lt;P&gt;I do not expect instantaneous correction in PWM since i am trying to charge a battery and it isn't hazardous.&lt;/P&gt;&lt;P&gt;What i want to achieve is driving a source from a MOSFET to a battery and another load.The other load demands&amp;nbsp; much more current than the battery.&lt;/P&gt;&lt;P&gt;I want to keep the battery charging at 10A and provide the load with whatever current it demands.So i want to keep the dutycycle under check till battery demands 10A current and when load demands more current duty cycle has to be increased&lt;/P&gt;&lt;P&gt;I will write some snippets here...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #3366ff;"&gt;&lt;STRONG&gt;&lt;EM&gt;ADC init&lt;/EM&gt;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #3366ff;"&gt;&lt;STRONG&gt;&lt;EM&gt;void Init_ADC(void)&lt;/EM&gt;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #3366ff;"&gt;&lt;STRONG&gt;&lt;EM&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&amp;nbsp; &lt;/EM&gt;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #3366ff;"&gt;&lt;STRONG&gt;&lt;EM&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ADCSC1&amp;nbsp; = 0x1F;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="color: #ff0000;"&gt;// No ADC channel selected during config&lt;/SPAN&gt;&lt;/EM&gt;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #3366ff;"&gt;&lt;STRONG style="color: #ff0000;"&gt;&lt;EM&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; //&amp;nbsp; ADCCFG&amp;nbsp; = 0xF8;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // Bus clk, 10-bit, long sampling, clock/2 &amp;amp; low power&lt;/EM&gt;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #3366ff;"&gt;&lt;STRONG&gt;&lt;EM&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ADCCFG&amp;nbsp; = 0x09;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="color: #ff0000;"&gt;// Bus clk, 10-bit, short sampling, clock/2 &amp;amp; high speed&lt;/SPAN&gt;&lt;/EM&gt;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #3366ff;"&gt;&lt;STRONG&gt;&lt;EM&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ADCSC2&amp;nbsp; = 0x00;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="color: #ff0000;"&gt;// S/w trigger, no compare&lt;/SPAN&gt;&lt;/EM&gt;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #3366ff;"&gt;&lt;STRONG&gt;&lt;EM&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; APCTL1_ADPC7&amp;nbsp; = 1&amp;nbsp;&amp;nbsp; ;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="color: #ff0000;"&gt;// Pin I/O disabled for ADP7&lt;/SPAN&gt;&lt;/EM&gt;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #3366ff;"&gt;&lt;STRONG&gt;&lt;EM&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; APCTL1_ADPC6&amp;nbsp; = 1&amp;nbsp;&amp;nbsp; ;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="color: #ff0000;"&gt;// Pin I/O disabled for ADP6&lt;/SPAN&gt;&lt;/EM&gt;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #3366ff;"&gt;&lt;STRONG&gt;&lt;EM&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; APCTL1_ADPC5&amp;nbsp; = 1&amp;nbsp;&amp;nbsp; ;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="color: #ff0000;"&gt;// Pin I/O disabled for ADP5&lt;/SPAN&gt;&lt;/EM&gt;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #3366ff;"&gt;&lt;STRONG&gt;&lt;EM&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; APCTL1_ADPC4&amp;nbsp; = 1&amp;nbsp;&amp;nbsp; ;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="color: #ff0000;"&gt;// Pin I/O disabled for ADP4&lt;/SPAN&gt;&lt;/EM&gt;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #3366ff;"&gt;&lt;STRONG&gt;&lt;EM&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; } &lt;/EM&gt;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #3366ff;"&gt;&lt;STRONG&gt;&lt;EM&gt;interrupt 7 void TimerCH1 (void)&lt;/EM&gt;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="color: #3366ff;"&gt;&lt;STRONG&gt;&lt;EM&gt;{&lt;/EM&gt;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="color: #ff0000;"&gt;&lt;STRONG&gt;&lt;EM&gt;&amp;nbsp; // Stops Timer1&lt;/EM&gt;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="color: #3366ff;"&gt;&lt;STRONG&gt;&lt;EM&gt;&amp;nbsp; TPMSC = TIMER_STOP; &lt;/EM&gt;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="color: #3366ff;"&gt;&lt;STRONG&gt;&lt;EM&gt;&amp;nbsp;&amp;nbsp; ADCSC1_test= ADCSC1; &lt;SPAN style="color: #ff0000;"&gt;//to unharm other ADC reads which r out of this ISR&lt;/SPAN&gt;&lt;/EM&gt;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="color: #3366ff;"&gt;&lt;STRONG&gt;&lt;EM&gt;&amp;nbsp;&amp;nbsp; ADCSC1 = 0x07 ;&lt;/EM&gt;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="color: #3366ff;"&gt;&lt;STRONG&gt;&lt;EM&gt;&amp;nbsp;&amp;nbsp; while (!ADCSC1_COCO);&lt;/EM&gt;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="color: #3366ff;"&gt;&lt;STRONG&gt;&lt;EM&gt;&amp;nbsp; current_adjust=ADCR;&lt;/EM&gt;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #3366ff;"&gt;&lt;STRONG&gt;&lt;EM&gt;&amp;nbsp; if(current_adjust&amp;lt;=4) current_adjust=4; &lt;SPAN style="color: #ff0000;"&gt;//min duty&lt;/SPAN&gt;&lt;/EM&gt;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #3366ff;"&gt;&lt;STRONG&gt;&lt;EM&gt;&amp;nbsp;&amp;nbsp; TPMC1V = current_adjust; &lt;/EM&gt;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="color: #3366ff;"&gt;&lt;STRONG&gt;&lt;EM&gt;&amp;nbsp;&amp;nbsp; ADCSC1= ADCSC1_test ; &lt;SPAN style="color: #ff0000;"&gt;//to retain other ADC readings&lt;/SPAN&gt;&lt;/EM&gt;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="color: #ff0000;"&gt;&lt;STRONG&gt;&lt;EM&gt;&amp;nbsp; // Restarts Timer1&lt;/EM&gt;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="color: #3366ff;"&gt;&lt;STRONG&gt;&lt;EM&gt;&amp;nbsp; TPMSC = TIMER_START;&amp;nbsp; &lt;/EM&gt;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="color: #3366ff;"&gt;&lt;STRONG&gt;&lt;EM&gt;}&lt;/EM&gt;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #3366ff;"&gt;&lt;STRONG&gt;&lt;EM&gt;void Timer1_init(void)&lt;/EM&gt;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #3366ff;"&gt;&lt;STRONG&gt;&lt;EM&gt;{&lt;/EM&gt;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff0000;"&gt;&lt;STRONG&gt;&lt;EM&gt;&amp;nbsp; // Timer1 period&amp;nbsp; &lt;/EM&gt;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #3366ff;"&gt;&lt;STRONG&gt;&lt;EM&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; TPMMOD = TIMER_OVERFLOW; &lt;SPAN style="color: #ff0000;"&gt;//200us&lt;/SPAN&gt;&lt;/EM&gt;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff0000;"&gt;&lt;STRONG&gt;&lt;EM&gt;//Initial duty cycle&amp;nbsp; &lt;/EM&gt;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #3366ff;"&gt;&lt;STRONG&gt;&lt;EM&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; TPMC1V=0;&lt;/EM&gt;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff0000;"&gt;&lt;STRONG&gt;&lt;EM&gt;&amp;nbsp; // Selects PWM Low-true pulses in the Timer1 Channel0 (PTA0/TPM1CH0) &lt;/EM&gt;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #3366ff;"&gt;&lt;STRONG&gt;&lt;EM&gt;&amp;nbsp; TPMC1SC = 0x024; &lt;SPAN style="color: #ff0000;"&gt;//flag=0|ch_int_dis=0|MSnBA=10=edge aligned PWM|ELSBA=01=set o/p on compare|00&lt;/SPAN&gt;&lt;/EM&gt;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff0000;"&gt;&lt;STRONG&gt;&lt;EM&gt;&amp;nbsp; // Starts Timer1&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;&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;&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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ELSBA=10=clr o/p on compare&lt;/EM&gt;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #3366ff;"&gt;&lt;STRONG&gt;&lt;EM&gt;&amp;nbsp; //TPMSC = TIMER_START;&amp;nbsp; &lt;SPAN style="color: #ff0000;"&gt;//0,TOIE=1,CPWMS=0,CLKSAB=01 PS2-0=011(div/8=1us)&lt;/SPAN&gt;&lt;/EM&gt;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #3366ff;"&gt;&lt;STRONG&gt;&lt;EM&gt; }&lt;/EM&gt;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Your suggestion to keep TPM enabled does not provide time for other peripherals, so am forced to disable it in ISR.&lt;/P&gt;&lt;P&gt;&lt;SPAN class="mce_paste_marker"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="mce_paste_marker"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;DIV&gt; &lt;/DIV&gt;&lt;DIV&gt; &lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 19 Jun 2013 06:22:02 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/QG8-Vary-PWM-from-ADC-reads/m-p/225722#M19299</guid>
      <dc:creator>abicash</dc:creator>
      <dc:date>2013-06-19T06:22:02Z</dc:date>
    </item>
    <item>
      <title>Re: QG8:Vary PWM from ADC reads</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/QG8-Vary-PWM-from-ADC-reads/m-p/225723#M19300</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello Mac,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Not meaning to hijack this thread but could I get you to explain this comment you made in your answer please?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; "To achieve this you would need to reduce your PWM frequency (this will also increase the PWM resolution)."&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Is there anywhere I could refer to about this to gain a better understanding in preparation of using the TPM in PWM mode for an RGB LED project I'm about to start.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Ian&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 19 Jun 2013 11:40:38 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/QG8-Vary-PWM-from-ADC-reads/m-p/225723#M19300</guid>
      <dc:creator>iansmusical</dc:creator>
      <dc:date>2013-06-19T11:40:38Z</dc:date>
    </item>
    <item>
      <title>Re: QG8:Vary PWM from ADC reads</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/QG8-Vary-PWM-from-ADC-reads/m-p/225724#M19301</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello Ian&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;What Mac means is &lt;/P&gt;&lt;P&gt;Increase TPMMOD (overflow value) so that effectively frequency is reduced&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 19 Jun 2013 12:08:41 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/QG8-Vary-PWM-from-ADC-reads/m-p/225724#M19301</guid>
      <dc:creator>abicash</dc:creator>
      <dc:date>2013-06-19T12:08:41Z</dc:date>
    </item>
    <item>
      <title>Re: QG8:Vary PWM from ADC reads</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/QG8-Vary-PWM-from-ADC-reads/m-p/225725#M19302</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Abhijit,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks for the reply and yes I can see how increasing TPMMOD will reduce the frequency but how is the PWM resolution calculated/changed? As I understand it's a 16 bit timer but if the TPMMOD is 255 max then the PWM resolution is 8 bits... is it that simple!?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Ian&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 19 Jun 2013 12:16:33 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/QG8-Vary-PWM-from-ADC-reads/m-p/225725#M19302</guid>
      <dc:creator>iansmusical</dc:creator>
      <dc:date>2013-06-19T12:16:33Z</dc:date>
    </item>
    <item>
      <title>Re: QG8:Vary PWM from ADC reads</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/QG8-Vary-PWM-from-ADC-reads/m-p/225726#M19303</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello Abhijit,&lt;/P&gt;&lt;BLOCKQUOTE&gt;
&lt;P&gt;Abhijit Jagtap wrote:&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;Your suggestion to keep TPM enabled does not provide time for other peripherals, so am forced to disable it in ISR.&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I do not understand your concern.&amp;nbsp; When the TPM module is operating in PWM mode, the output is quite independent of, and does not affect the operation of any other peripheral module.&amp;nbsp; The PWM channel interrupt would usually remain disabled.&amp;nbsp; When ready to update the duty value, simply write the new value to the TPM channel register (TPMC1V) and the change of waveform will be automatically synchronised, as previously explained.&amp;nbsp; In fact, disabling and re-enabling the TPM module may potentially disrupt the PWM waveform because the normal "coherency" mechanism. would be temporarily disabled.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Since you have no synchronisation issues between the ADC operation and the PWM waveform, the only reason you might have the TPM overflow interrupt enabled would be for general timing purposes.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You're averaging of more than one reading for each ADC channel is presumably to reduce noise fluctuations.&amp;nbsp; To reduce the effect of mains hum, you could equally space the ADC samples for each channel, so that the average value would apply over a 20ms period.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I notice that you have a prescale setting of 8.&amp;nbsp; I suggest that you use a prescale setting of 1, and multiply the TPMMOD value by 8.&amp;nbsp; This will increase the PWM resolution by the same factor.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;It is unclear how many ADC channels that you actually require.&amp;nbsp; You appear to have four enabled (channels 4 to 7).&amp;nbsp; However, I would suggest that you simultaneously write to all bits of the APCTL1 register, rather than one bit at a time.&amp;nbsp; This will improve the efficiency of your code (fewer bytes and fewer cycles).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Mac&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 20 Jun 2013 03:07:31 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/QG8-Vary-PWM-from-ADC-reads/m-p/225726#M19303</guid>
      <dc:creator>bigmac</dc:creator>
      <dc:date>2013-06-20T03:07:31Z</dc:date>
    </item>
    <item>
      <title>Re: QG8:Vary PWM from ADC reads</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/QG8-Vary-PWM-from-ADC-reads/m-p/225727#M19304</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello Ian,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The TPM module uses a 16-bit counter, with the ability to adjust the modulo value to a smaller value.&amp;nbsp; For PWM operation, the modulo value TPMMOD, in conjunction with the TPM prescale value and the bus frequency, will determine the PWM frequency.&amp;nbsp; The PWM period is given by (TPMMOD + 1) * prescale / fbus.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This means that the maximum count is TPMMOD, and the counter will again become zero on the next TPM clock.&amp;nbsp; The PWM duty is given by TPMCnV / (TPMMOD + 1).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Mac&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 20 Jun 2013 03:24:57 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/QG8-Vary-PWM-from-ADC-reads/m-p/225727#M19304</guid>
      <dc:creator>bigmac</dc:creator>
      <dc:date>2013-06-20T03:24:57Z</dc:date>
    </item>
    <item>
      <title>Re: QG8:Vary PWM from ADC reads</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/QG8-Vary-PWM-from-ADC-reads/m-p/225728#M19305</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Mac,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you for the explanation, much appreciated. Can you clarify how I calculate the PWM resolution that you mentioned about increasing to Abhijit. My guess is that a TPMMOD value of 255 would deliver an 8 bit resolution or is it not that simple?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Ian&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 20 Jun 2013 07:19:51 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/QG8-Vary-PWM-from-ADC-reads/m-p/225728#M19305</guid>
      <dc:creator>iansmusical</dc:creator>
      <dc:date>2013-06-20T07:19:51Z</dc:date>
    </item>
    <item>
      <title>Re: QG8:Vary PWM from ADC reads</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/QG8-Vary-PWM-from-ADC-reads/m-p/225729#M19306</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello Ian,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The step increment in duty is given by 1/(TPMMOD + 1).&amp;nbsp; The OP was using a TPMMOD value of 60, with a prescale factor of 8.&amp;nbsp; My previous comment suggested that the prescale value could be set to 1, and the TPMMOD value increased to 487, so as to produce exactly the same PWM frequency.&amp;nbsp; This would result in the step increment being reduced by a factor of 8, i.e. 1/488 instead of 1/61.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Mac&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 21 Jun 2013 03:17:28 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/QG8-Vary-PWM-from-ADC-reads/m-p/225729#M19306</guid>
      <dc:creator>bigmac</dc:creator>
      <dc:date>2013-06-21T03:17:28Z</dc:date>
    </item>
    <item>
      <title>Re: QG8:Vary PWM from ADC reads</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/QG8-Vary-PWM-from-ADC-reads/m-p/225730#M19307</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello Mac&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;"When the TPM module is operating in PWM mode, the output is quite independent of, and does not affect the operation of any other peripheral module"&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;&lt;BR /&gt;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;This is not happening.I have to force shut it in the ISR , change the duty and restart the timer, only then will it work.&lt;/P&gt;&lt;P&gt;Not working means that i get the least duty cycle and as i see in the True time simulator , no other variables are being updated.(same thing happens when i am not connecting the debugger)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I tried thus&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;read ADC value;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;check for limits;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;increase or decrease duty cycle depending on set values;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;check limits for max and min duty;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;write to TPMC1V in ISR;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;&lt;BR /&gt;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;I have selected&lt;/P&gt;&lt;P&gt;&lt;EM&gt;TPMMOD = 1024;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;TPMSC= 0x48;// tried with 0x49&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;&lt;BR /&gt;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;I repeat , the duty cycle variation works &lt;SPAN style="text-decoration: underline;"&gt;only when i stop and start time&lt;/SPAN&gt;r in isr&lt;/P&gt;&lt;P&gt;The only issue here is than i cannot reach Duty cycle above 90%, here waveform becomes unstable.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Can you please help??&lt;/P&gt;&lt;DIV&gt; &lt;/DIV&gt;&lt;DIV&gt; &lt;/DIV&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Message was edited by: Abhijit Jagtap&#xD;
Forgot to mention one more thing.&#xD;
&#xD;
I have changed &#xD;
TPMC1SC = 0x028;//from 0x24&#xD;
&#xD;
i get waves as attached (with different time bases)&#xD;
you can see an unwanted SET o/p when o/p should be low...&#xD;
cant understand why this is happening......&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 26 Jun 2013 06:36:25 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/QG8-Vary-PWM-from-ADC-reads/m-p/225730#M19307</guid>
      <dc:creator>abicash</dc:creator>
      <dc:date>2013-06-26T06:36:25Z</dc:date>
    </item>
    <item>
      <title>Re: QG8:Vary PWM from ADC reads</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/QG8-Vary-PWM-from-ADC-reads/m-p/225731#M19308</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I suggest that you attach your project to this thread so that others may test.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Using the overflow interrupt, presumably on every overflow, I would expect that there would be a minimum allowable duty dependent on the latency and execution time of the ISR.&amp;nbsp; To minimize the execution time, only the update of the TPMC1V value should be done within the ISR - the limit checks, etc. could be done within the main loop.&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Mac&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 26 Jun 2013 18:21:57 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/QG8-Vary-PWM-from-ADC-reads/m-p/225731#M19308</guid>
      <dc:creator>bigmac</dc:creator>
      <dc:date>2013-06-26T18:21:57Z</dc:date>
    </item>
    <item>
      <title>Re: QG8:Vary PWM from ADC reads</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/QG8-Vary-PWM-from-ADC-reads/m-p/225732#M19309</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello Mac&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I figured it out.&lt;/P&gt;&lt;P&gt;I wasn't reading and resetting the TOF flag!!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Now it works as expected :smileyhappy:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks and Regards&lt;/P&gt;&lt;P&gt;Abhijit&lt;/P&gt;&lt;DIV&gt; &lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 27 Jun 2013 05:17:47 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/QG8-Vary-PWM-from-ADC-reads/m-p/225732#M19309</guid>
      <dc:creator>abicash</dc:creator>
      <dc:date>2013-06-27T05:17:47Z</dc:date>
    </item>
  </channel>
</rss>

