| Author |
Message |
Joel

Joined: Sep 12, 2006 Posts: 97 Location: London, UK
|
Posted: Sun Jun 22, 2008 8:09 am Post subject:
PIC help |
 |
|
Hi all,
firstly I realise this isn't a microcontroller programming forum so sorry if anyone doesn't feel this is an appropriate place to ask this stuff. There may be others who want to start programming for themselves however, so this could be useful(?!)...
I've written a short "LED blinker" program to try and start programming PICs myself. I'm currently using an 18F2455 on a solderless breadboard. Code is listed below (CCS C). Problems include :
- flashes a few times (~10 - 30), then stops
- stops if I touch the body of the 7805 regulator
- when it stops, simply disconnecting then reconnecting the power does not reset it. Have to pull the PIC from the board then put back in
Bizarrely, this is not my first attempt at writing code and on the same breadboard, using the same power rails, there is a 16F684 happily runnning a more complex code (PWM, interrupts etc).
I'm pretty sure the wiring is fine, as per the datasheet (GND pins 8,19; +5v pin 20) and the PIC is being programmed using a JDM2 DIY programmer that has been used successfully before including with this chip.
Any guesses as to why this might be acting so strangely?
Thanks, Joel
| Code: | #INCLUDE <18F2455>
#USE delay (internal=8M)
int counter = 0;
void main() {
while(1){
delay_ms(200);
output_bit(PIN_C0,counter);
counter = 1-counter;
}
} |
|
|
|
Back to top
|
|
 |
blue hell
Former site admin

Joined: Apr 03, 2004 Posts: 24864 Location: The Netherlands, Enschede
Audio files: 353
G2 patch files: 320
|
Posted: Sun Jun 22, 2008 8:24 am Post subject:
|
 |
|
| Sounds like a hardware issue to me with some input pin(s) having an undefined level ... maybe reset? or some of the intX pins? |
|
|
Back to top
|
|
 |
Joel

Joined: Sep 12, 2006 Posts: 97 Location: London, UK
|
Posted: Sun Jun 22, 2008 9:44 am Post subject:
|
 |
|
Hi Jan, I hoped you might take a look
I've added
| Code: |
set_tris_A(0x00);
set_tris_B(0x00);
set_tris_C(0x00); |
now the LED flashes continuously for much longer, and doesn't stop when I touch the regulator as before. Thanks!
However, if I pull the power and then replace it, the PIC doesn't start back up as normal; you have to plug the PIC into the board with the power already in place for it to start up. This isn't the case with the other PIC on the board. Any suggestions?
[Edit] The problem with touching the regulator still happens, but only when the other microcontroller circuit is powered as well. Guess the whole lot could be drawing too much power? So perhaps a separate issue [/Edit] |
|
|
Back to top
|
|
 |
blue hell
Former site admin

Joined: Apr 03, 2004 Posts: 24864 Location: The Netherlands, Enschede
Audio files: 353
G2 patch files: 320
|
Posted: Sun Jun 22, 2008 10:40 am Post subject:
|
 |
|
Making unused pins an output is a good idea (input would be OK as well, but then you should use a pull up or pull down resistor on it).
Whole lot of weirdness still, ok .. one thing at a time .. the reset issue ...
Did you look at your processor configuration words? MCLR should be defined as a reset pin, and you could be having a brown out issue ... maybe set the brown out level lower ... although an 7805 should be adequate to feed a handful of PICS .. is there anything else drawing a lot of current?
And then there is the reset circuit itself ... did you use the recommended circuit from chapter 4 in this data sheet? EDIT: the one for slow Vdd power up I mean.
Oh wait, what are you using for debugging? is there any debugging code auto-linked in? That could give issues with startup as well. |
|
|
Back to top
|
|
 |
Joel

Joined: Sep 12, 2006 Posts: 97 Location: London, UK
|
Posted: Sun Jun 22, 2008 11:06 am Post subject:
|
 |
|
Well, turns out connecting Pin1 (MCLR) high via a 10k resistor has solved all the problems, thanks! I hadn't previously thought to connect Pin1 to anything, I guess the floating was causing the problems
Looking at the configuration words, MCLR is enabled and the brownout voltage is set to 2v.
I've not looked into debugging at all (I think you need more hardware than a JDM2 programmer, right?), I think it'll have to wait for another day...
So in conclusion, sorry, I should have RTFM'd, and thanks again for your help  |
|
|
Back to top
|
|
 |
blue hell
Former site admin

Joined: Apr 03, 2004 Posts: 24864 Location: The Netherlands, Enschede
Audio files: 353
G2 patch files: 320
|
Posted: Sun Jun 22, 2008 11:14 am Post subject:
|
 |
|
| Joel wrote: | | I should have RTFM'd |
I know, you should ... and I should too ... in this case TFM is a bit overwhelming and it's not always easy to decide which parts to skip ... I've been using PICs for many years now and I still get nasty surprises at times ... tip .. read the errata as well! |
|
|
Back to top
|
|
 |
|