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


    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

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

  3. #3
    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 18: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 " !!!
    *****************************************

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

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

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


    Did you find this post helpful? Yes | No

    Default

    Steve,

    Thanks once again for all you help. I had given up and wrapped up the board to post it to my mate, however I took it out of the jiffy bag and gave it one last try...

    I copied and pasted the code in your last post (the first program) and tried that. It compiled fine and loaded into the PIC, however the code does exactly the same as all other attempts. ie it ramps (for want of a better word) up the brightness to full, and then goes off, then repeats the same. It still doesn't ramp down from full brightness to low like it should - I've tried different PICs so it rules out that as being the cause.

    I think I'll call it a day on this.. thanks again for your help

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


    Did you find this post helpful? Yes | No

    Default

    That's really strange... it's working here using the first code of my previous message.

    Ramp-up, ramp-down in an endless loop... mmm.

    I suspect a hardware problem but damn it's not a really complicated hardware, i removed all the usual capacitor around, nothing on all other i/o, simple LED+300 ohm resistor... work fine. if i raise down the psu voltage... it's working from 2.5V. so uneless your Vdd rail is below or really noisy causing a RESET... i don't see why it shouldn't work.
    Last edited by mister_e; - 9th July 2006 at 19:47.
    Steve

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

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


    Did you find this post helpful? Yes | No

    Default

    Steve,

    Rest assured your code works fine.. I've just breadboarded the PIC and it works, yet in the PCB ot only wants to ramp up ????? - strange !!

    I would of thought that if there was something wrong with the PCB I made (like a short) then the thing would not work full stop ! The board uses a 5.1 zenner to provide the supply to the PIC, and the output simply from GPIO 0 drives the gate of the FET and the LED - why it ramps up and not down I don't know ?

    Thanks mate.. don't waste any more of your time... I've attached the schematic just in case someone might see whats the issue ?
    Attached Images Attached Images  

Similar Threads

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