PDA

View Full Version : PIC programs, resonator resonates, but does not run code.



jmgelba
- 8th August 2012, 19:40
Baffling problem. The code was tested fine on an 18 pin 18F1320 on a breadboard, the pcb uses a 20 pin 18F1320. The 20mhz resonator runs perfectly. A test program using internal RC doesnt run either. I can program and read back the code and it verified ok. Also, this is 2 different PIC's in a row.

Any ideas what the heck the issue is? Anyone seen this before?

Here is a short test program to turn on and off a pin:



Define OSC 20

ADCON1 = %01111000
ADCON2 = %10000111

TRISA = %11100111
TRISB = %11000011

loop1:
portb.2 = 1
pause 100
portb.2 = 0
goto loop1


I'm programming using HS just as I did on the breadboard. MCLR is set as an input.

LinkMTech
- 8th August 2012, 19:54
Add another PAUSE 100 to your test loop so you can see it go low.


loop1:
portb.2 = 1
pause 100
portb.2 = 0
PAUSE 100
goto loop1

jmgelba
- 8th August 2012, 20:03
Thanks.

It never actually goes high though. :(

jmgelba
- 8th August 2012, 20:28
Well, a third PIC shows the exact same behavior. It will program and verify fine but will not execute code. I changed the resonator, same result. Will try a new pcb next.

jmgelba
- 8th August 2012, 21:37
New pcb, new PIC, same result. Only populated the board with a 5v regulator and caps, plus resonator and PIC. Layout is good. Can program, verify, read back, erase etc etc. Again, resonator is showing clean 20mhz waveform, it just will not execute the code.

gadelhas
- 8th August 2012, 22:17
Try this please;



loop1:
LATB.2 = 1
pause 100
LATB.2 = 0
PAUSE 100
goto loop1


Also check if MCLR is connected to VCC. I don't see the configuration bits of your code!

LinkMTech
- 8th August 2012, 22:45
Confusing since it worked on the 18 pin but I would also try configuring in the order shown in Example 10-2 of the data sheet:


PORTA = %00000000 ' Turn off all PORTA
PORTB = %00000000 ' Turn off all PORTB
ADCON1 = %01111000
ADCON2 = %10000111
TRISA = %11100111
TRISB = %11000011

Dave
- 8th August 2012, 22:55
Let's look at the code that works. Maybe theres something you left out...

Darrel Taylor
- 8th August 2012, 23:31
The 20-pin version has separate AVSS and AVDD pins.
Did you connect them to VSS and VDD?

jmgelba
- 9th August 2012, 01:47
Fixed!

So it would appear if you use the auto insert serial number feature it changes your config bits during programming. This applies to the U2 programmer software. Uncheck this feature, problem solved, and the design functions just fine.