Shop OBEX P1 Docs P2 Docs Learn Events
More help with counters. Simple minded use of Duty cycle mode — Parallax Forums

More help with counters. Simple minded use of Duty cycle mode

pgbpsupgbpsu Posts: 460
edited 2009-09-03 20:00 in Propeller 1
I'm trying to use the Duty cycle section in the Prop App note (AN001) to get a 50% duty square wave. Although that's not my final goal I thought I should start very simply since I'm not very familiar with using the counters.

I understand I need to setup the CTRA and FRQA registers. I
PUB Duty_mode
'                  mode  PLL                    BPIN           APIN
              '1_09876_543_21098765_432109_876_543210
  CTRA     := %0_00110_000_00000000_000000_000_010011  'Establish mode and APIN (BPIN is ignored)
'  PHSA     := 0
  FRQA     := $8000_0000                                'Set FRQA so PHSA[noparse][[/noparse]31] toggles every clock
  dira[noparse][[/noparse]%1_0011] := 1                                    'Set APIN to output
  repeat                                                'infinite loop, so counter continues to run

                         




When I run this I get a very ratty waveform that looks to be beyond the abilities of my 50Mhz scope. I suspect that I was missing the fact that in this mode the outgoing waveform will be 80Mhz (since that's my system clock) and I only have control over the duty. Is that correct?

Is there a way to slow this down without adjusting the system clock? What I'd really like is a user selectable frequency and duty cycle. Most likely it would be something like 150Khz wave with 1.5% duty cycle. To put it another way, I need the high part of the waveform to be as narrow as 100ns, but I only need a new cycle about every ~6uSec.

I had some brute force PASM code, but I couldn't get the smallest high-time below 150nS because it took me too many instructions.

Does anyone know how to divide down the clock for Duty mode?

Thanks,
Peter

Comments

  • max72max72 Posts: 1,155
    edited 2009-09-03 14:05
    Try to check the synth object and the synth demo in the propeller tool install directory.

    Massimo
  • JonnyMacJonnyMac Posts: 9,198
    edited 2009-09-03 14:24
    You can't get a variable-duty, fixed-frequency waveform from the counters programming them stand-alone; you need a bit of PASM to fix the output frequency. I'm hoping the next generation Propeller has an additional phase register that allows for set-and-forget programming for frequency and duty cycle (the SX48 has a mode for its times that allows this).
  • pgbpsupgbpsu Posts: 460
    edited 2009-09-03 14:28
    @Massimo-

    Thanks for the suggestion. I took a look at that and it uses the NCO mode of the counter which I believe only allows 50% duty. I need to be able to vary the duty cycle so I think I've got to use the Duty mode. I need to vary the Frequency which I'm not sure is possible in that mode.

    p
  • pgbpsupgbpsu Posts: 460
    edited 2009-09-03 14:44
    @JonnyMac

    Thanks for responding. After reading your post I realized I didn't present my problem accurately. It still may not be possible, but I think it makes my requirements a bit easier.

    I need a stable waveform that has a given frequency and duty cycle. If I need to change that duty cycle, I'm happy to shutdown the cog, re-program the registers and start up again. Once I've picked a frequency and duty cycle, that cog will stay that way until I kill it off. So my request for varying-duty isn't accurate. If I can simply select the duty cycle and frequency, I'll be satisfied.

    Do you have an example of some PASM that shows how to fix the output frequency?

    Thanks,
    p
  • mctriviamctrivia Posts: 3,772
    edited 2009-09-03 14:48
    Look at wav player in obex definetly possible.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    propmod_us and propmod_1x1 are in stock. Only $30. PCB available for $5

    Want to make projects and have Gadget Gangster sell them for you? propmod-us_ps_sd and propmod-1x1 are now available for use in your Gadget Gangster Projects.

    Need to upload large images or movies for use in the forum. you can do so at uploader.propmodule.com for free.
  • RaymanRayman Posts: 14,849
    edited 2009-09-03 14:52
    Would Beau's PWM driver help?

    http://forums.parallax.com/showthread.php?p=829640



    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    My Prop Info&Apps: ·http://www.rayslogic.com/propeller/propeller.htm
  • Beau SchwabeBeau Schwabe Posts: 6,568
    edited 2009-09-03 15:13
    Phil Pilgrim's version is probably what you want. His method takes it a couple of steps further using the Video section to generate 8 independent channels of PWM. ... Phil Pilgrim's initial release ... program located in the OBEX

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Beau Schwabe

    IC Layout Engineer
    Parallax, Inc.

    Post Edited (Beau Schwabe (Parallax)) : 9/3/2009 3:27:37 PM GMT
  • max72max72 Posts: 1,155
    edited 2009-09-03 17:05
    As an alternative approach there is a nice article on the July issue of Nuts and Volts. It is focused on the LEDs, but is should work for you case too, and the article is very inspiring.

    Massimo
  • pgbpsupgbpsu Posts: 460
    edited 2009-09-03 17:25
    mctriva, Rayman, Beau, and Massimo-

    Thanks for all the leads. I'm convinced there's a way to get this working the way I need to. Now I've just got to get through all these suggestions and figure out which works best/simplest.

    Thanks,
    Peter
  • Tracy AllenTracy Allen Posts: 6,664
    edited 2009-09-03 20:00
    To make a variable duty cycle, constant frequency, set it and forget it PWM, employ both counters A and B. Set them both for NCO mode at the same frequency, offset the starting phases, and both address the same pin. Since the pin is a logical OR of the two outputs, you can see duty cycles from 50% to 100%, or from 0% to 50% depending on how you look at it. A circuit trick with an XOR gate can extend it over the whole range.

    PUB NCO_fixedPWM
      FRQa := 53687    ' 1000 Hz with 80mHz clock
      PHSa := 0     ' 50% by itself
      PHSb := 1,073,741,824   ' 0x40000000, offest 1/4 cycle, combined 75% high 25% low
      CTRa := %0_00100_000_00000000_000000_000_000101   ' both NCO mode to pin 5
      CTRb := %0_00100_000_00000000_000000_000_000101
      dira(5)~~   ' attaches the phs(31) bit of counters a OR b to the pin 5, frequency 1000 hertz, duty 75%
    

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
Sign In or Register to comment.