Strangw results when using PWM command


Closed Thread
Results 1 to 21 of 21

Hybrid View

  1. #1
    malc-c's Avatar
    malc-c Guest

    Default Strangw results when using PWM command

    I've written a simple program to pulse a LED on GPIO.0 of a 12F675, which worked fine. However I didn't save the file, and so I started from scratch again this morning.. but I'm experiencing some strange behaviour.

    This is the main body of the code:

    Code:
    led var GPIO.0
    
    i var byte
    
    up:
    For i = 1 to 254                                                  
    Pwm GPIO.0,i,1
    if i = 254 then goto down
    next i
    
    down:
    for i = 254 to 1 step-1
    pwm GPIO.0,i,1
    if i = 1 then goto main
    next i
    As you can see its a simple FOR/NEXT loop, that, should i reach a set value, goto either up or down section.

    However when programmed, the LED ramps up in brightness but then fails to ramp down. I've tried remming out the up section and all that happens is that the LED flashes fast (as if i is not reducing by the step-1 command)

    Code:
    ;up:
    For i = 255 to 1 step-1                                                 
    Pwm GPIO.0,i,1
    ;if i = 254 then goto down
    next i
    
    ;down:
    ;for i = 254 to 1 step-1
    ;pwm GPIO.0,i,1
    ;if i = 1 then goto main
    ;next i
    Its as if the PWM command or the step-1 statement is not being observed. And what's bugging me is I know it can be done as it worked before (the chip is now in cornwall so I can't read back the HEX !)

    Comments anyone please !

  2. #2
    malc-c's Avatar
    malc-c Guest


    Did you find this post helpful? Yes | No

    Default

    This is really strange.. its as though the "IF" in the "IF i = 245" is being ignored.

    I've just tried the following and it simply ramps up the LED to full brightness, over and over again, with out any pause ! (ie its the same as not having the pause statement there)

    Code:
    Main:
    For i = 1 to 254                                                 
    Pwm GPIO.0,i,1
    if i = 254 then pause 500
    if i = 254 then down
    next i

  3. #3
    malc-c's Avatar
    malc-c Guest


    Did you find this post helpful? Yes | No

    Default

    Now this is getting silly !

    Code:
    Main:
    for i = 1 to 254                                             
    Pwm GPIO.0,i,1
    if i=253 then goto down
    next i
    
    down:
    high gpio.0 
    pause 1000
    low gpio.0
    goto main
    The above test even fails... it simple runs the main loop and doesn't branch off to the down routine !


    EDIT:

    As does the following
    Code:
    Main:
    for i = 1 to 254                                             
    Pwm GPIO.0,i,1
    if i=253 then t=1
    if t=1 then goto down
    next i
    This is doing my head in
    Last edited by malc-c; - 9th July 2006 at 14:08.

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


    Did you find this post helpful? Yes | No

    Wink just simplify ...

    Hi, Malc

    Try this ... and do not forget I/Os and clock defining ...

    DEFINE OSCCAL_1K 1

    ADCON0 = 0
    ANSEL = 0

    ' Define YOUR I/Os Here !!! TRISIO = % ?????1

    led var GPIO.0

    i var byte

    up:
    For i = 1 to 254
    Pwm GPIO.0,i,1
    next i

    for i = 254 to 1 step-1
    pwm GPIO.0,i,1
    next i

    GOTO up

    END

    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 " !!!
    *****************************************

  5. #5
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Acetronics
    DEFINE OSCCAL_1K 1

    ADCON0 = 0
    ANSEL = 0

    ' Define YOUR I/Os Here !!! TRISIO = % ?????1
    The define OSCCAL have nothing usefull to do there
    Same for ADCON0 as it's the POR default.. but i agree could be safer

    Add CMCON=7 as it's a 12F675 and it have internal comparator multiplexed with GP.0

    Quote Originally Posted by Malc-C
    Main:
    for i = 1 to 254
    Pwm GPIO.0,i,1
    if i=253 then goto down
    next i
    Bad programming method IMHO, i always prefer to validate the Loop condition before getout and if usefull, set a flag wich say i interrupt the loop... something like
    Code:
    Main:
    for i = 1 to 254                                             
        Pwm GPIO.0,i,1
        if i=253 then 
            i=254
            GetOut=1
            endif
       next i
    
    if Getout then DoSomething
    In your case, the main problem is most the analog stuff
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  6. #6
    malc-c's Avatar
    malc-c Guest


    Did you find this post helpful? Yes | No

    Default

    Alain, thank for the reply, but that still has the same effect, ie the LED ramps up in brightness, but doesn't ramp down.

    Steve,
    I never said my coding was tidy

    However isn't

    Code:
    Main:
    for i = 1 to 254                                             
        Pwm GPIO.0,i,1
        if i=253 then 
            i=254
            GetOut=1
            endif
       next i
    
    if Getout then DoSomething
    The same thing as

    Code:
    Main:
    for i = 1 to 254                                             
    Pwm GPIO.0,i,1
    if i=253 then t=1
    if t=1 then goto down
    next i
    in a round about way ? where the condition is replaced with t in my case ?

    The thing that is also bugging me if that whilst the loop to increase the brightness works, the one to decrease it doesn't ???

    Let me go away and try Steve's suggestion and see if I get any further.

    Thanks as always for your inputs

Similar Threads

  1. Active low input?
    By CosMecc in forum mel PIC BASIC Pro
    Replies: 14
    Last Post: - 8th August 2010, 20:31
  2. Variable PWM PIC18F2431
    By trr1985 in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 12th June 2009, 06:03
  3. turning gpio.0 high after pwm command
    By sirvo in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 21st February 2007, 18:22
  4. Can I do this???
    By noobie in forum mel PIC BASIC
    Replies: 2
    Last Post: - 10th June 2006, 18:57
  5. Searches
    By bearpawz in forum Forum Requests
    Replies: 11
    Last Post: - 7th November 2005, 18:47

Members who have read this thread : 0

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