Shop OBEX P1 Docs P2 Docs Learn Events
PWM object not enough control — Parallax Forums

PWM object not enough control

grasshoppergrasshopper Posts: 438
edited 2008-12-19 21:20 in Propeller 1
Any one know of a way that i can modify the PWM object for better control? Instead of 0 - 100 I am looking for something that I can adjust from 0 - 10_00 or even better if possible.
Some things i thought of changing were below


PUB SetDuty(counts)
   if (counts < 0)
     counts := 0
   if (counts > 10_000)
     counts := 10_000
   sDuty :=counts*sPeriod/10_000
   




Any ideas if this is the right aproach?

Comments

  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2008-12-18 19:58
    If you use the PWM_x8 object, the resolution is settable by a CONstant in the object itself. Just make sure it's a multiple of four.

    -Phil

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    'Just a few PropSTICK Kit bare PCBs left!
  • T ChapT Chap Posts: 4,223
    edited 2008-12-18 20:31
    If you look at pwmasm, you can set the duty like below(this is set to duty 1000) as this does work.




    PUB SetDuty(counts)
       if (counts < 0)
         counts := 0
       if (counts > 1000)                       '100 = 100 duty, 1000 = 1000 duty, etc
         counts := 1000                         '100 = 100 duty  
       sDuty :=counts*sPeriod/1000      '100 = 100 duty
    

    Post Edited (TChapman) : 12/18/2008 8:45:25 PM GMT
  • Paul RowntreePaul Rowntree Posts: 49
    edited 2008-12-19 02:57
    Hi Grasshopper;
    Oddly enough, I was just working on that for a motor driver. I use the PWM to drive the base of a TIP120, and it gives a very nice ramp from about 10 Hz up to 200 Hz, apparently linear in duty cycle. This is taken from other files on the Parallax site, I claim no originality or cleverness in the modifications. It is here buzzing away beside me as I type!

    Note that I changes the start method as well for my own style. I also added some parentheses in the driver to avoid overflows.

    Cheers!
  • grasshoppergrasshopper Posts: 438
    edited 2008-12-19 21:20
    Yea,

    Thanks all. I think I got it working better now. Using the modified code works.
Sign In or Register to comment.