Beginner problems
Moderators: David Barker, Jerry Messina
-
- Posts: 15
- Joined: Fri Apr 04, 2008 12:28 am
- Location: Plymouth, UK
Beginner problems
I wonder if anyone has any suggestions. I've plenty of experience with 16F PICs but I'm new to 18F and Swordfish. I simply can't get my 18F4520 to even flash an LED. My programme has no problems with flashing code and reading back. I'm sure it's recieving the correct voltage and wired up correctly. I've tried with internal and external OSC. The4 only other thing I can think of is that I'm not specifially setting up the TRISS registers. None of the sample code seems to do this either, unless it's hidden away in an "include". Can anyone help.
Chris
Chris
Hello and welcome to Swordfish
Can you try this code and let us know if it works ?
Try this ... try to test with Led connected on PortB.0 if possible. As for TRIS You have to set it ... with TRISB = $FF for example or TRISB = %11111111 if you want all port B as INPUT and TRISB = 0 if you want all pins as output.
Notice that the used instruction LOW(led) automatically set the TRIS of the pin to output, and sets the concerned Pin to low level.
Please, try it and let us know if it work.
Regards
octal
Can you try this code and let us know if it works ?
Code: Select all
device = 18F4520
clock = 20 '*********** do not forgot to change the crystal frequency, use clock=8 for 8MHz
// alias to port pin...
dim LED as PORTB.0 '*** Change this if your Led is on another port pin
// main program...
low(LED)
repeat
toggle (LED)
delayms (500)
until false
Try this ... try to test with Led connected on PortB.0 if possible. As for TRIS You have to set it ... with TRISB = $FF for example or TRISB = %11111111 if you want all port B as INPUT and TRISB = 0 if you want all pins as output.
Notice that the used instruction LOW(led) automatically set the TRIS of the pin to output, and sets the concerned Pin to low level.
Please, try it and let us know if it work.
Regards
octal
-
- Posts: 15
- Joined: Fri Apr 04, 2008 12:28 am
- Location: Plymouth, UK
Thanks for the advice. Tried the code you provided and still no joy although I'm now wondering if I have a faulty resonator circuit. My PORTB.0 LED occasionally flashes if I mess with the oscillator.
By "decoupling" the power supply pins do you mean connecting each pin to the power supply directly, rather than, for example, connecting both Vdd together and then from one pin to supply?
My plan is to get some new resonator components and give those a try. I'll also try switching off the peripherals as suggested.
I will post again with the results.
By "decoupling" the power supply pins do you mean connecting each pin to the power supply directly, rather than, for example, connecting both Vdd together and then from one pin to supply?
My plan is to get some new resonator components and give those a try. I'll also try switching off the peripherals as suggested.
I will post again with the results.
Hi,
as XOR suggested try by fully disabling the AN converters:
Try also to add crystal capacitors (22pf should be sufficient at 20Mhz)
Regards
octal
as XOR suggested try by fully disabling the AN converters:
Code: Select all
device = 18F4520
clock = 20 '*********** do not forgot to change the crystal frequency, use clock=8 for 8MHz
Include "utils.bas"
// alias to port pin...
dim LED as PORTB.0 '*** Change this if your Led is on another port pin
SetAllDigital()
// main program...
low(LED)
repeat
toggle (LED)
delayms (500)
until false
Regards
octal
Re: Beginner problems
The setup "punchlist" for your PIC18 is essentially the same as for any PIC16. You should know these things already based on your statement above.chrismills wrote:I've plenty of experience with 16F PICs but I'm new to 18F and Swordfish.
Your particular PIC18 has a bit more complex oscillator setup and I think Octal's example should get you started...
Decoupling is one of the most overlooked tools in a software engineers arsenal.
If the PIC is unable to operate correctly due to poor power supply no amount of code will ever cure it.
The simple way to guarantee good supply is to run power directly from the power source which should have a good sized capacitor(100uf or larger is my favourite) and a small 100nf to kill any noise produced by the regulator(even if its a cell).
Then the PIC power pins should have a minimum of a 100n capacitor(and a 1 to 10uf if the PIC is switching anything) AT THEIR ACTUAL PIN, not somewhere along the track.
Should the PIC have several supply pins these should all have a 100n capacitor as they will all be able to cause noise and be influenced by exteral noise.
The above will cure any standard supply bourne issues in 99% of cases(in my experience), I use these simple measures on all projects, especially experimental boards, and I do not remeber any power supply issues in years, nor any mysterious reset issues.
Sorry if I am teaching you how to suck eggs! but I have seen so many posts by people who just do not consider the power supply as important when it is in fact the most important part of the circuit.
If the PIC is unable to operate correctly due to poor power supply no amount of code will ever cure it.
The simple way to guarantee good supply is to run power directly from the power source which should have a good sized capacitor(100uf or larger is my favourite) and a small 100nf to kill any noise produced by the regulator(even if its a cell).
Then the PIC power pins should have a minimum of a 100n capacitor(and a 1 to 10uf if the PIC is switching anything) AT THEIR ACTUAL PIN, not somewhere along the track.
Should the PIC have several supply pins these should all have a 100n capacitor as they will all be able to cause noise and be influenced by exteral noise.
The above will cure any standard supply bourne issues in 99% of cases(in my experience), I use these simple measures on all projects, especially experimental boards, and I do not remeber any power supply issues in years, nor any mysterious reset issues.
Sorry if I am teaching you how to suck eggs! but I have seen so many posts by people who just do not consider the power supply as important when it is in fact the most important part of the circuit.
-
- Posts: 15
- Joined: Fri Apr 04, 2008 12:28 am
- Location: Plymouth, UK
OK. Again, thanks for all the advice and suggestions.
I now have a brand new 20MHz crystal and a pair 22pF caps. I've tried all the suggestions but still no luck from the flashing LED.
However, I have noticed that if I disconnect the oscillator circuit from grond then sometimes the output LED flashes a couple of times before switching on constantly.
Any more ideas any one. I'm feel like I'm missing fundamental.
I now have a brand new 20MHz crystal and a pair 22pF caps. I've tried all the suggestions but still no luck from the flashing LED.
However, I have noticed that if I disconnect the oscillator circuit from grond then sometimes the output LED flashes a couple of times before switching on constantly.
Any more ideas any one. I'm feel like I'm missing fundamental.
-
- Posts: 15
- Joined: Fri Apr 04, 2008 12:28 am
- Location: Plymouth, UK
Thanks for your help every one.
Finally I have a beautiful flashing LED.
It would seem that fuse settings are not being correctly passed by the HEX file to my programmer software, or the software is not interpreting them correctly. Each time I load the HEX, the OSC fuse is reset to LP, rather than HS. By manually setting the fuses in the programmer software I seem to have got things set up right and suddenly we are in business.
This is where the fun begins.
For the record I am using a K182 USB programmer with MicroBrn software and FixHex V2. If anyone can suggest a programmer which might work a bit more seamlessly with Swordfish, that would be great.
Thanks again every one that offered help
Chris
Finally I have a beautiful flashing LED.
It would seem that fuse settings are not being correctly passed by the HEX file to my programmer software, or the software is not interpreting them correctly. Each time I load the HEX, the OSC fuse is reset to LP, rather than HS. By manually setting the fuses in the programmer software I seem to have got things set up right and suddenly we are in business.
This is where the fun begins.
For the record I am using a K182 USB programmer with MicroBrn software and FixHex V2. If anyone can suggest a programmer which might work a bit more seamlessly with Swordfish, that would be great.
Thanks again every one that offered help
Chris
The Pickit2 (US$35) from Microchip is a great programmer:
http://www.microchip.com/stellent/idcpl ... e=en023805
http://www.microchip.com/stellent/idcpl ... e=en023805
-
- Posts: 15
- Joined: Fri Apr 04, 2008 12:28 am
- Location: Plymouth, UK