PWM with counters/video generator?
jazzed
Posts: 11,803
Hi,
I'd like to create a PWM with COG counters without having to run a loop in a COG.
Would this be possible using video registers by setting the colors using waitvid just once?
Having to waste an entire COG on PWM as described in AN001 is not desirable.
Thanks.
I'd like to create a PWM with COG counters without having to run a loop in a COG.
Would this be possible using video registers by setting the colors using waitvid just once?
Having to waste an entire COG on PWM as described in AN001 is not desirable.
Thanks.
Comments
What the video generator can do is output a sequence of 32+ (with the last bit repeating) bits at a fixed frequency. Each WAITVID would then output a single sample. You'd still need a cog to periodically do a WAITVID for each sample or the output is locked to the last bit for the next sample. However, depending upon your sample duration, the cog could be doing other things during that time. The WAITVID could also be used to synchronize other activities (i.e. input sampling).
I guess i'll just use a count down variable in the main mailbox control loop to set run the PWM output.
Determinism is not really important in this particular case as the PWM wavelength is about 25ms.
In the Prop 1, the video generator grabs whatever happens to be on the source and destination busses when it times out. waitvid is just a way to make sure that what is on those busses is what you want to be there. As I understand it, the Prop 2 will be different, in that the color and pixel data will be latched internally to be reused in the absence of a waitvid.
BTW, my PWMx8 object in the OBEX uses the video generator to provide PWMing on up to eight channels.
-Phil
Not the video generator, but the following might do what you want. Set it and forget it standard PWM, by overlapping phase of ctra and ctrb on one pin at your selected frequency.
http://obex.parallax.com/objects/668/
Hi Tracy. I was thinking about that third counter in logic mode yesterday. However it didn't really occur to me at the time for some reason that I could use "any" COG to fulfill the logic function since it's passive. Thanks for shaking me out
The key requirement for me is set and forget (not having to use a loop at all to make it work). Looks like Tracy's ideas are perfect. All I have to do is add some setups.
Thanks.
Hi jazzed,
until now I had the luck that in any project I had at least one cog that was repeatedly polling external IO registers (74HC166 or 74HC595) or I²C peripherials or other non timing critical stuff. By adjusting the poll frequency to the PWM frequency I got that PWM "interrupt" almost for free.
1-cog noise free wave player object using NCO PWM. Time is not wasted because the cog is processing the signal between counter updates:
http://forums.parallax.com/showthread.php?141346-Yet-another-wave-player-now-NCO-based-and-noise-%28almost%29-free&highlight=wave
12-bit PWM @ 50 kHz using video generator:
http://forums.parallax.com/showthread.php?141102-12-bit-audio-using-video-generator-first-working-concept&highlight=wave