Page 1 of 1

Beginner problems

Posted: Thu Apr 10, 2008 8:36 am
by chrismills
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

Posted: Thu Apr 10, 2008 8:45 am
by octal
Hello and welcome to Swordfish :o

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

Posted: Thu Apr 10, 2008 10:59 pm
by xor
2 "other" things not mentioned:

Decouple the Power Supply pins of the PIC at the PIC.

Disable the ADC's and Comparators. In the datasheet under IO PORTS is a small example box for each port.... usually PORTA is enough.... and you can see the values for disabling these features.

Posted: Fri Apr 11, 2008 11:33 pm
by chrismills
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.

Posted: Sat Apr 12, 2008 5:37 am
by dman776
Also, make sure that you are setting the config fuses properly (for the OSC you are using.)

Posted: Sat Apr 12, 2008 7:57 am
by octal
Hi,
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 
Try also to add crystal capacitors (22pf should be sufficient at 20Mhz)
Regards
octal

Posted: Sat Apr 12, 2008 8:27 am
by richardb
make sure the programmer is not enabeling Low Voltage Programming. or pull down port b.5

Re: Beginner problems

Posted: Sat Apr 12, 2008 11:37 am
by xor
chrismills wrote:I've plenty of experience with 16F PICs but I'm new to 18F and Swordfish.
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.

Your particular PIC18 has a bit more complex oscillator setup and I think Octal's example should get you started...

Posted: Sat Apr 12, 2008 2:28 pm
by Doj
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.

Posted: Sun Apr 13, 2008 10:55 pm
by chrismills
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.

Posted: Mon Apr 14, 2008 12:04 am
by Raistlin
Try lowering the caps to 15pf
And makesure the OSC is set to HS

Posted: Mon Apr 14, 2008 11:43 am
by Doj
Have you got MCLR tied to supply (via diode and resistor)?, it will never come out of reset if not.

Posted: Wed Apr 16, 2008 10:56 pm
by chrismills
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

Posted: Wed Apr 16, 2008 11:43 pm
by rmteo
The Pickit2 (US$35) from Microchip is a great programmer:
http://www.microchip.com/stellent/idcpl ... e=en023805

Posted: Mon Jun 09, 2008 10:53 pm
by chrismills
Late follow up

Got the PicKit2 programmer and it works miles better than the one I was using before.

No problems with programming now and I would thoroughly recommend this programmer to anyone starting out messing with PICs.

Thanks for all the help

Chris