News:

PROTON pic BASIC Compilers for PIC, PIC24, dsPIC33

Main Menu

Can not get a 18F2550 to Flash Test Leds

Started by RossMcLennan, Aug 21, 2024, 07:01 PM

Previous topic - Next topic

RossMcLennan

Hope you can give me some guidance. This is the first time to use a  18F2550. When using a new model PIC I usually just start by getting it to flash a led on and off. I am a relative novice and have not done this for a while. For some reason I can not even get to this basic step of getting the leds to flash. I would really appreciate any suggestion on what I have done wrong. Attahed is a circuit diagram and below is the code.
Thanks for your guidance.
Ross


;-------------------------------------------------------------------------------
;**** Added by Fuse Configurator ****
; Use the Fuse Configurator plug-in to change these settings

Device = 18F2550
Declare Xtal = 7

Config_Start
  PLLDIV = 1    ;No prescale (4 MHz oscillator input drives PLL directly)
  CPUDIV = OSC1_PLL2    ;[Primary Oscillator Src: /1][96 MHz PLL Src: /2]
  USBDIV = 1    ;USB clock source comes directly from the primary oscillator block with no postscale
  FOSC = HS    ;HS oscillator (HS)
  FCMEN = OFF    ;Fail-Safe Clock Monitor disabled
  IESO = OFF    ;Oscillator Switchover mode disabled
  PWRT = OFF    ;PWRT disabled
  BOR = On    ;Brown-out Reset enabled in hardware only (SBOREN is disabled)
  BORV = 3    ;Minimum setting 2.05V
  VREGEN = OFF    ;USB voltage regulator disabled
  WDT = On    ;WDT enabled
  WDTPS = 32768    ;1:32768
  CCP2MX = On    ;CCP2 input/output is multiplexed with RC1
  PBADEN = On    ;PORTB<4:0> pins are configured as analog input channels on Reset
  LPT1OSC = OFF    ;Timer1 configured for higher power operation
  MCLRE = On    ;MCLR pin enabled; RE3 input pin disabled
  STVREN = On    ;Stack full/underflow will cause Reset
  LVP = On    ;Single-Supply ICSP enabled
  XINST = OFF    ;Instruction set extension and Indexed Addressing mode disabled (Legacy mode)
  Debug = OFF    ;Background debugger disabled, RB6 and RB7 configured as general purpose I/O pins
  Cp0 = OFF    ;Block 0 (000800-001FFFh) is not code-protected
  CP1 = OFF    ;Block 1 (002000-003FFFh) is not code-protected
  CP2 = OFF    ;Block 2 (004000-005FFFh) is not code-protected
  CP3 = OFF    ;Block 3 (006000-007FFFh) is not code-protected
  CPB = OFF    ;Boot block (000000-0007FFh) is not code-protected
  CPD = OFF    ;Data EEPROM is not code-protected
  WRT0 = OFF    ;Block 0 (000800-001FFFh) is not write-protected
  WRT1 = OFF    ;Block 1 (002000-003FFFh) is not write-protected
  WRT2 = OFF    ;Block 2 (004000-005FFFh) is not write-protected
  WRT3 = OFF    ;Block 3 (006000-007FFFh) is not write-protected
  WRTC = OFF    ;Configuration registers (300000-3000FFh) are not write-protected
  WRTB = OFF    ;Boot block (000000-0007FFh) is not write-protected
  WRTD = OFF    ;Data EEPROM is not write-protected
  EBTR0 = OFF    ;Block 0 (000800-001FFFh) is not protected from table reads executed in other blocks
  EBTR1 = OFF    ;Block 1 (002000-003FFFh) is not protected from table reads executed in other blocks
  EBTR2 = OFF    ;Block 2 (004000-005FFFh) is not protected from table reads executed in other blocks
  EBTR3 = OFF    ;Block 3 (006000-007FFFh) is not protected from table reads executed in other blocks
  EBTRB = OFF    ;Boot block (000000-0007FFh) is not protected from table reads executed in other blocks
Config_End

;**** End of Fuse Configurator Settings ****
;-------------------------------------------------------------------------------



