PIC basic circuit problem

For questions and comments on programming in general. And for any items that don't fit into the forums below.

Moderators: Benj, Mods

Post Reply
JimWalker
Posts: 5
Joined: Wed May 13, 2009 8:25 am

PIC basic circuit problem

Post by JimWalker »

Hi

This is going to be a real beginner question, but having embarrasingly spent 4 days not getting anywhere I thought it might be sensible to ask someone for help.

I am trying to make a basic blinking LED program - i've tried this with a 16F877 but got nowhere, and am now getting equally nowhere with a 16F874.

The code is attached to this post whch should simply flash PORTB high and low. This works in Flowcode.

I am programming the chip using a PICKit2 and from flowcode when I 'compile to chip' I get 'Program suceeded' and 'Operation Suceeded'

The path is correct and the parameters I think are also correct...
-PPIC%p -F%F.hex -M -A5 -H

My circuit is very simple (and possibly to blame) but I am struggling to find a problem with it.

Can anyone help by spotting a problem with either the circuit or program. (excuse the crudity of the drawing)

Thanks in advance.

Jim
Attachments
circuit.jpg
(43.52 KiB) Downloaded 1862 times
Flowcode1 16f874.fcf
(4 KiB) Downloaded 288 times
Last edited by JimWalker on Sat May 16, 2009 3:32 pm, edited 1 time in total.

Sean
Valued Contributor
Valued Contributor
Posts: 548
Joined: Tue Jun 26, 2007 11:23 am
Has thanked: 6 times
Been thanked: 44 times

Re: PIC basic circuit problem

Post by Sean »

Hello Jim,

The problem might be with the Reset/MCLR circuit. The 10K resistor should be connected to Vdd to act as a pull-up during normal operation.

An additional signal diode could be added in series with the 10K resistor (blocking the return path from MCLR to Vdd) to help prevent the high programming voltage on the MCLR pin from affecting Vdd.

Also, make sure the load produced be the LED circuit does not affect the operation of the PGD signal (can the LED be moved to another pin?).

JimWalker
Posts: 5
Joined: Wed May 13, 2009 8:25 am

Re: PIC basic circuit problem

Post by JimWalker »

Hi Sean

Thank you for the message.

I have connected the MCLR pin through the resistor and diode as you have suggested. Also I've moved the LED on to another PortB pin.

I've updated the schematic in my original post to show what the circuit now looks like. Unfortunately this is still not working.

To give some more information which I have now established - I think the PIC is programming ok. When I program it throught the PICkit 2 programmer and 'Verify' after i've done it, it shows the same code. I can do all the obvious things from the PICkit 2 software as well such as erase, verify, blank check.

This makes me believe it is the after programming bit which is not working.

Thanks again for your suggestions.

Jim

Sean
Valued Contributor
Valued Contributor
Posts: 548
Joined: Tue Jun 26, 2007 11:23 am
Has thanked: 6 times
Been thanked: 44 times

Re: PIC basic circuit problem

Post by Sean »

Hello Jim,

I made an exact copy of your updated drawing on solderless breadboard, and downloaded the hex file generated from your Flowcode Program (using the PICKit2 programmer software). It worked perfectly first time!!!

The only additional checks I can think of are:
1/ Make sure the PICKit is configured to supply power to the circuit after programming is complete - or use an external power supply.
2/ Make sure 5v is present on the MCLR pin
3/ Check that the LED polarity is correct. If you have a volt meter you shoud be able to measure approximately 2.5v on the Port B pins - indicating that they are switching between 5v and 0v.

JimWalker
Posts: 5
Joined: Wed May 13, 2009 8:25 am

Re: PIC basic circuit problem

Post by JimWalker »

Hi Sean

Thank you very much for taking the time to look into this and test the circuit.

I am extremely pleased it's now working. I did try all the suggestions you had made, and on a whim also replaced the crystal I was using with one I had lying around, and the led started blinking.

The crystal I was originally using was a 20mhz low profile type which I actually bought to go in another kit based on a pic. The 'normal' crystal was a 4mhz crystal. I am certain the chip is rated for 20mhz - i've actually tried several different chips 877, 873, 874 and with that type of crystal there was similiarly no response. With the 4mhz crystal however, it works on all. The pic attached shows the type I am referring to.

The circuit I intend building needs to time responses, so now I know the circuit works I intend to try faster crystals up to 20mhz but perhaps only on the 'normal' sized crystals to be on the safe side, or until i've researched what the difference is.

Thanks once again for your help.

Jim
Attachments
crystals.JPG
crystals.JPG (6.59 KiB) Viewed 5084 times

Sean
Valued Contributor
Valued Contributor
Posts: 548
Joined: Tue Jun 26, 2007 11:23 am
Has thanked: 6 times
Been thanked: 44 times

Re: PIC basic circuit problem

Post by Sean »

Hello jim,

I used a 16MHz xtal with two 22pF capacitors. The clock circuit seems to be quite tolerant of layout and component value variations.

The 874A devices are good for 20MHz. If you have an 874 (no A suffix) check to see if there is a speed rating at the end of the part number. There might have been lower frequency versions of the older devices (10MHz).

Microchip specify the use of 'parallel cut' crystals; series cut crystals might not work correctly.

Post Reply