Slowing Down RGB PWM Routine


Closed Thread
Results 1 to 6 of 6
  1. #1
    Join Date
    Feb 2005
    Location
    Essex, UK
    Posts
    154

    Default Slowing Down RGB PWM Routine

    I have an RGB sequence which works fairly well, but very quickly. Is there a way of slowing down the routine. I have tried altering the PWM duty, but this just causes the LEDs to flicker. Also the Pause command produces the same flickering results.

    I would like the transition of clours to be a lot slower.

    This is part of a bigger routine, but i would like to get this part right.

    Any ideas from anyone?

    Many thanks,

    Steve

    TRISB = 0

    Red VAR PORTB.1 ' All LEDs
    Green VAR PORTB.2 ' Connected between
    Blue VAR PORTB.3 ' RC pins and ground

    rbgArray var byte[3] ' holds the rgb values in this case the led is rbg
    x var byte
    y var byte
    adcVar var byte
    rbg var byte ' which value we are changing in the rbg array
    rainbowVal var byte ' the current value to produce rainbow
    Delta var byte ' find the size of each section in the 6stage rainbow
    Section var byte ' which section it is in

    maxValue con 255 'the maximum input value for generating rainbow

    delta = maxValue/6

    y = 0

    main:
    for rainbowval = 0 to 255
    gosub rbgrainbow
    next
    for rainbowval= 255 to 0 step - 1
    gosub rbgrainbow
    next
    goto main


    rbgrainbow:
    for rbg = 0 to 2
    section = ((rainbowval + ((rbg * 2)*delta))/ delta) // 6 ' this gives what section it is in

    select case section
    case 0
    rbgarray[rbg] = (rainbowval // delta)*6 'this is how far it has gone in its section
    case 1
    rbgarray[rbg] = 255
    case 2
    rbgarray[rbg] = 255
    case 3
    rbgarray[rbg] = 255 - ((rainbowval //delta)*6)
    case 4
    rbgarray[rbg] = 0
    case 5
    rbgarray[rbg] = 0
    case 6 'this one is for pics bad math
    rbgarray[rbg] = 0
    end select
    next

    gosub ledpwm

    return

    ledPWM:
    For y = 0 to 2
    Select Case y
    Case 0
    pwm red, rbgarray[y], 1
    case 1
    pwm blue, rbgarray[y], 1
    case 2
    pwm green, rbgarray[y], 1
    end select
    next
    return

  2. #2
    Join Date
    Jul 2003
    Location
    Sweden
    Posts
    237


    Did you find this post helpful? Yes | No

    Default

    Perhaps you could call your "ledPWM" routine more than once. That should keep the LEDs happy and take longer time.

  3. #3
    Join Date
    Feb 2005
    Location
    Essex, UK
    Posts
    154


    Did you find this post helpful? Yes | No

    Default

    OK, i think i know what you mean, but being new, how do i do that in the code i have. Would you mind giving me an example using my code?

    I'm guessing it will use a loop where i call that routine, say ten times and then jump to the next sequences etc.

    Many thanks.

    Steve

  4. #4
    egberttheone's Avatar
    egberttheone Guest


    Did you find this post helpful? Yes | No

    Default

    That is not so hard let me help ya;

    Code:
     
    
    main:
    
    for rainbowval = 0 to 255
    
    for a = 1 to 100
    gosub rbgrainbow 
    next a
    next rainbowval
    for rainbowval= 255 to 0 step - 1
    for a = 1 to 100
    gosub rbgrainbow 
    next a
    next rainbowval
    
    goto main
    of course you have to adjust the value's and you have to create the variable "A" (if your gone use high value's create a word size variable)

    Edit: you could also let a timer run in the background that keeps sending the pwm signals and change the value's in the mainloop
    Last edited by egberttheone; - 4th March 2005 at 21:35.

  5. #5
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default A different approach

    Hi Tissy,

    Since the software PWM command only works while that statement is active. It's going to be difficult to get the LED's to work the way you're wanting.

    Take a look at this link
    Multiple Slow speed Software PWM

    This will allow you to have all 3 PWM's running in the background at the same time. Then you can just cycle thru the PWM levels as needed without worrying about the timing.


    HTH,
       Darrel

  6. #6
    Join Date
    Jul 2003
    Location
    Sweden
    Posts
    237


    Did you find this post helpful? Yes | No

    Post

    Exactly what i meant ......

    FOR X = 1 to 10
    GOSUB ledpwm
    NEXT

Similar Threads

  1. Variable PWM PIC18F2431
    By trr1985 in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 12th June 2009, 06:03
  2. PWM setting PIC16F887
    By Gevo in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 12th June 2008, 07:24
  3. RGB Fading Using 3 LEDs and PWM
    By Tissy in forum mel PIC BASIC Pro
    Replies: 27
    Last Post: - 20th February 2007, 15:53
  4. RGB Fading Using 3 LEDs and PWM
    By _abello in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 19th April 2006, 15:50
  5. Tidying Up PWM Routine
    By Tissy in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 21st February 2005, 00:26

Members who have read this thread : 1

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