FlashLed:
Low PORTC.4
Low PORTC.5
DelayMS 500
High PORTC.4
High PORTC.5
DelayMS 500
GoTo FlashLed

End

  18F2550 Circuit.jpg

RGV250

Hi,
First thought is you have got watchdog WDT enabled and no reset. I never use it so try turning it off.

Bob

Pepe

#2
In the simulation in Proteus it works but in the real hardware it doesn't, change to other pins because in the 18f2550 the USB port can only be used as input if it is disabled

RGV250

Hi,
2.2k is way too high for LED, try around 300.

Mapo

Hi Ross,
in your drawing you have the LED diodes placed backwards,
invert anode with cathode

Mapo

RossMcLennan

OOOps,sorry I drew the LEDs the wrong way around. They are correct in the actual circuit board.
Regards
Ross

RossMcLennan

Thanks for the info and suggestions.
1. I had tested the 2.2k resistors to see if they would light up the LEDs and they were suffecient but I changed them to 330ohms to be sure, but still no go.
2. Added PortA.0 to the code and added a led circuit to PORTA.0 but this  port also does not work.
3. I have turned OFF the WDT but still no go.
4. I also checked the XTAL OSC on the board with the oscilloscope and it is running fine at 7.2MHz.

normnet

Hope this helps:
   Device = 18F2550 

   Config_Start
     PLLDIV = 5 ; Divide by 5 (20 MHz oscillator input)
     CPUDIV = OSC1_PLL2 ; [OSC1/OSC2 Src: /1][96 MHz PLL Src: /2]
     USBDIV = 2 ; USB clock source comes from the 96 MHz PLL divided by 2
     FOSC = HSPLL_HS ; HS oscillator, PLL enabled, HS used by USB
     FCMEN = OFF ; Fail-Safe Clock Monitor disabled
     IESO = OFF ; Oscillator Switchover mode disabled
     PWRT = On ; PWRT enabled
     BOR = ON_ACTIVE ; Brown-out Reset enabled in hardware only and disabled in Sleep mode (SBOREN is disabled)
     BORV = 2 ;
     VREGEN = OFF ; USB voltage regulator disabled
     WDT = OFF ; HW Disabled - SW Controlled
     WDTPS = 1 ; 1:1
     MCLRE = On ; MCLR pin enabled; RE3 input pin disabled
     LPT1OSC = OFF ; Timer1 configured for higher power operation
     PBADEN = OFF ; PORTB<4:0> pins are configured as digital I/O on Reset
     CCP2MX = On ; CCP2 input/output is multiplexed with RC1
     STVREN = On ; Stack full/underflow will cause Reset
     LVP = OFF ; Single-Supply ICSP disabled
     XINST = OFF ; Instruction set extension and Indexed Addressing mode disabled (Legacy mode)
     Debug = OFF ; Background debugger disabled, RB6 and RB7 configured as general purpose I/O pins
     CP0 = OFF ; Block 0 (000800-001FFFh) not code-protected
     CP1 = OFF ; Block 1 (002000-003FFFh) not code-protected
     CP2 = OFF ; Block 2 (004000-005FFFh) not code-protected
     CP3 = OFF ; Block 3 (006000-007FFFh) not code-protected
     CPB = OFF ; Boot block (000000-0007FFh) not code-protected
     CPD = OFF ; Data EEPROM not code-protected
     WRT0 = OFF ; Block 0 (000800-001FFFh) not write-protected
     WRT1 = OFF ; Block 1 (002000-003FFFh) not write-protected
     WRT2 = OFF ; Block 2 (004000-005FFFh) not write-protected
     WRT3 = OFF ; Block 3 (006000-007FFFh) not write-protected
     WRTB = OFF ; Boot block (000000-0007FFh) not write-protected
     WRTC = OFF ; Configuration registers (300000-3000FFh) not write-protected
     WRTD = OFF ; Data EEPROM not write-protected
     EBTR0 = OFF ; Block 0 (000800-001FFFh) not protected from table reads executed in other blocks
     EBTR1 = OFF ; Block 1 (002000-003FFFh) not protected from table reads executed in other blocks
     EBTR2 = OFF ; Block 2 (004000-005FFFh) not protected from table reads executed in other blocks
     EBTR3 = OFF ; Block 3 (006000-007FFFh) not protected from table reads executed in other blocks
     EBTRB = OFF ; Boot block (000000-0007FFh) not protected from table reads executed in other blocks
   Config_End

  'XTAL = 40
  'XTAL = 4      ' DEFAULTS TO 4
   Xtal = 48      ' Set the oscillator speed to 48MHz (using a 20MHz crystal)
