Shop OBEX P1 Docs P2 Docs Learn Events
PWM with counters/video generator? — Parallax Forums

PWM with counters/video generator?

jazzedjazzed Posts: 11,803
edited 2012-10-07 10:29 in Propeller 1
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.

Comments

  • ericballericball Posts: 774
    edited 2012-10-05 09:46
    Maybe.

    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).
  • jazzedjazzed Posts: 11,803
    edited 2012-10-05 10:00
    Thanks Eric.

    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.
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2012-10-05 10:50
    jazzed wrote:
    Would this be possible using video registers by setting the colors using waitvid just once?

    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
  • Tracy AllenTracy Allen Posts: 6,664
    edited 2012-10-05 11:05
    jazzed wrote: »
    Hi,

    I'd like to create a PWM with COG counters without having to run a loop in a COG.

    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/
  • jazzedjazzed Posts: 11,803
    edited 2012-10-05 11:34
    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.
  • ManAtWorkManAtWork Posts: 2,176
    edited 2012-10-06 08:16
    jazzed wrote: »
    I'd like to create a PWM with COG counters without having to run a loop in a COG.
    ...Having to waste an entire COG on PWM as described in AN001 is not desirable.

    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.
  • pik33pik33 Posts: 2,367
    edited 2012-10-07 10:29
    I did some work in this field:

    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
Sign In or Register to comment.