What is theabsolutely minimal hardware to run BLINK with a PIC18F4620?
I am trying to get a PIC18F4620 to blink a LED.
I think I have enough hardware bit I cannot get it to work.
Code:
'****************************************************************
' Name : BLINK.pbp Based on the MeLabs code examples for Lab-X1
' Compiler : PICBASIC PRO Compiler 3.0.7.4
' IDE : MCSP 5.0.0.5
' Assembler : MPASM
' Target PIC : 18F4620 in 40 pin PDIP.
' Oscillator : internal IntRC (Clkout) set in Config fuse at code burn time
' Programmer : MeLabs U2 USB
' Keywords : BLINK LED
' Description : Minimal hardware PIC18F4620 in 40 pin DIP
'****************************************************************
'
'The following program is a simple test to blink an LED on and off.
' Hardware : minimal breadboard 7805, input cap, output cap
'
'pin 1 = reset, tied to +5
'pin 11 +5V
'Pin 12 Gnd
'1 uF cap between pins 11 & 12
'Pin 31 Gnd
'Pin 32 +5V
'1 uF cap between pins 31 & 32
'Pin 33 Port B.0 has LED to Gnd via 1k resistor
'Program is compiled with PBP3.0.7.4 and MCSP 5.0.0.5
'At program time the IntRC (ClkOut) oscillator is selected.
LED1 VAR PORTB.0 ' Assign name "LED1" to PORTB.0 on pin 33
OSCCON = %11111111 '
' 0------- IDLEN 0 = enters SLEEP on Sleep command = 4 uA
' 1------- Enters IDLE and draws 550 uA
' -111---- IRCF <2:0> Int Osc freq select 111 = 8 MHz
' ----0--- OSTS Osc Startup Status - read only - ignore
' -----0-- IOFS IntOsc Freq Stable - read only - ignore
' ------00 System Clock Select 00 = Primary Osc
WDTCON = %00000001 ' enables SWDT - needs WDT OFF in config
' xxxxxxx1 SWDTEN software controlled WDT enabled
ADCON0 = %00000000 ' ADC OFF
' xx0000-- CH<3:0> select analog channels
' ------0- 1 = Go, 0 = Done
' -------0 1 = ADC ON, 0 = ADC OFF
ADCON1 = %00001111 'VRefs = Vdd & Vss, All ports digital
' 00------ unimplimented
' --00---- VCFG<1:0> Select Vcc & Gnd as ADC references
' ----0110 PCFG<3:0> A/D Port configuration see register 19-2
' ADCON2 = %00111111 'Left just (=8 bit), ADacq time = 20 Tad, ADClk = Frc
' 0------- ADFM 0 = Left Justified 8 bit mode
' -x111--- ACQ<2:0> A/D acquisition time = 20 Tad
' -----111 ADCS<2:0> A/D conversion clock select = Fr/c
CMCON = %00000111 ' Comparators OFF
' 00------ No comparator outputs
' --00---- No inversion on outputs
' ----0--- Vin to pins AN0 & AN1
' -----111 Comparators OFF
mainloop:
High LED1 ' Turn on LED connected to PORTB.0
Pause 500 ' Delay for .5 seconds
Low LED1 ' Turn off LED connected to PORTB.0
Pause 500 ' Delay for .5 seconds
Goto mainloop ' Go back to loop and blink LED forever
End
When I program the PIC I select INTRC(ClkOut) as the clock option
Any help gratefully received.
Thanks
BrianT
Re: What is theabsolutely minimal hardware to run BLINK with a PIC18F4620?
Don't want to be fatuous, but start by double checking that the LED is the right way around. A common fault.
Cheers Ron...
Re: What is theabsolutely minimal hardware to run BLINK with a PIC18F4620?
I would also try changing LED1 variable assignment to:
Code:
LED1 VAR LATB.0 ' Assign name "LED1" to LATB.0 on pin 33
Re: What is theabsolutely minimal hardware to run BLINK with a PIC18F4620?
Isn't 1K on the LED a bit high?
I usually have 330R.
Robert
Re: What is theabsolutely minimal hardware to run BLINK with a PIC18F4620?
The LED polarity is correct. With the MCU removed, the LED lights when 5V is applied to PortB.0
Re: What is theabsolutely minimal hardware to run BLINK with a PIC18F4620?
Thanks for the tip. I tried LATB.0 and it makes no difference.
Re: What is theabsolutely minimal hardware to run BLINK with a PIC18F4620?
1k with high brightness LEDs is plenty.
I think the problem is a missing register definition somewhere but I can't find it.
Cheers
BrianT
Re: What is theabsolutely minimal hardware to run BLINK with a PIC18F4620?
Hi Brian,
I would guess it's something in the default configs that is/are? at odds with your code, better to hand code the configs so you know what you have.
DEFINE OSC ??
Re: What is theabsolutely minimal hardware to run BLINK with a PIC18F4620?
Bit 7 of OSCCON, should not be a zero?
Ioannis
Re: What is theabsolutely minimal hardware to run BLINK with a PIC18F4620?
bit 7 only matters if using sleep
add led1=0 near the beginning of your code
You should also define the osc to 08
Re: What is theabsolutely minimal hardware to run BLINK with a PIC18F4620?
Try
OSCCON = %01111000
OSCTUNE = %01000000
DEFINE OSC 32
I use "INTIO2" but your setting should make no difference if you don't use osc pins as digital in/out.
Cheers
Al.
Re: What is theabsolutely minimal hardware to run BLINK with a PIC18F4620?
I'm not the best at reading the manual for this chip but from what I read on the data sheet OSCTUNE = %01000000 bit 6(PLLEN) can only be used with a 4 or 8 MHz oscillator.
OSCCON = %01111000 defines a 8 MHz internal oscillator. I think the first part should be of OSCCON should be OSCCON = %011111xx that defines an internal stable oscillator. I don't understand what the last two bits do so that would take some more exploration. It looks like you've got a plethora of options that depend on your specific situation.
In smaller chips the port usually needs to be set to digital for LEDs to light. I couldn't figure out how to do that for this chip.
Also, if the LED takes 2.2 volts of the 5 volts applied that leaves 2.8 volts for the 1k resistor. That's only 2.8 milliamps if the chip doesn't drop any voltage. I think that's low and am surprised it will light with 5 volts applied.
I hope it helps.
Re: What is theabsolutely minimal hardware to run BLINK with a PIC18F4620?
He is using high brightness LEDs. They might consume less than the average 20mA used by common LEDs (might be very high efficiency LEDs).
Robert