'   Optimiser_Level = 3

  ' OSCCON = %01100010   ' OK  P 32  %01100000=4 MHz  ' INTERNAL REQUIRED
  ' OSCCON = %01110010    ' OK  P 32  %01110000=8 MHz  ' INTERNAL REQUIRED
   OSCCON = %00000000    ' EXTERNAL REQUIRED 

   Symbol sSEROUT_PIN = PORTB.1
   Symbol sBAUD = 16416  ' 16416 = 19200 BAUD

   Clear
   
   Dim yLOOP As Byte

   TRISA=%11111111
   TRISB=%00000000
   TRISC=%00000000


  'Declare HSERIAL_BAUD 115200
   Declare Hserial_Baud 9600
  'Declare HSERIAL_RCSTA
  'Declare HSERIAL_TXSTA 00100100
                       ' SYNC IS BIT 4 OF TXSTA
   TXSTA.2 = 1  ' BRGH = BIT 2 OF TXSTA  1 = HIGH SPEED  %00100110
   TXSTA.4 = 0  ' SYNC = BIT 4 OF TXSTA  0 = ASYNCHRONOUS
   SPBRG = 25           ' 10 = 115200 AT 20 MHz AT HIGH SPEED (BRGH = 1)=(BIT2 OF TXSTA)
   BAUDCON.3 = 0  '%01000000   BRG16 = 8 BIT 3 OF BAUDCON   0 = 8 BIT      01000000 DEFAULT

   ADCON1 = %00001111  ' %00001111 ALL DIGITAL
       
   START:
   DelayMS 800

   SerOut sSEROUT_PIN,sBAUD,["START",13]
'  HSerOut["HSEROUT",13,10]

   MAIN:
   Toggle PORTB.0

   Inc yLOOP
   SerOut sSEROUT_PIN,sBAUD,["LOOP = ",Dec yLOOP,13]
   DelayMS 1000

   GoTo MAIN

   End

Wimax

#8
I have no experience with Pic18Fs, I do know for sure that using Pickit4 there should be no components on the clock and data line (pull-up/down resistors, capacitors etc.) other than the pull-up resistor on MCLR. If the programming is successful... the problems surely lie elsewhere.
Just for info: what do you use for programming? Using Mplab X IPE I sometimes forget to take out the micro from 'hold in reset' mode...

RGV250

#9
Hi,
Have you tried the code on another device just to discount the device?

Another thought, probably not needed but have you tried VSS to pin 8?

Bob

RossMcLennan

Normet. Thanks for the config setting. I now have a heart beat from the PIC. The LED on PORTA.0 is flashing much faster than expected but I guess that is something to do with the pre\postscaler setting. So I will look at that further but it is alive. Thank you.
Still nothing on PORTC.4 or PORTC.5. This may be what was advised by Pepe so I will look at that further.
Very Happy it is alive. Thanks so much.
FYI the project is for a geofence using GPS to relase a high altitude payload when it gets into near space at approx 34,000m (112,000ft). Previousy flight we have been using a 18F4525 with great success for transmitting its GPS coordinates and Altitude for the recover after landing.
Thanks
Ross

Stephen Moss

