Beginner problems

Discuss PIC and electronic related things

Moderators: David Barker, Jerry Messina

Post Reply
chrismills
Posts: 15
Joined: Fri Apr 04, 2008 12:28 am
Location: Plymouth, UK

Beginner problems

Post by chrismills » Thu Apr 10, 2008 8:36 am

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

User avatar
octal
Registered User
Registered User
Posts: 586
Joined: Thu Jan 11, 2007 12:49 pm
Location: Paris IDF
Contact:

Post by octal » Thu Apr 10, 2008 8:45 am

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

xor
Posts: 286
Joined: Sun Nov 05, 2006 1:15 pm
Location: NYC
Contact:

Post by xor » Thu Apr 10, 2008 10:59 pm

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.

chrismills
Posts: 15
Joined: Fri Apr 04, 2008 12:28 am
Location: Plymouth, UK

Post by chrismills » Fri Apr 11, 2008 11:33 pm

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.

dman776
Posts: 115
Joined: Mon May 28, 2007 3:59 pm
Location: Texas

Post by dman776 » Sat Apr 12, 2008 5:37 am

Also, make sure that you are setting the config fuses properly (for the OSC you are using.)

User avatar
octal
Registered User
Registered User
Posts: 586
Joined: Thu Jan 11, 2007 12:49 pm
Location: Paris IDF
Contact:

Post by octal » Sat Apr 12, 2008 7:57 am

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

richardb
Posts: 307
Joined: Tue Oct 03, 2006 8:54 pm

Post by richardb » Sat Apr 12, 2008 8:27 am

make sure the programmer is not enabeling Low Voltage Programming. or pull down port b.5
Hmmm..

xor
Posts: 286
Joined: Sun Nov 05, 2006 1:15 pm
Location: NYC
Contact:

Re: Beginner problems

Post by xor » Sat Apr 12, 2008 11:37 am

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

Doj
Posts: 362
Joined: Wed Apr 11, 2007 10:18 pm
Location: East Sussex

Post by Doj » Sat Apr 12, 2008 2:28 pm

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.

chrismills
Posts: 15
Joined: Fri Apr 04, 2008 12:28 am
Location: Plymouth, UK

Post by chrismills » Sun Apr 13, 2008 10:55 pm

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.

Raistlin
Registered User
Registered User
Posts: 69
Joined: Tue Apr 01, 2008 1:13 pm

Post by Raistlin » Mon Apr 14, 2008 12:04 am

Try lowering the caps to 15pf
And makesure the OSC is set to HS
If you can read this you are too close

Doj
Posts: 362
Joined: Wed Apr 11, 2007 10:18 pm
Location: East Sussex

Post by Doj » Mon Apr 14, 2008 11:43 am

Have you got MCLR tied to supply (via diode and resistor)?, it will never come out of reset if not.

chrismills
Posts: 15
Joined: Fri Apr 04, 2008 12:28 am
Location: Plymouth, UK

Post by chrismills » Wed Apr 16, 2008 10:56 pm

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

rmteo
Posts: 237
Joined: Fri Feb 29, 2008 7:02 pm
Location: Colorado, USA

Post by rmteo » Wed Apr 16, 2008 11:43 pm

The Pickit2 (US$35) from Microchip is a great programmer:
http://www.microchip.com/stellent/idcpl ... e=en023805

chrismills
Posts: 15
Joined: Fri Apr 04, 2008 12:28 am
Location: Plymouth, UK

Post by chrismills » Mon Jun 09, 2008 10:53 pm

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

Post Reply