Newbie help. RGB Led on a PIC10F202


Closed Thread
Results 1 to 40 of 42

Hybrid View

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


    Did you find this post helpful? Yes | No

    Default Re: Newbie help. RGB Led on a PIC10F202

    Yup, or there's no pull-up/down resistor. whatever
    Code:
            '-------------------------------------------------------------------------------------------
            '
            '       The following have been tested, no problem at all
            '       
            '       Hardware description
            '           1) LEDs connected betwee PIC I/O and GND via resistor
            '           2) Push button between PIC and GND... nothing else.
            ' 
            '-------------------------------------------------------------------------------------------  
             
    @       __config _WDT_OFF & _MCLRE_OFF & _CP_OFF
                    ' Disable watch dog timer
                    ' Disable MLCR, GP3 as I/O
                    ' Disable Code Protection 
                                  
            Red         var GPIO.0
            Green       var GPIO.1
            Blue        var GPIO.2
            SwitchPin   var GPIO.3  ' Active low
           
            OPTION_REG = %00000000
                       ' -0-------- _GPWU -- Disable Wake-Up on pin change
                       ' --0------- _GFPPU - Enable Weak Pull-Ups 
                       ' ---0------ T0CS --- Timer0 Clock Source Internal (O T0CKI pin, 0 Internal)
                       ' ----xxxxx- Timer0 related stuff... don't care
            
            TRISIO = 0          ' Clear all I/Os
            GPIO = %00001000    ' GP3: Input, other pin: Output 
                   
            ButtonCount VAR BYTE
    
    MAIN:
            IF !SwitchPin THEN                              ' Switch down?
                                                            ' - YES
                    If ButtonCount = 3 THEN ButtonCount = 0 ' - Currently on GP3 (MCLR)?  If so, pass go, claim 200$ 
                    pwm ButtonCount,127,100                 ' - Light Show
                    WHILE !SwitchPin : wend                 ' - Spin 'till button is released
                    pAUSE 50                                ' - arbitrary debouince delay
                    ButtonCount = ButtonCount + 1           ' - Point to next LED
                    endif                                   ' 
            GOTO MAIN
    Steve

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

  2. #2
    Join Date
    Aug 2011
    Posts
    16


    Did you find this post helpful? Yes | No

    Default Re: Newbie help. RGB Led on a PIC10F202

    Simple circuit. VDD hooked up to 3.7v, GPIO.0 to Red Lead, GPIO.1 to Green Lead, GPIO.2 to Blue Lead, GPIO.3 to Switch and ground when pressed, Vss hooked to Ground. And of course resistors coming from each of the I/O pins to the LED cathodes while the anode goes to 3.7v.

    Steve, When i run your code i get all three leds on, making white, press button i get Bright Blue, press button again i get more of a regular blue, again i get a dim green with both green and red leds lit.

    But at least the switch is working.
    Last edited by brianmorris; - 14th August 2011 at 17:41.

  3. #3
    Join Date
    Aug 2010
    Location
    Maryland, USA
    Posts
    869


    Did you find this post helpful? Yes | No

    Default Re: Newbie help. RGB Led on a PIC10F202

    So If the switch is not pressed, the input pin is floating, unless there are weak pull-ups in play here. If not, try adding a pull-up to the input. This way the input is either high or low, but never allowed to float.
    -Bert

    The glass is not half full or half empty, Its twice as big as needed for the job!

    http://foamcasualty.com/ - Warbird R/C scratch building with foam!

  4. #4
    Join Date
    Aug 2011
    Posts
    16


    Did you find this post helpful? Yes | No

    Default Re: Newbie help. RGB Led on a PIC10F202

    I connected a 10k resistor from VCC to GPIO.3 and then the button is still connected to GPIO.3 and GND. Push the button, the color changes, but still the same as above.

  5. #5
    Join Date
    Jan 2006
    Location
    Istanbul
    Posts
    1,185


    Did you find this post helpful? Yes | No

    Default Re: Newbie help. RGB Led on a PIC10F202

    Your LEDs are conected to Vdd instead of GND.
    And GPIO is set to 0, so initially all pins are low at the beginning and thus LEDs are on.
    When a PWM cycle is done, the pin stays low again and the LED is still on.

    I am guessing Steve forgat to add these in his last posted code above.


    Before "pwm ButtonCount,127,100", insert these:
    Code:
    HIGH RED
    HIGH GREEN
    HIGH BLUE

    So the new code will be as below:
    Code:
    MAIN:
     
            IF !SwitchPin THEN                              ' Switch down?
     
                                                            ' - YES
     
                    If ButtonCount = 3 THEN ButtonCount = 0 ' - Currently on GP3 (MCLR)?  If so, pass go, claim 200$ 
     
                    HIGH RED
     
                    HIGH GREEN
     
                    HIGH BLUE       
                    pwm ButtonCount,127,100                 ' - Light Show
     
                    WHILE !SwitchPin : wend                 ' - Spin 'till button is released
     
                    pAUSE 50                                ' - arbitrary debouince delay
     
                    ButtonCount = ButtonCount + 1           ' - Point to next LED
     
                    endif                                   ' 
            GOTO MAIN
    Last edited by sayzer; - 14th August 2011 at 20:05. Reason: typo
    "If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte

  6. #6
    Join Date
    Aug 2011
    Posts
    16


    Did you find this post helpful? Yes | No

    Default Re: Newbie help. RGB Led on a PIC10F202

    I have one RGB LED with a common anode thats hooked up to VDD. The individual pins are connected to the I/O ports on the chip. I entered in the code above but all colors are still on. The even funnier part is i even commented out those lines including the PWM line and all three are still on. I commented out just the PWM line, same thing. I even erased the chip, verified erase and reprogrammed.

  7. #7
    Join Date
    Jan 2006
    Location
    Istanbul
    Posts
    1,185


    Did you find this post helpful? Yes | No

    Default Re: Newbie help. RGB Led on a PIC10F202

    cmcon0 = 0




    "If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte

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


    Did you find this post helpful? Yes | No

    Default Re: Newbie help. RGB Led on a PIC10F202

    Quote Originally Posted by brianmorris View Post
    Steve, When i run your code i get all three leds on, making white, press button i get Bright Blue, press button again i get more of a regular blue, again i get a dim green with both green and red leds lit.

    But at least the switch is working.
    I guess i've been lucky then, modifs in RED

    Code:
            TRISIO = 0          ' Clear all I/Os
            GPIO = %00001000    ' GP3: Input, other pin: Output 
                   
            ButtonCount VAR BYTE
            CLEAR
    MAIN:
            IF !SwitchPin THEN                              ' Switch down?
                                                            ' - YES
                    If ButtonCount = 3 THEN ButtonCount = 0 ' - Currently on GP3 (MCLR)?  If so, pass go, claim 200$ 
                    PWM ButtonCount,127,100                 ' - Light Show
                    LOW ButtonCount
                    WHILE !SwitchPin : WEND                 ' - Spin 'till button is released
                    PAUSE 50                                ' - arbitrary debouince delay
                    ButtonCount = ButtonCount + 1           ' - Point to next LED
                    endif                                   ' 
            GOTO MAIN
    Steve

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

  9. #9
    Join Date
    Aug 2011
    Posts
    16


    Did you find this post helpful? Yes | No

    Default Re: Newbie help. RGB Led on a PIC10F202

    Bruce, your code is working perfectly. I can cycle through every color, the only thing I am having trouble with is maybe the switch is a tad too sensitive. I am thinking maybe using TMR0 where if i hold down the switch for 1-2 seconds, it will then change colors.

  10. #10
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default Re: Newbie help. RGB Led on a PIC10F202

    Probably just a really bad case of switch bounce. Try adjusting the delay something like this;

    Code:
         WHILE !SwitchPin
            PAUSE 50  ' adjust this until it starts acting right. 
         WEND
    That might do it. If not place this same code at the bottom just before it returns to Main.

    You could also increment a variable in the WHILE loop. When it reaches a certain value it will indicate approx how long the switch was held down.
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  11. #11
    Join Date
    Jan 2006
    Location
    Istanbul
    Posts
    1,185


    Did you find this post helpful? Yes | No

    Default Re: Newbie help. RGB Led on a PIC10F202

    In Steve's code, PWM command should be in the main loop.
    "If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte

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


    Did you find this post helpful? Yes | No

    Default Re: Newbie help. RGB Led on a PIC10F202

    ..........huh?
    Steve

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

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