#11
Quote from: RossMcLennan on Aug 21, 2024, 10:30 PM4. I also checked the XTAL OSC on the board with the oscilloscope and it is running fine at 7.2MHz.
Using the PLL is not strait forward on some devices, the reason the setting in the post by normnet works is becasue...
  • For some devices if you want to use the PLL its is not just a question of turning it on in the config fuses you also have to manipulate setting in the OSCCON register, bacause you have to select whether the processor and peripherals are being clocked from the internal, external or PLL clock source. as I recall the 18F2550 is one such device.
  • The PLL requires a 4MHz clock input, there is no PLL prescaller divider to 7MHz down to 4 so using a 7MHz clock won't work very well with the PLL/for USB.
  • The frequency you state in your Xtal declare must be that the processor is being clock at which is not necessarily that of your xtal, for example if you are using the PLL/2 output to clock everything and the PLL input is from and 8MHz external Xtal/2 then your must specify the clock speed as Xtal = 48, not the 8MHz of the crystal.

I did write an article (PDF) on using PLL's in Positron that explains this and give examples of the different ways to do things but I cannot remember if I posted on this forum or just the old one.

Frizie


== Off topic ==

Quote from: RGV250 on Aug 21, 2024, 07:56 PMHi,
2.2k is way too high for LED, try around 300.
Depends on the LED type.
Old LEDs were indeed around 330 Ohm at 5V, later 1k was already needed.
I have LEDs in a circuit here that burn very brightly at 39k at 5V.

== On topic ==
Ohm sweet Ohm | www.picbasic.nl

top204

#13
You have chosen one of the devices with the most complex config fuse settings. They even confused me when I used to use them!

Using bits and pieces from this thread, try the code template below:

'
'   /\\\\\\\\\
'  /\\\///////\\\
'  \/\\\     \/\\\                                                 /\\\          /\\\
'   \/\\\\\\\\\\\/        /\\\\\     /\\\\\\\\\\     /\\\\\\\\   /\\\\\\\\\\\  /\\\\\\\\\\\  /\\\\\\\\\
'    \/\\\//////\\\      /\\\///\\\  \/\\\//////    /\\\/////\\\ \////\\\////  \////\\\////  \////////\\\
'     \/\\\    \//\\\    /\\\  \//\\\ \/\\\\\\\\\\  /\\\\\\\\\\\     \/\\\         \/\\\        /\\\\\\\\\\
'      \/\\\     \//\\\  \//\\\  /\\\  \////////\\\ \//\\///////      \/\\\ /\\     \/\\\ /\\   /\\\/////\\\
'       \/\\\      \//\\\  \///\\\\\/    /\\\\\\\\\\  \//\\\\\\\\\\    \//\\\\\      \//\\\\\   \//\\\\\\\\/\\
'        \///        \///     \/////     \//////////    \//////////      \/////        \/////     \////////\//
'                                  Let's find out together what makes a PIC Tick!
'
' A code template for a PIC18F2550 device operating as a standard device and not with USB (untested).
'
' Written for the Positron8 BASIC compiler by Les Johnson
'
    Device = 18F2550                        ' Tell the compiler what device to compile for
    Declare Xtal = 48                       ' Tell the compiler, the device will be operating at 48MHz (using a 20MHz crystal)
    Declare Onboard_USB = False             ' Free up the USB RAM for general use
'
' Setup USART1
'
    Declare Hserial_Baud = 9600
    Declare HRSOut_Pin   = PORTC.6
    Declare HRSIn_Pin    = PORTC.7

    Symbol LED_Pin = PORTB.0                ' The pin used for the LED
'
' Create any global variables here
'
    Dim wCounter As Word
  
'---------------------------------------------------------------------------------
' The main program starts here
'
Main:
    Setup()                                 ' Setup the program and any variables or peripherals

    HRSOutLn "Hello World"
    wCounter = 0
    Do
        HRSOutLn "wCounter = ", Dec wCounter
        Inc wCounter
        Toggle LED_Pin
        DelayMS 1000
    Loop

'---------------------------------------------------------------------------------
' Setup the program and any variables or peripherals
' Input     : None
' Output    : None
' Notes     : None
'
Proc Setup()
    OSCCON = %00000000                      ' Make sure the device knows it is using an external oscillator
    UCON   = %00000000                      ' \ Disable the USB tranceiver (just in case)
    UCFG   = %00000000                      ' /
    PinLow LED_Pin
EndProc

