PWM not working?


Closed Thread
Results 1 to 4 of 4
  1. #1
    Join Date
    Jan 2006
    Location
    New Hampshire, USA
    Posts
    107

    Default PWM not working?

    This program runs (produces pulses of varying width):
    Code:
    REM DEVICE = 12F675
        CMCON = 7           'SETS DIGITAL MODE
        ANSEL = 0           'GPIO.0 TO GPIO.3 SET AS DIGITAL
        TRISIO = 0          'ALL OUTPUTS BUTGP3 (PIN4) IS INPUT ONLY
        VRCON.7 = 0         'TURN OFF VOLTAGE REFERENCE TO SAVE POWER
        DEFINE OSCCAL_1K 1  'TO SAVE OSCILLATOR CALIBRATION
            tme var word    'BEGINNING NUMBER OF PULSE CYCLES(COUNT DOWN)
            d var byte  'DUTY CYCLE OF PULSE, 127=50%
            j var word  'NUMBER OF CYCLES OF PULSE
        START:
           
             FOR d = 50 TO 250
             PWM GPIO.0,d,1
             PAUSEUS 500
             NEXT D
            
           GOTO START 
            end
    This program does not:
    Code:
    REM DEVICE = 12F675
        CMCON = 7           'SETS DIGITAL MODE
        ANSEL = 0           'GPIO.0 TO GPIO.3 SET AS DIGITAL
        TRISIO = 0          'ALL OUTPUTS BUTGP3 (PIN4) IS INPUT ONLY
        VRCON.7 = 0         'TURN OFF VOLTAGE REFERENCE TO SAVE POWER
        DEFINE OSCCAL_1K 1  'TO SAVE OSCILLATOR CALIBRATION
            tme var word    'BEGINNING NUMBER OF PULSE CYCLES(COUNT DOWN)
            d var byte  'DUTY CYCLE OF PULSE, 127=50%
            j var word  'NUMBER OF CYCLES OF PULSE
        START:
           
             FOR d = 250 TO 50
             PWM GPIO.0,d,1
             PAUSEUS 500
             NEXT D
            
           GOTO START 
            end
    Can anyone explain why this does not run (produces no pulses).
    Last edited by ScaleRobotics; - 25th October 2010 at 16:21. Reason: added code tags

  2. #2
    Join Date
    Nov 2007
    Location
    West Covina, CA
    Posts
    219


    Did you find this post helpful? Yes | No

    Default

    Hi Russ,
    Try this:
    Code:
    FOR d = 250 TO 50 STEP -1
    Louie

  3. #3
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,615


    Did you find this post helpful? Yes | No

    Default

    Hi, Russ

    One thing hurts me in your program ...

    you write :
    produces pulses of varying width
    in fact the PWM command produces pulses BURSTS whose total duration match the requested "duty" ratio ...

    understand signal is not a nice pulse with one High level and one low level, but some kind of garbage.

    No problem, if you drive a lamp or generate a voltage through a Low Pass filter ...
    but not so good if driving some kind of inductive load ( motor i.e. )

    in this last case ... you should create some Software PWM by regularly toggling a pin ... or use a 12F683 that has a HPWM module.

    Alain
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  4. #4
    Join Date
    Jan 2006
    Location
    New Hampshire, USA
    Posts
    107


    Did you find this post helpful? Yes | No

    Default Oh duh! Is my face red.

    Quote Originally Posted by LinkMTech View Post
    Hi Russ,
    Try this:
    Code:
    FOR d = 250 TO 50 STEP -1
    I knew that! Bonk! Bonk! Bonk!

Members who have read this thread : 2

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts