PICBasic newbie problem


Closed Thread
Results 1 to 33 of 33
  1. #1
    Join Date
    Feb 2008
    Posts
    8

    Question PICBasic newbie problem

    Dear members,

    FOA,I'm not new to the PIC World, I'm using CCS C compiler regularly

    Recently I started using PICBasic Pro because i knew basic is easy to use when it come create very simple project... you know leds stuff!

    However after reading that @ __config is depreciated for PIC18
    I'm trying to use CONFIG instead but how ?

    Code:
    CONFIG FOSC = HS,LVP = OFF,BOR = OFF,MCLRE = OFF
    
    led VAR PORTB.5
    steps VAR WORD
    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:
    
    up:
    For steps=0 TO 255
    PWM led,steps,cycles
    Next
    High led
    
    Pause 2500
    
    down:
    For steps=255 TO 1 STEP -1
    PWM led,steps,cycles
    Next
    Low led
    
    Pause 2500
    
    
    GoTo fade
    
    End
    Microcode studio says ERROR syntax at the first line! why ?

    Yes i did read the other post, including the faq about headers but like i said __CONFIG dont work anymore with MPASM

    Best Regards,

    Laurent

    EDIT: oh btw , pic18f4550 with 12mhz hs xtal
    Last edited by ELCouz; - 7th February 2008 at 23:09.

  2. #2
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default

    http://ww1.microchip.com/downloads/e...Doc/39632b.pdf
    check out OSCCON and OSCTUNE see section 2.2.2, 2.2.5.2, aw heck, read all of section 2.
    Last edited by Archangel; - 8th February 2008 at 02:42.
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

  3. #3
    Join Date
    Feb 2008
    Posts
    8


    Did you find this post helpful? Yes | No

    Default

    Yes, i have a printed pdf of this pic on my wall :P

    I did read them before , the problem is ... how to write (declare) them in PICBasic this is my first attempt at picbasic , so don't bash me :P ?

    IMPORTANT: For the PIC18 devices, the __CONFIG directive has been
    ; superseded by the CONFIG directive. The following settings
    ; are available for this device.
    ;
    ; PLL Prescaler Selection bits:
    ; PLLDIV = 1 No prescale (4 MHz oscillator input drives PLL directly)
    ; PLLDIV = 2 Divide by 2 (8 MHz oscillator input)
    ; PLLDIV = 3 Divide by 3 (12 MHz oscillator input)
    ; PLLDIV = 4 Divide by 4 (16 MHz oscillator input)
    ; PLLDIV = 5 Divide by 5 (20 MHz oscillator input)
    ; PLLDIV = 6 Divide by 6 (24 MHz oscillator input)
    ; PLLDIV = 10 Divide by 10 (40 MHz oscillator input)
    ; PLLDIV = 12 Divide by 12 (48 MHz oscillator input)
    ;
    ; CPU System Clock Postscaler:
    ; CPUDIV = OSC1_PLL2 [OSC1/OSC2 Src: /1][96 MHz PLL Src: /2]
    ; CPUDIV = OSC2_PLL3 [OSC1/OSC2 Src: /2][96 MHz PLL Src: /3]
    ; CPUDIV = OSC3_PLL4 [OSC1/OSC2 Src: /3][96 MHz PLL Src: /4]
    ; CPUDIV = OSC4_PLL6 [OSC1/OSC2 Src: /4][96 MHz PLL Src: /6]
    ;
    ; USB Clock Selection bit (used in Full Speed USB mode only; UCFG:FSEN = 1):
    ; USBDIV = 1 USB clock source comes directly from the primary oscillator block with no postscale
    ; USBDIV = 2 USB clock source comes from the 96 MHz PLL divided by 2
    ;
    ; Oscillator Selection bits:
    ; FOSC = XT_XT XT oscillator, XT used by USB
    ; FOSC = XTPLL_XT XT oscillator, PLL enabled, XT used by USB
    ; FOSC = ECIO_EC External clock, port function on RA6, EC used by USB
    ; FOSC = EC_EC External clock, CLKOUT on RA6, EC used by USB
    ; FOSC = ECPLLIO_EC External clock, PLL enabled, port function on RA6, EC used by USB
    ; FOSC = ECPLL_EC External clock, PLL enabled, CLKOUT on RA6, EC used by USB
    ; FOSC = INTOSCIO_EC Internal oscillator, port function on RA6, EC used by USB
    ; FOSC = INTOSC_EC Internal oscillator, CLKOUT on RA6, EC used by USB
    ; FOSC = INTOSC_XT Internal oscillator, XT used by USB
    ; FOSC = INTOSC_HS Internal oscillator, HS used by USB
    ; FOSC = HS HS oscillator, HS used by USB
    ; FOSC = HSPLL_HS HS oscillator, PLL enabled, HS used by USB
    ;
    ; Fail-Safe Clock Monitor Enable bit:
    ; FCMEN = OFF Fail-Safe Clock Monitor disabled
    ; FCMEN = ON Fail-Safe Clock Monitor enabled
    ;
    ; Internal/External Oscillator Switchover bit:
    ; IESO = OFF Oscillator Switchover mode disabled
    ; IESO = ON Oscillator Switchover mode enabled
    ;
    ; Power-up Timer Enable bit:
    ; PWRT = ON PWRT enabled
    ; PWRT = OFF PWRT disabled
    ;
    ; Brown-out Reset Enable bits:
    ; BOR = OFF Brown-out Reset disabled in hardware and software
    ; BOR = SOFT Brown-out Reset enabled and controlled by software (SBOREN is enabled)
    ; BOR = ON_ACTIVE Brown-out Reset enabled in hardware only and disabled in Sleep mode (SBOREN is disabled)
    ; BOR = ON Brown-out Reset enabled in hardware only (SBOREN is disabled)
    ;
    ; Brown-out Voltage bits:
    ; BORV = 0 Maximum setting
    ; BORV = 1
    ; BORV = 2
    ; BORV = 3 Minimum setting
    ;
    ; USB Voltage Regulator Enable bit:
    ; VREGEN = OFF USB voltage regulator disabled
    ; VREGEN = ON USB voltage regulator enabled
    ;
    ; Watchdog Timer Enable bit:
    ; WDT = OFF HW Disabled - SW Controlled
    ; WDT = ON HW Enabled - SW Disabled
    ;
    ; Watchdog Timer Postscale Select bits:
    ; WDTPS = 1 1:1
    ; WDTPS = 2 1:2
    ; WDTPS = 4 1:4
    ; WDTPS = 8 1:8
    ; WDTPS = 16 1:16
    ; WDTPS = 32 1:32
    ; WDTPS = 64 1:64
    ; WDTPS = 128 1:128
    ; WDTPS = 256 1:256
    ; WDTPS = 512 1:512
    ; WDTPS = 1024 1:1024
    ; WDTPS = 2048 1:2048
    ; WDTPS = 4096 1:4096
    ; WDTPS = 8192 1:8192
    ; WDTPS = 16384 1:16384
    ; WDTPS = 32768 1:32768
    ;
    ; MCLR Pin Enable bit:
    ; MCLRE = OFF RE3 input pin enabled; MCLR disabled
    ; MCLRE = ON MCLR pin enabled; RE3 input pin disabled
    ;
    ; Low-Power Timer 1 Oscillator Enable bit:
    ; LPT1OSC = OFF Timer1 configured for higher power operation
    ; LPT1OSC = ON Timer1 configured for low-power operation
    ;
    ; PORTB A/D Enable bit:
    ; PBADEN = OFF PORTB<4:0> pins are configured as digital I/O on Reset
    ; PBADEN = ON PORTB<4:0> pins are configured as analog input channels on Reset
    ;
    ; CCP2 MUX bit:
    ; CCP2MX = OFF CCP2 input/output is multiplexed with RB3
    ; CCP2MX = ON CCP2 input/output is multiplexed with RC1
    ;
    ; Stack Full/Underflow Reset Enable bit:
    ; STVREN = OFF Stack full/underflow will not cause Reset
    ; STVREN = ON Stack full/underflow will cause Reset
    ;
    ; Single-Supply ICSP Enable bit:
    ; LVP = OFF Single-Supply ICSP disabled
    ; LVP = ON Single-Supply ICSP enabled
    ;
    ; Dedicated In-Circuit Debug/Programming Port (ICPORT) Enable bit:
    ; ICPRT = OFF ICPORT disabled
    ; ICPRT = ON ICPORT enabled
    ;
    ; Extended Instruction Set Enable bit:
    ; XINST = OFF Instruction set extension and Indexed Addressing mode disabled (Legacy mode)
    ; XINST = ON Instruction set extension and Indexed Addressing mode enabled
    ;
    ; Background Debugger Enable bit:
    ; DEBUG = ON Background debugger enabled, RB6 and RB7 are dedicated to In-Circuit Debug
    ; DEBUG = OFF Background debugger disabled, RB6 and RB7 configured as general purpose I/O pins
    ;
    ; Code Protection bit Block 0:
    ; CP0 = ON Block 0 (000800-001FFFh) code-protected
    ; CP0 = OFF Block 0 (000800-001FFFh) not code-protected
    ;
    ; Code Protection bit Block 1:
    ; CP1 = ON Block 1 (002000-003FFFh) code-protected
    ; CP1 = OFF Block 1 (002000-003FFFh) not code-protected
    ;
    ; Code Protection bit Block 2:
    ; CP2 = ON Block 2 (004000-005FFFh) code-protected
    ; CP2 = OFF Block 2 (004000-005FFFh) not code-protected
    ;
    ; Code Protection bit Block 3:
    ; CP3 = ON Block 3 (006000-007FFFh) code-protected
    ; CP3 = OFF Block 3 (006000-007FFFh) not code-protected
    ;
    ; Boot Block Code Protection bit:
    ; CPB = ON Boot block (000000-0007FFh) code-protected
    ; CPB = OFF Boot block (000000-0007FFh) not code-protected
    ;
    ; Data EEPROM Code Protection bit:
    ; CPD = ON Data EEPROM code-protected
    ; CPD = OFF Data EEPROM not code-protected
    ;
    ; Write Protection bit Block 0:
    ; WRT0 = ON Block 0 (000800-001FFFh) write-protected
    ; WRT0 = OFF Block 0 (000800-001FFFh) not write-protected
    ;
    ; Write Protection bit Block 1:
    ; WRT1 = ON Block 1 (002000-003FFFh) write-protected
    ; WRT1 = OFF Block 1 (002000-003FFFh) not write-protected
    ;
    ; Write Protection bit Block 2:
    ; WRT2 = ON Block 2 (004000-005FFFh) write-protected
    ; WRT2 = OFF Block 2 (004000-005FFFh) not write-protected
    ;
    ; Write Protection bit Block 3:
    ; WRT3 = ON Block 3 (006000-007FFFh) write-protected
    ; WRT3 = OFF Block 3 (006000-007FFFh) not write-protected
    ;
    ; Boot Block Write Protection bit:
    ; WRTB = ON Boot block (000000-0007FFh) write-protected
    ; WRTB = OFF Boot block (000000-0007FFh) not write-protected
    ;
    ; Configuration Register Write Protection bit:
    ; WRTC = ON Configuration registers (300000-3000FFh) write-protected
    ; WRTC = OFF Configuration registers (300000-3000FFh) not write-protected
    ;
    ; Data EEPROM Write Protection bit:
    ; WRTD = ON Data EEPROM write-protected
    ; WRTD = OFF Data EEPROM not write-protected
    ;
    ; Table Read Protection bit Block 0:
    ; EBTR0 = ON Block 0 (000800-001FFFh) protected from table reads executed in other blocks
    ; EBTR0 = OFF Block 0 (000800-001FFFh) not protected from table reads executed in other blocks
    ;
    ; Table Read Protection bit Block 1:
    ; EBTR1 = ON Block 1 (002000-003FFFh) protected from table reads executed in other blocks
    ; EBTR1 = OFF Block 1 (002000-003FFFh) not protected from table reads executed in other blocks
    ;
    ; Table Read Protection bit Block 2:
    ; EBTR2 = ON Block 2 (004000-005FFFh) protected from table reads executed in other blocks
    ; EBTR2 = OFF Block 2 (004000-005FFFh) not protected from table reads executed in other blocks
    ;
    ; Table Read Protection bit Block 3:
    ; EBTR3 = ON Block 3 (006000-007FFFh) protected from table reads executed in other blocks
    ; EBTR3 = OFF Block 3 (006000-007FFFh) not protected from table reads executed in other blocks
    ;
    ; Boot Block Table Read Protection:
    ; EBTRB = ON Boot block (000000-0007FFh) protected from table reads executed in other blocks
    ; EBTRB = OFF Boot block (000000-0007FFh) not protected from table reads executed in other blocks
    ;
    It would be nice if i could write them (ex: FOSC = HS written in P18F4550.inc of MPASM ) instead of defining them with HEX stuff
    Have a nice day!

    Best Regards,
    Laurent

  4. #4
    Join Date
    Apr 2006
    Location
    New Hampshire USA
    Posts
    298


    Did you find this post helpful? Yes | No

    Smile

    Hi Laurent,

    Welcome to the forum.
    See if this previous series of posts from Melanie, mister_e and others, helps.
    http://www.picbasic.co.uk/forum/showthread.php?p=14264

    -Adam-
    Ohm it's not just a good idea... it's the LAW !

  5. #5
    Join Date
    Feb 2008
    Posts
    8


    Did you find this post helpful? Yes | No

    Default

    Thanks I've commented the Picbasic fuses in the include...

    Fuses is ok but on compiling this code:

    Code:
    ASM
        CONFIG FOSC=HS    ; Use HS oscillator (20MHZ here)
        CONFIG BOR=OFF    ; Brown out reset ON  
        CONFIG WDT=ON    ; Watch dog timer ON
        CONFIG LVP=OFF   ; Low Voltage programming OFF
        CONFIG DEBUG=OFF ; Background debugger OFF
        ENDASM
    led VAR PORTB.5
    steps VAR WORD
    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:
    
    up:
    For steps=0 TO 255
    PWM led,steps,cycles
    Next
    High led
    
    Pause 2500
    
    down:
    For steps=255 TO 1 STEP -1
    PWM led,steps,cycles
    Next
    Low led
    
    Pause 2500
    
    
    GoTo fade
    
    End
    i receive many errors :


    maybe it's the code that is faulty or it's something else ?

    Could you show me a code that will ABSOLUTELY compile (and tested to work), ex: blink a led so i can start to debug the previous code , to see if its my compile that freaks out or it just a simple issue....


    Many thanks!

    Have a nice week!

    Best Regards,

    Laurent

  6. #6
    Join Date
    Sep 2007
    Posts
    50


    Did you find this post helpful? Yes | No

    Default

    I just went through the same problems. See the thread below post#6 regarding editing the .inc file


    http://www.picbasic.co.uk/forum/show...ighlight=fuses
    Best Regards,

    Kurt A. Kroh
    KrohTech

    “Goodbye and thanks for all the fish”

  7. #7
    Join Date
    Sep 2007
    Posts
    50


    Did you find this post helpful? Yes | No

    Default

    Code:
    ASM
        CONFIG FOSC=HS    ; Use HS oscillator (20MHZ here)
        CONFIG BOR=OFF    ; Brown out reset ON  
        CONFIG WDT=ON    ; Watch dog timer ON
        CONFIG LVP=OFF   ; Low Voltage programming OFF
        CONFIG DEBUG=OFF ; Background debugger OFF
        ENDASM
    I never did get this method to work. I use this method of setting the fuses on my 18F2410:

    Code:
    @       __CONFIG    _CONFIG1H, _OSC_INTIO67_1H
    @       __CONFIG    _CONFIG2H, _WDT_ON_2H & _WDTPS_512_2H
    @       __CONFIG    _CONFIG3H, _MCLRE_OFF_3H & _PBADEN_OFF_3H 
    @       __CONFIG    _CONFIG4L, _LVP_OFF_4L & _XINST_OFF_4L
    Last edited by krohtech; - 8th February 2008 at 22:27.
    Best Regards,

    Kurt A. Kroh
    KrohTech

    “Goodbye and thanks for all the fish”

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


    Did you find this post helpful? Yes | No

    Default

    Refer to post #20 in the above thread link. PBP still does not support the new style config directive without the double underscore.

    You need to do it the old fashioned way as indicated in the above post by krohtech.
    Regards,

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

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

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

  11. #11
    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”

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

  13. #13
    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”

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

  15. #15
    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”

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

  17. #17
    Join Date
    Feb 2008
    Posts
    8


    Did you find this post helpful? Yes | No

    Default

    I need at least 16-24 channels, i will investigate more on the forum, if anyone have spotted something useful please be nice to post it here

    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.
    That's exactly what I've done in C but that wasn't refresh at the same speed at yours... i was running the outputs @ 220.4 hz but the effects that i need to do with the leds wasn't good , kinda jerky sometimes even with 48mhz (12mips) clock, I ran out off juice :S !

    Btw,skimask why not post it to the code examples or a little example here? I respect your work, if you don't want to share your code it's ok i understand that ...

    Have a nice day you guys!

    You really helped me

    I really love this forum, every time i come, i learn something :P

    Best Regards,
    Laurent
    Last edited by ELCouz; - 9th February 2008 at 11:27.

  18. #18
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by ELCouz View Post
    Btw,skimask why not post it to the code examples or a little example here? I respect your work, if you don't want to share your code it's ok i understand that ...
    Exactly which piece of work do you respect the most?
    Most people don't respect my work at all, if only because it's basically unreadable, as I'm sure it would be to you. The style of coding I've chosen and use is almost unreadable to the person that's not used to it. Ask anybody that's been around awhile, they'll tell you the same thing. The High Colonic Master...yep...that's me...

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


    Did you find this post helpful? Yes | No

    Default

    And: what : makes : your : coding : style : different : than : anyone : elses :....;o}
    Regards,

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

  20. #20
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Bruce View Post
    And: what : makes : your : coding : style : different : than : anyone : elses :....;o}
    I like to think of it in these terms:
    My code takes up less space on the screen...
    Most other's code takes up less space in the brain...
    :::::::::::::::::::::::::::::::::::::::::::::::::: :::::::::

  21. #21
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by skimask View Post
    I like to think of it in these terms:
    My code takes up less space on the screen...
    Most other's code takes up less space in the brain...
    :::::::::::::::::::::::::::::::::::::::::::::::::: :::::::::
    I'm : having : a : stack : overflow :
    Last edited by Archangel; - 9th February 2008 at 21:35.
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

  22. #22
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Joe S. View Post
    I'm : having : a : stack : overflow :
    Me too :::::::::::::::::::)))))))))))))))))))))

    At any rate, just to prove I'm not an _ _ _ (insert word here)...here's some cut down 3 channel code I use on a 16F628A running at 20Mhz.
    Interrupt driven 8 bit, 76Hz software PWM for RGB.
    You got a timer (Timer 0) running as fast as it can, interrupting at 19,531.25 Hz. That increments a byte counter, pwmcount.
    You got 3 duty cycle registers (reddcr, greendcr, bluedcr). If the individual duty cycle register is less than the pwmcounter, the LED stays on, if not the LED goes out.
    Change the DCRs in the mainloop and it should work.
    Like I said, this is cut down code. The full code works just fine for me, but I took out all of the serial interface code, the 5 button interface code and the serial LCD code. Might work, might not. Pay attention to how the hardware hooks up (3 LEDs on PortA, that's it).
    The code should fade the 3 LEDs each in turn in about one second from off to full brightness, over and over again, 3 seconds for all 3 LEDs, wash lather rinse repeat.

    But if you can't make an LED blink in the first place, DO THAT BEFORE YOU TRY THIS!

    Code:
    'PWM loop is @ 19,531.25 hz, w/ 256 cnt res, Freq of PWM is 76.2939hz
    @ DEVICE PIC16F628A , HS_OSC , WDT_OFF , PWRT_ON , MCLR_ON , BOD_ON , LVP_OFF , PROTECT_OFF	'HS 20mhz osc, watchdog off, powerup timer on, mclr external, brown out detect on, low volt program off , code protect off for now
    resetplaceholder:
    DEFINE		OSC		20	'20mhz
    DEFINE		NO_CLRWDT	1	'don't clear the watchdog timer, I'm not using it anyways
    DISABLE				'disable software interrupt checks
    CLEAR					'clear out the ram and do a software 'reset'
    redled var porta.0:greenled var porta.1:blueled var porta.2:chx var porta:reddcr var byte:greendcr var byte:bluedcr var byte:ledtemp var byte:pwmcount var byte
    temp var byte : temp2 var word
    startupholder:	goto skipsubs		'skip over all the commonly used subroutines
    ON INTERRUPT GOTO INTHANDLER
    DISABLE INTERRUPT
    INTHANDLER:	if intcon.2 = 1 then						'if tmr0 rolled over
    			intcon.2 = 0						'reset timer 0 overflow flag
    			if pwmcount = 0 then				'if pwmcounter has rolled over
    				if reddcr <> 0 then ledtemp.0 = 1	'turn off red leds if dcr is 0 (dcr = duty cycle register for LED), otherwise turn it on
    				if greendcr <> 0 then ledtemp.1 = 1	'turn off green leds if dcr is 0
    				if bluedcr <> 0 then ledtemp.2 = 1	'turn off blue leds if dcr is 0
    				chx = ledtemp		'update port pins of led status (on or off), can do this because all the LEDs are on the same port
    				endif
    			endif
    			if reddcr < pwmcount then ledtemp.0 = 0	'if the channel's dcr (duty cycle register) is less than the pwmcounter, turn that channel off, otherwise, leave it on ( < rather than <=, fixes problem with pulsing at high rates)
    			if greendcr < pwmcount then ledtemp.1 = 0
    			if bluedcr < pwmcount then ledtemp.2 = 0
    			chx = ledtemp : pwmcount = pwmcount + 1	'update the port pins and increment the pwmcount
    		endif
    intfinish:	RESUME
    'commonly used subroutines start here
    alloff:		reddcr = 0 : greendcr = 0 : bluedcr = 0 : return	'turn off all leds thru dcr's
    allon:		reddcr = 255 : greendcr = 255 : bluedcr = 255 : return     'turn on all leds
    skipsubs: option_reg=8:pie1=$20:trisa=0:porta=0:trisb=$ef:portb=$10:t1con=0:t2con=0:cmcon=7:ccp1con=0:vrcon=0:pir1.5=0:ledtemp=0:redled=0:blueled=0
                   greenled = 0 : intcon = $e0
    ENABLE INTERRUPT
    mainloop:
    for temp=0 to 255:reddcr=temp:for temp2=0 to 2603:pauseus 1:next temp2:next temp:for temp=0 to 255:greendcr=temp:for temp2=0 to 2603:pauseus 1:next temp2
    next temp:for temp=0 to 255:bluedcr=temp:for temp2=0 to 2603:pauseus 1:next temp2:next temp:goto mainloop	'do it over again
    END
    And for those that don't like colons...
    Code:
    'PWM loop is @ 19,531.25 hz, w/ 256 cnt res, Freq of PWM is 76.2939hz
    @ DEVICE PIC16F628A , HS_OSC , WDT_OFF , PWRT_ON , MCLR_ON , BOD_ON , LVP_OFF , PROTECT_OFF	'HS 20mhz osc, watchdog off, powerup timer on, mclr external, brown out detect on, low volt program off , code protect off for now
    resetplaceholder:
    DEFINE		OSC		20	'20mhz
    DEFINE		NO_CLRWDT	1	'don't clear the watchdog timer, I'm not using it anyways
    DISABLE				'disable software interrupt checks
    CLEAR					'clear out the ram and do a software 'reset'
    redled var porta.0
    greenled var porta.1
    blueled var porta.2
    chx var porta
    reddcr var byte
    greendcr var byte
    bluedcr var byte
    ledtemp var byte
    pwmcount var byte
    temp var byte
    temp2 var word
    startupholder:
    goto skipsubs		'skip over all the commonly used subroutines
    ON INTERRUPT GOTO INTHANDLER
    DISABLE INTERRUPT
    INTHANDLER:
    if intcon.2 = 1 then						'if tmr0 rolled over
    intcon.2 = 0						'reset timer 0 overflow flag
    if pwmcount = 0 then				'if pwmcounter has rolled over
    if reddcr <> 0 then
    ledtemp.0 = 1	'turn off red leds if dcr is 0 (dcr = duty cycle register for LED), otherwise turn it on
    endif
    if greendcr <> 0 then
    ledtemp.1 = 1	'turn off green leds if dcr is 0
    endif
    if bluedcr <> 0 then
    ledtemp.2 = 1	'turn off blue leds if dcr is 0
    endif
    chx = ledtemp		'update port pins of led status (on or off), can do this because all the LEDs are on the same port
    endif
    endif
    if reddcr < pwmcount then
    ledtemp.0 = 0
    endif
    'if the channel's dcr (duty cycle register) is less than the pwmcounter, turn that channel off, otherwise, leave it on ( < rather than <=, fixes problem with pulsing at high rates)
    if greendcr < pwmcount then
    ledtemp.1 = 0
    endif
    if bluedcr < pwmcount then
    ledtemp.2 = 0
    endif
    chx = ledtemp
    pwmcount = pwmcount + 1	'update the port pins and increment the pwmcount
    endif
    intfinish:
    RESUME
    'commonly used subroutines start here
    alloff:
    reddcr = 0
    greendcr = 0
    bluedcr = 0
    return	'turn off all leds thru dcr's
    allon:
    reddcr = 255
    greendcr = 255
    bluedcr = 255
    return     'turn on all leds
    skipsubs:
    option_reg = 8
    pie1 = $20
    trisa = 0
    porta = 0
    trisb = $ef
    portb = $10
    t1con = 0
    t2con = 0
    cmcon = 7
    ccp1con = 0
    vrcon = 0
    pir1.5 = 0
    ledtemp = 0
    redled = 0
    blueled = 0
    greenled = 0
    intcon = $e0
    ENABLE INTERRUPT
    mainloop:
    for temp = 0 to 255
    reddcr = temp
    for temp2 = 0 to 2603
    pauseus 1
    next temp2
    next temp
    for temp = 0 to 255
    greendcr = temp
    for temp2 = 0 to 2603
    pauseus 1
    next temp2
    next temp
    for temp = 0 to 255
    bluedcr = temp
    for temp2 = 0 to 2603
    pauseus 1
    next temp2
    next temp
    goto mainloop	'do it all over again
    END
    Last edited by skimask; - 10th February 2008 at 01:17.

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


    Did you find this post helpful? Yes | No

    Default

    3 channels ...

    No, No, No!

    You said you could do 48 channels.
    That's what they want.

    Frankly, I'd like to see 48 chanels of 8-bit software PWM too.
    <br>
    DT

  24. #24
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Darrel Taylor View Post
    3 channels ...
    No, No, No!
    You said you could do 48 channels.
    That's what they want.
    Frankly, I like to see 48 chanels of 8-bit software PWM too.
    <br>
    Well, the basics are there (as you well know)...
    And the 48 channels...I'll post some differences:
    18F8722 vs. 16F628A
    40Mhz vs. 20Mhz
    Timer 0 prescale is 1:2 instead of 1:1, thereby keeping the same 76Hz Freq of PWM...
    ...got 512 cycles to work with instead of 256. 48 channels in 512 cycles = 10 cycles per channel with even some extra leftover.
    Code is practically the same, except:
    PWM 0-7 on PortB (along with PGC/PGD/PGM, LVP disabled)
    PWM 8-15 on PortD (serial comm's on PortC, along with a couple of buttons)
    PWM 16-23 on PortE
    PWM 24-31 on PortF
    PWM 32-39 on PortH
    PWM 40-47 on PortJ
    The rest of the pins are either used for buttons, indicators, or whatever, the usual crap.

    At first I had a heck of a time finding enough cycles to run everything thru the interrupt loop and not miss any interrupts, that's when I figured out to keep all of the PWM channels in blocks of 8, byte writes to each port instead of bit writes saved just enough time to make it work reliably and leave a bit of time leftover to actually have a MAINLOOP to do other things. There's a few other shortcuts in the interrupt loop, such as checking the high bit of each DCR instead of checking the whole thing when doing the comparisons. That's one of the places where the PWM jitters a bit (I never said it was a ROCK SOLID 48 channels!). If too many of the channels have to take the jump where it sets or resets the pin, the PWM for all of them hiccups a bit. Worst case scenario is when all DCRs for each channel are exactly the same, they all have to take the jump to reset the pins. But if they're spread out, it's not bad at all. I can even trace it on the 'scope and only get a couple of us of jitter.

    THERE! Now everybody knows all of my secrets!

    You know, come to think of it...this might be one of those things just would go good with that little 'code optimization' exercise that went on awhile back.
    Get an '8722 to use every available pin for software driven PWM'ing of LEDs, while using the serial port for control at high speed, and still have solid PWM.
    Last edited by skimask; - 10th February 2008 at 05:04.

  25. #25
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by skimask View Post
    Me too :::::::::::::::::::)))))))))))))))))))))

    At any rate, just to prove I'm not an _ _ _ (insert word here)...
    HMMMMMMMMM . . . . not an _ _ _ . . . what could that be . . ( Joe mutters to himself with a big grin on his ugly mug) E G G . . . no that's too obvious . . D O G . . . perhaps, no . . . HMMMMMM , what could it be? D O N K E Y? No too many letters . . . HMMMMMMM . . . What could it be . . . ? HE HE HE HE HE HE . . . .
    Last edited by Archangel; - 10th February 2008 at 06:40.
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

  26. #26
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Joe S. View Post
    HMMMMMMMMM . . . . not an _ _ _ . . .
    I'll even give you a hint there...
    Since I wrote 'not AN _ _ _' vs. 'not A _ _ _'
    then it can be assumed that the 3 letter word does in fact start with a vowel...

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


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by skimask View Post
    ...
    Since I wrote 'not AN _ _ _' vs. 'not A _ _ _'
    then it can be assumed that the 3 letter word does in fact start with a vowel...
    I had come up with so many possibilities
    Especially after reading this ...

    <a href="http://www.dailywritingtips.com/using-a-and-an-before-words/">http://www.dailywritingtips.com/using-a-and-an-before-words/</a>
    <br>
    DT

  28. #28
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by skimask View Post
    I'll even give you a hint there...
    Since I wrote 'not AN _ _ _' vs. 'not A _ _ _'
    then it can be assumed that the 3 letter word does in fact start with a vowel...
    hmmmmmmmm . . . not AN . . . EAR . . . OWL . . . OAR . . . ? Be very careful if you pick one because there's lots of 3 letter words you do not want to be Lucky for me you are <font color=red>not</font color> AN overly sensitive drama queen ! and allow me to pick on you a little . . . all in fun though!
    Last edited by Archangel; - 10th February 2008 at 09:02.
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

  29. #29
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Darrel Taylor View Post
    I had come up with so many possibilities
    Especially after reading this ...
    <a href="http://www.dailywritingtips.com/using-a-and-an-before-words/">http://www.dailywritingtips.com/using-a-and-an-before-words/</a>
    <br>
    Point taken.

    Quote Originally Posted by Joe S. View Post
    hmmmmmmmm . . . not AN . . . EAR . . . OWL . . . OAR . . . ? Be very careful if you pick one because there's lots of 3 letter words you do not want to be Lucky for me you are not AN overly sensitive drama queen ! ans allow me to pick on you a little . . . all in fun though!
    APE...AXE...EMU...UNK...AKA...
    Drama Queen!!! WTH?
    Talk about getting off track...

  30. #30
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by skimask View Post
    I'll even give you a hint there...
    Since I wrote 'not AN _ _ _' vs. 'not A _ _ _'
    then it can be assumed that the 3 letter word does in fact start with a vowel...
    I found another hint
    The High Colonic Master...yep...that's me...
    and another
    And for those that don't like colons...
    So I used Google and came up with this
    http://en.wikipedia.org/wiki/Colon_(anatomy)

    These puzzles are fun, when can we do another?

    Sorry skimask, I could not help myself
    Dave
    Always wear safety glasses while programming.

  31. #31
    Join Date
    Sep 2007
    Posts
    50


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by ELCouz View Post
    I need at least 16-24 channels, i will investigate more on the forum, if anyone have spotted something useful please be nice to post it here
    Hi Laurent

    I have had great sucess with Darrel's DT_INTS-18 and SPWM_INT . I am doing 16 ch of PWM on a pic 18F2410 32 MHz. The pwm is running at 100Hz 8 bit resolution.

    Thanks Darrel (I never tire of saying that)

    take a look at this thread:
    http://www.picbasic.co.uk/forum/showthread.php?t=8088
    Best Regards,

    Kurt A. Kroh
    KrohTech

    “Goodbye and thanks for all the fish”

  32. #32
    Join Date
    Feb 2008
    Posts
    8


    Did you find this post helpful? Yes | No

    Default

    Hi,

    Just a little update, sorry for being late to answer I've be on a road trip to Quebec all the weekend ... yeah rock - on :P

    Well I'm tired so i will investigate further your nice posts guys tomorrow.

    See ya kids :P hehe

    Best Regards,
    Laurent

  33. #33
    Join Date
    Feb 2008
    Posts
    8


    Did you find this post helpful? Yes | No

    Default

    It works !!!

    I'm using the Darrel Taylor's DT_INTS-18 & SPWM_INT code.

    Everything is running smooth!

    Thanks everyone for the help!

    Have a nice day,

    Best Regards,

    Laurent

Similar Threads

  1. Newbie? Problem with LCD
    By lew247 in forum mel PIC BASIC Pro
    Replies: 10
    Last Post: - 7th December 2009, 20:48
  2. Picbasic Newbie Problem
    By Stargazer3141 in forum mel PIC BASIC
    Replies: 4
    Last Post: - 21st August 2007, 18: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, 17:33
  4. PicBasic Pro Math Problem??
    By Glen65 in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 5th March 2006, 05:36
  5. DMX & PicBasic coding problem
    By magicmarty in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 20th September 2004, 16:35

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