'---------------------------------------------------------------------------------
' Setup the config fuses for a PIC18F2550 device
'
Config_Start
    PLLDIV = 5                          ' Divide by 5 (20MHz oscillator input)
    CPUDIV = OSC1_PLL2                  ' [OSC1/OSC2 Src: /1][96 MHz PLL Src: /2]
    USBDIV = 2                          ' USB clock source comes from the 96 MHz PLL divided by 2
    FOSC = HSPLL_HS                     ' HS oscillator, PLL enabled, HS used by USB
    FCMEN = Off                         ' Fail-Safe Clock Monitor disabled
    IESO = Off                          ' Oscillator Switchover mode disabled
    PWRT = On                           ' PWRT enabled
    BOR = ON_ACTIVE                     ' Brown-out Reset enabled in hardware only and disabled in Sleep mode (SBOREN is disabled)
    BORV = 2
    VREGEN = Off                        ' USB voltage regulator disabled
    WDT = Off                           ' Watchdog Timer disabled
    WDTPS = 128                         ' 1:128
    MCLRE = On                          ' MCLR pin enabled
    LPT1OSC = Off                       ' Timer1 configured for higher power operation
    PBADEN = Off                        ' PORTB<4:0> pins are configured as digital I/O on Reset
    CCP2MX = On                         ' CCP2 input/output is multiplexed with RC1
    STVREN = On                         ' Stack full/underflow will cause Reset
    LVP = Off                           ' Single-Supply ICSP disabled
    XINST = Off                         ' Instruction set extension and Indexed Addressing mode disabled (Legacy mode)
    Debug = Off                         ' Background debugger disabled, RB6 and RB7 configured as general purpose I/O pins
    Cp0 = Off                           ' Block 0 (000800-001FFF) not code-protected
    CP1 = Off                           ' Block 1 (002000-003FFF) not code-protected
    CP2 = Off                           ' Block 2 (004000-005FFF) not code-protected
    CP3 = Off                           ' Block 3 (006000-007FFF) not code-protected
    CPB = Off                           ' Boot block (000000-0007FF) not code-protected
    CPD = Off                           ' Data EEPROM not code-protected
    WRT0 = Off                          ' Block 0 (000800-001FFF) not write-protected
    WRT1 = Off                          ' Block 1 (002000-003FFF) not write-protected
    WRT2 = Off                          ' Block 2 (004000-005FFF) not write-protected
    WRT3 = Off                          ' Block 3 (006000-007FFF) not write-protected
    WRTB = Off                          ' Boot block (000000-0007FF) not write-protected
    WRTC = Off                          ' Configuration registers (300000-3000FF) not write-protected
    WRTD = Off                          ' Data EEPROM not write-protected
    EBTR0 = Off                         ' Block 0 (000800-001FFF) not protected from table reads executed in other blocks
    EBTR1 = Off                         ' Block 1 (002000-003FFF) not protected from table reads executed in other blocks
    EBTR2 = Off                         ' Block 2 (004000-005FFF) not protected from table reads executed in other blocks
    EBTR3 = Off                         ' Block 3 (006000-007FFF) not protected from table reads executed in other blocks
    EBTRB = Off                         ' Boot block (000000-0007FF) not protected from table reads executed in other blocks
Config_End

Note that the USB RAM has been made into general purpose RAM by the Declare Onboard_USB. This tells the compiler that the device does not have USB capabilities, so the compiler does not format the RAM internally for USB, and the full 2K is available for general use.

When the program is running, if you do not see "Hello World" on a serial terminal set for 9600 Baud, then the continuous "wCounter = nnnn" text, it means the config fuses are incorrect for the crystal frequency used, but a bit of tweaking here and there and you will get it. The good thing about using the USART for speed checks is that if the device's speed is not what the compiler has been told to compile for, the text will not be displayed on a serial terminal correctly, and as soon as the frequency matches with fuse tweaks, you will see the texts correctly.

normnet

Another 18F4550 example: 

