PICBasic newbie problem


Closed Thread
Results 1 to 33 of 33

Hybrid View

  1. #1
    Join Date
    Feb 2008
    Posts
    8


    Did you find this post helpful? Yes | No

    Default

    Thanks ! You fix all my problems !

    However i have another question about this code and the function PWM...

    How to have multiple pwms output ?

    take a look to the following code

    Code:
    @       __CONFIG    _CONFIG1L, _PLLDIV_3_1L & _CPUDIV_OSC1_PLL2_1L
    @       __CONFIG    _CONFIG1H, _FOSC_HSPLL_HS_1H
    @       __CONFIG    _CONFIG2L, _VREGEN_OFF_2L
    @       __CONFIG    _CONFIG2H, _WDT_OFF_2H 
    @       __CONFIG    _CONFIG3H, _MCLRE_OFF_3H & _PBADEN_OFF_3H 
    @       __CONFIG    _CONFIG4L, _LVP_OFF_4L & _XINST_OFF_4L & _DEBUG_OFF_4L
    DEFINE OSC 48
    led VAR PORTD
    'changed WORD for BYTE ... using 32bit int for 8bit value is taking more cycle to do operation to it
    step0 VAR byte
    step1 VAR byte
    step2 VAR byte
    step3 VAR byte
    step4 VAR byte
    step5 VAR byte
    step6 VAR byte
    step7 VAR byte
    cycles CON 2
    
    ' Change limits for steps to play around 0 or 100% brightness
    ' Change steps for different duration of ramps
    ' Works good even with high brightness LEDs, harder to control linearly
    
    
    fade:
    
    
    For step0=0 TO 100
    PWM led.0,step0,cycles
    Next
    For step1=0 TO 100
    PWM led.1,step1,cycles
    Next
    For step2=0 TO 100
    PWM led.2,step2,cycles
    Next
    For step3=0 TO 100
    PWM led.3,step3,cycles
    Next
    For step4=0 TO 100
    PWM led.4,step4,cycles
    Next
    For step5=0 TO 100
    PWM led.5,step5,cycles
    Next
    For step6=0 TO 100
    PWM led.6,step6,cycles
    Next
    For step7=0 TO 100
    PWM led.7,step7,cycles
    Next
    
    For step0=100 TO 1 STEP -1
    PWM led.0,step0,cycles
    Next
    For step1=100 TO 1 STEP -1
    PWM led.1,step1,cycles
    Next
    For step2=100 TO 1 STEP -1
    PWM led.2,step2,cycles
    Next
    For step3=100 TO 1 STEP -1
    PWM led.3,step3,cycles
    Next
    For step4=100 TO 1 STEP -1
    PWM led.4,step4,cycles
    Next
    For step5=100 TO 1 STEP -1
    PWM led.5,step5,cycles
    Next
    For step6=100 TO 1 STEP -1
    PWM led.6,step6,cycles
    Next
    For step7=100 TO 1 STEP -1
    PWM led.7,step7,cycles
    Next
    
    GoTo fade
    
    End
    What i want is to fade ON all led each by each while keeping them ON
    then after Turn them OFF (while fading) one by one

    The code only do pwm on 1 led at time only :S

    Any clues ?

    oh btw, searching through the forum is PITA ... it doesn't take words like PWM , because it's too short ... hence rendering the search practically useless for "Multiple PWM"

    Cheers,


    Best Regards,

    Laurent

  2. #2
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by ELCouz View Post
    Thanks ! You fix all my problems !
    How to have multiple pwms output ?
    PWM is a blocking command. You can only do one PWM at any one time, PBP only has one 'hand' available to do PWM. You have to write good interrupt driven software to do multiple channels. Well, you don't HAVE to do anything. There are many ways to do multiple channel PWM, software based PWM...

    oh btw, searching through the forum is PITA ... it doesn't take words like PWM , because it's too short ... hence rendering the search practically useless for "Multiple PWM"
    Look in the FAQ's...

  3. #3
    Join Date
    Sep 2007
    Posts
    50


    Did you find this post helpful? Yes | No

    Default Multi SPWM

    I use Darrel’s Multi SPWM code to get 8 ch of PWM at 100 Hz. Works GREAT (((thanks Darrel)))

    See:
    http://www.pbpgroup.com/modules/wfse...p?articleid=12
    Best Regards,

    Kurt A. Kroh
    KrohTech

    “Goodbye and thanks for all the fish”

  4. #4
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by krohtech View Post
    I use Darrel’s Multi SPWM code to get 8 ch of PWM at 100 Hz. Works GREAT (((thanks Darrel)))
    See:
    http://www.pbpgroup.com/modules/wfse...p?articleid=12
    Forgot about that one.
    I've done it myself on an 18F8722 to the tune of 48 channels of LEDs at 40Mhz, refreshing at 7152.2Hz. Same principle, but relatively easily done. If you can do 2 channels, you can do 100.

  5. #5
    Join Date
    Sep 2007
    Posts
    50


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by skimask View Post
    Forgot about that one.
    I've done it myself on an 18F8722 to the tune of 48 channels of LEDs at 40Mhz, refreshing at 7152.2Hz. Same principle, but relatively easily done. If you can do 2 channels, you can do 100.
    Hey skimask,

    How did you do 48 CHannels. Did you have to modify Darrel's asm code?
    Best Regards,

    Kurt A. Kroh
    KrohTech

    “Goodbye and thanks for all the fish”

  6. #6
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by krohtech View Post
    Hey skimask,

    How did you do 48 CHannels. Did you have to modify Darrel's asm code?
    Didn't use DT's code for that one.
    Just a simple Tmr0 overflow running as fast as it can... When the interrupt hits, I update the channels/pins according to their duty cycle 'register' variable. Outside the interrupt sub, in the main loop, I update the duty cycle 'register' itself depending on whatever I'm doing. Theoretically, assuming there's enough clock cycles in the day, you can run as many channels as you want.
    On the '8722, you could have up to 70 channels of halfway decent PWM (well, 69, one of those pins is input only if I remember right). I only stopped at 48 'cause that's all the red LEDs I had on hand at the time.

  7. #7
    Join Date
    Sep 2007
    Posts
    50


    Did you find this post helpful? Yes | No

    Default

    Can each channel have different duty cycles?

    This is quite a bit over my head, could you post a code example?
    Best Regards,

    Kurt A. Kroh
    KrohTech

    “Goodbye and thanks for all the fish”

  8. #8
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by krohtech View Post
    Can each channel have different duty cycles?
    As many as can be had. Only limitation is processor cycles. Depending on what freq the PWM gets run at, you end up running out of enough cycles to adjust all of the channel's PWM's in the main loop and might run out of cycles in the interrupt loop to update all of the channels before the next interrupt hits.

Similar Threads

  1. Newbie? Problem with LCD
    By lew247 in forum mel PIC BASIC Pro
    Replies: 10
    Last Post: - 7th December 2009, 19:48
  2. Picbasic Newbie Problem
    By Stargazer3141 in forum mel PIC BASIC
    Replies: 4
    Last Post: - 21st August 2007, 17:40
  3. Problem on writing EEPROM in Winpic800 with picbasic pro
    By selimkara in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 4th May 2007, 16:33
  4. PicBasic Pro Math Problem??
    By Glen65 in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 5th March 2006, 04:36
  5. DMX & PicBasic coding problem
    By magicmarty in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 20th September 2004, 15:35

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