pwm generation using ic MC68HC908JK3E

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

pwm generation using ic MC68HC908JK3E

1,732 Views
sathya
Contributor I
Hi,
 am sathya
i want to generate the pwm, using the MC68HC908JK3E
 the problem is AS U KNOW der r one timer and two channrels
am using CH0 ,i.e PIN NUM 19
  
   am using TIMCH0 Interrupt to generate a pwm
i.e wen compareoccures it cals the interrupt and into the ISR
    WEN I USING EQUAL WIDTH ,I GOT THE PWM OF Equal
width,
but wen i go for varying pule width ,not able get the varying pwm
dat means if we give the 8 varying count in the CH0 Interrupt  corresponding to the pwm width,
at dat time some values are skipping
 derfore can u suggest hw to use interrupts to generate the pwm ?
 and i am using codewarrior 5.7.0

the code is below can u reply ?





Labels (1)
0 Kudos
Reply
2 Replies

460 Views
bigmac
Specialist III
Hello Sathya,
 
Your timer setup for unbuffered PWM on channel 0 appears to be correct, and you are also correct in changing the PWM pulse width within the channel 0 interrupt handler (after the PWM output has gone low).
 
The issue appears to be that, since you are incrementing the width following each interrupt, there will actually be two interrupts per PWM cycle, the first time after timer overflow has occurred and the output is high (after toggle on overlow), and the second time on the increased channel value, prior to the next timer overflow when the output is still low.
 
The simplest way to handle this situation would be to test the timer overflow flag, and only if the flag is set, to update the channel value.  Perhaps your interrupt handler might be modified as follows -
 
#pragma TRAP_PROC
interrupt void TIMCH0_Interrupt(void)
{
   TSC0_CH0F = 0;  // Clear channel 0 flag
   if (TSC_TOF) {  // Test for overflow flag set
      TSC_TOF = 0; // Clear overflow flag
      TCH0L = sinewave[i];
      i++;
      if (i > 7)
         i = 0;
   }
}
 
It should be unnecessary to make use of a second timer channel.
 
Regards,
Mac
 
0 Kudos
Reply

460 Views
JimDon
Senior Contributor III
I suggest that you really want to use two different timer channels.

One that is the PWM channel, and one that changes the duty cycle of the PWM channel to generate the desired wave form.

The PWM channel does not need to be serviced by an interrupt. You need need an interrupt to generate a nice wave form, but it's job should be to vary the duty cycle of the PWM channel.


0 Kudos
Reply