Strangw results when using PWM command


Closed Thread
Results 1 to 21 of 21

Hybrid View

  1. #1
    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 " !!!
    *****************************************

  2. #2
    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.

  3. #3
    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

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


    Did you find this post helpful? Yes | No

    Default

    Steve,

    I tried that and it still just ramps up and doesn't seem to want to jump to the down label

    Code:
    @ __CONFIG _INTRC_OSC_NOCLKOUT & _WDT_ON & _PWRTE_ON & _MCLRE_OFF & _BODEN_ON
    
    TRISIO.0 = 0   'Set GPIO.0 to output.
    ANSEL.0 = 0    'Set GPIO.0 to digital		
    GPIO.0 = 0
    CMCON = 7 ' PortA Digital inputs
    VRCON = 0        ' Voltage reference disabled
    OPTION_REG.7 =    0
    
    
    led var GPIO.0
    i var byte
    getout var bit
    
    main:
    for i = 1 to 254                                             
        Pwm GPIO.0,i,1
        if i=253 then 
            i=254
            GetOut=1
            endif
       next i
    
    if Getout=1 then goto down
    
    down:
    for i = 254 to 1 step -1                                            
        Pwm GPIO.0,i,1
        if i=2 then 
            i=1
            GetOut=0
            endif
       next i
    
    if Getout=0 then goto main

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


    Did you find this post helpful? Yes | No

    Default

    Steve,

    I've also tried the following, which seems to flash the LED rather than ramp down in brighness

    Code:
    for i = 254 to 1 step-1                                             
        Pwm GPIO.0,i,1
        if i=2 then 
            i=1
            GetOut=1
            endif
       next i
    
    if Getout=1 then goto down
    I can't for the life of me work out what's wrong...

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


    Did you find this post helpful? Yes | No

    Wink There's ONLY ONE Dr' No's lamp !!!

    Hi, Malc

    I had just forgotten it was for your famous Dr Who's light ...

    so, it could not work properly with such a soft ...

    There was a thread you've already started about that ... you didn't find anything usable in it ???

    http://www.picbasic.co.uk/forum/show...1754#post21754

    I'll try to make a search ...

    Alain

    Seems the HPWM module of the 16F628a you saw was doing the job ... but may be the "slow PWM" thread from Darrel could help here !!! or use a 12F683 ...
    Last edited by Acetronics2; - 9th July 2006 at 17:13.
    ************************************************** ***********************
    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 " !!!
    *****************************************

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


    Did you find this post helpful? Yes | No

    Default

    Alain,

    Yes this is to do with the "Dr Who" thread in a way. I started a new one as the matters raised in that thread (ie the fact you need to mod the inc files) resolved it.

    What I can't understand was that I had used a 12F675 and the for next loops with the pwm command to successfully produce a pulsating LED for my mates project. I sent this off to him but he found that he needed to drive a bulb as the LED didn't give him the brightness he needed. I informed him that he could just used a FET and how to use a zenenr diode etc to produce 5v from a 12v battery, however he has never done any electronics, and may of fried the PIC. I then loaded up the PBP program but for some reason it stops running the down loop of the code.. anyway.. I've sent off the PCB so hopefully he hasn't fried his original PIC and he can simply drop that in and get filming

    Thanks guys

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


    Did you find this post helpful? Yes | No

    Default

    with the existing stuff, try this one
    Code:
    @ __CONFIG _INTRC_OSC_NOCLKOUT & _WDT_ON & _PWRTE_ON & _MCLRE_OFF & _BODEN_ON
    
    ANSEL.0  = 0 ' Set GPIO.0 to digital		
    CMCON    = 7 ' PortA Digital inputs
    VRCON    = 0 ' Voltage reference disabled
    TRISIO.0 = 0 ' Set GPIO.0 to output.
    GPIO.0   = 0 ' 
    
    LED    var GPIO.0
    I      var byte
    GetOut var bit
    
    main:
        for i = 1 to 254                                             
            Pwm GPIO.0,i,1
            if i=253 then 
                i=254
                GetOut=1
                endif
           next i
    
        if Getout=1 then down
        goto main
    
    down:
        getout=0
        for i = 254 to 1 step -1                                            
            Pwm GPIO.0,i,1
            if i=2 then 
                i=1
                GetOut=1
                endif
           next i
        
        if Getout=1 then main
        goto down
    and to make something usefull with the GetOut flag, use the following. Tested and work at treat. OK i'd modified the hardware assignement to fit to one of my already build board here
    Code:
    @ __CONFIG _INTRC_OSC_NOCLKOUT & _WDT_ON & _PWRTE_ON & _MCLRE_OFF & _BODEN_ON
    
    ANSEL  = 0      ' Set GPIO.0 to digital		
    CMCON  = 7      ' PortA Digital inputs
    VRCON  = 0      ' Voltage reference disabled
    TRISIO = $0F    ' gpio<3:0> : Input
                    ' gpio<5:4> : Output
    
    GPIO   = 0      ' clear all outputs
    
    LED    var GPIO.5
    PB     var GPIO.0
    I      var byte
    GetOut var bit
    
    Pause 50        ' oscillator settle time...
    OPTION_REG.7 =0 ' enable internal pull-up
    WPU = 1         ' enable pull-up on GPIO.0 only
    
    main:
        for i = 1 to 254                                             
            Pwm led,i,1
            if pb=0 then 
                i=254
                GetOut=1
                endif
           next i
        
        if Getout=1 then 
           while pb=0 : wend 
           pause 50
           GETOUT=0
           goto down
           endif
        goto main
    
    down:
        for i = 254 to 1 step -1                                            
            Pwm led,i,1
            if pb=0 then 
                i=1
                GetOut=1
                endif
           next i
        
        if Getout=1 then 
           while pb=0 : wend 
           pause 50    
           GETOUT=0
           GOTO main
           ENDIF
        goto down
    HTH
    Steve

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

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