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

    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

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

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

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

  5. #5
    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 21:27.
    Best Regards,

    Kurt A. Kroh
    KrohTech

    “Goodbye and thanks for all the fish”

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

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

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

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

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

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