Device = 18F4550

   CONFIG_START
     PLLDIV = 5 ; Divide by 5 (20 MHz oscillator input)
     CPUDIV = OSC1_PLL2 ; [OSC1/OSC2 Src: /1][96 MHz PLL Src: /2]
     USBDIV = 1 ; USB clock source comes directly from the primary oscillator block with no postscale
     FOSC = HS ; HS oscillator, HS used by USB
     FCMEN = OFF ; Fail-Safe Clock Monitor disabled
     IESO = OFF ; Oscillator Switchover mode disabled
     PWRT = On ; PWRT enabled
     BOR = On ; Brown-out Reset enabled in hardware only (SBOREN is disabled)
     BORV = 3 ; Minimum setting
     VREGEN = OFF ; USB voltage regulator disabled
     WDT = OFF ; HW Disabled - SW Controlled
     WDTPS = 1 ; 1:1
     MCLRE = On ; MCLR pin enabled; RE3 input pin disabled
     LPT1OSC = OFF ; Timer1 configured for higher power operation
     PBADEN = OFF ; PORTB<4:0> pins are configured as digital I/O on Reset
     CCP2MX = On ; CCP2 input/output is multiplexed with RC1
     STVREN = On ; Stack full/underflow will cause Reset
     LVP = OFF ; Single-Supply ICSP disabled
     ICPRT = OFF ; ICPORT disabled
     XINST = OFF ; Instruction set extension and Indexed Addressing mode disabled (Legacy mode)
     Debug = OFF ; Background debugger disabled, RB6 and RB7 configured as general purpose I/O pins
     CP0 = OFF ; Block 0 (000800-001FFFh) not code-protected
     CP1 = OFF ; Block 1 (002000-003FFFh) not code-protected
     CP2 = OFF ; Block 2 (004000-005FFFh) not code-protected
     CP3 = OFF ; Block 3 (006000-007FFFh) not code-protected
     CPB = OFF ; Boot block (000000-0007FFh) not code-protected
     CPD = OFF ; Data EEPROM not code-protected
     WRT0 = OFF ; Block 0 (000800-001FFFh) not write-protected
     WRT1 = OFF ; Block 1 (002000-003FFFh) not write-protected
     WRT2 = OFF ; Block 2 (004000-005FFFh) not write-protected
     WRT3 = OFF ; Block 3 (006000-007FFFh) not write-protected
     WRTB = OFF ; Boot block (000000-0007FFh) not write-protected
     WRTC = OFF ; Configuration registers (300000-3000FFh) not write-protected
     WRTD = OFF ; Data EEPROM not write-protected
     EBTR0 = OFF ; Block 0 (000800-001FFFh) not protected from table reads executed in other blocks
     EBTR1 = OFF ; Block 1 (002000-003FFFh) not protected from table reads executed in other blocks
     EBTR2 = OFF ; Block 2 (004000-005FFFh) not protected from table reads executed in other blocks
     EBTR3 = OFF ; Block 3 (006000-007FFFh) not protected from table reads executed in other blocks
     EBTRB = OFF ; Boot block (000000-0007FFh) not protected from table reads executed in other blocks
   CONFIG_END
         
  'XTAL = 40      ; Do we require the PLL ? USE 10 MHz CRYSTAL & DECLARE: XTAL = 40
   XTAL = 20

  'PIC18F4550
'  Digital input  RC5 and RC4 are only available as port pins when the USB module is disabled (UCON<3> = 0)
'  Unlike other PORTC pins, RC4 And RC5 do Not have
'  TRISC bits associated with them. As digital ports, they
'  can only function As digital inputs.

   Clear

   Symbol sSEROUT_PIN = PORTD.2
   Symbol sBAUD = 16416  '16416 = 19200 BAUD
   Symbol sLED = PORTD.1
   Symbol TRUE = 1
   Symbol FALSE = 0
   Dim yLOOPCNT AS Byte

   MAIN:

   SerOut sSEROUT_PIN,sBAUD,["LOOP",Dec yLOOPCNT,13]
   Inc yLOOPCNT

   Toggle sLED

   DelayMS 1000

   GoTo MAIN

   End

joesaliba

Quote from: RossMcLennan on Aug 22, 2024, 07:57 AMFYI the project is for a geofence using GPS

Is it difficult to calculate and implement a geofence?

Regards

Joe