hi i am using timer 1 to generate a 5kHz square wave but i would like to be able to load the timer with a preset number of pulses for it to generate. for example if i load the timer with 100 it will generate 100 pules at a rate of 5khz then stop until i reset the value in the timer. Can anyone suggest how i might go about doing this or is there a better way of generating a specific number of pulses at a required frequency
many thanks morebudwiser
a Guest
Posted: Thu May 03, 2007 5:42 am
How are you generating the PWM? interrupt? polling? hardware?
morebudwiser
Joined: 17 Oct 2005 Posts: 26
Posted: Thu May 03, 2007 5:53 am
i am using the ccm interrupt to generate the 5khz dont know if this is the best way or not i am open to suggestions. i did try switching an i/o pin high and low put this did not give me and equal mark space ratio
anestho
Joined: 27 Dec 2006 Posts: 28
Posted: Thu May 03, 2007 8:51 am
Define an 8bit integer (assuming 255 is the max pulses you will send). In the interrupt use this as a counter to count from the # of pulses you want to zero. Use an if-then to turn off the interrupt when count reaches 0.
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum