cancel
Showing results for 
Search instead for 
Did you mean: 

PWM spike problem

adib
Associate II
Posted on August 16, 2006 at 15:31

PWM spike problem

3 REPLIES 3
adib
Associate II
Posted on August 16, 2006 at 09:13

Hi,

I am working with ST72F264G2 mcu. I'm using timer A to generate PWM.

In my application I need the PW to change from min to max progressively so I enabled timer A interrupt each time OCR1 (timer reset) happens. In the interrupt subroutine I increment OC1HR,OC1LR by one until I reach max PW. When OC1HR=0 and OC1LR=0x20 the OCMP1 output ''freezes'' momentary and I get a spike on the DC voltage generated by the PWM. After that the PW continues normally.

My micro is runing on 4MHz osc.

Timer A frequency is fcpu/2=1MHz.

PWM frequency is OCR2=3FB = ~976Hz.

Can someone help me?

[ This message was edited by: Gilat on 16-08-2006 12:49 ]

wolfgang2399
Associate II
Posted on August 16, 2006 at 10:53

Hi Gilat,

what is the previous value of OCR1 before you write 0x0020.

With your description I assume it to be 0x001F - correct?

Just an idea:

Attend the Note 1 of chapter 11.3.3.4 Output Compare

 

1. After a processor write cycle to the OCiHR register,

 

the output compare function is inhibited

 

until the OCiLR register is also written.

 

That would mean you have to write first the OC1HR and then the OC1LR. And you should never write only OC1HR without writing to OC1LR immediately afterwards.

WoRo

adib
Associate II
Posted on August 16, 2006 at 15:31

Hi WoRo,

I am aware of the that, actually I increment an image of the OC1HR/OC1LR counter and just before exiting the interrupt routine I load the image register into the OC1R with the correct order HB than LB.

I noticed that the PWM misses 3-4 pulses when the problem happens (I get ''1'' logic on the OCMP1 pin).

I beleive it has something to do with the inhibit of the output compare, maybe it happens when the PW is exactly the same time it takes the micro to perform load of OC1HR and OCR1LB?