programming pic microcontroller

For E-blocks user to discuss using E-blocks and programming for them.

Moderators: Benj, Mods

Post Reply
kalim007
Posts: 67
Joined: Mon Jan 28, 2013 6:00 am
Has thanked: 20 times
Been thanked: 4 times
Contact:

programming pic microcontroller

Post by kalim007 »

Hi,
I am using flowcode EB006 to program pic16F877A. I can write program in flowcode, made hex file and downloaded the program in EB-board. Using input switch and output LED, everything works. But when I move pic microcontroller from this E-board to bread board and make my own interface circuit. It does not work at all. I used 20MHz crystal oscillator in between pin 16 and 17 with two capacitors.

Can anyone tell me why pic microcontroller is not showing any sign of having program in it?

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: programming pic microcontroller

Post by medelec35 »

Have you got pin1 (MCLR) pulled up to +5V via a minimum resistor of 10K?
If not your microcontroller will be in the Permanent reset state.

Martin
Martin

kalim007
Posts: 67
Joined: Mon Jan 28, 2013 6:00 am
Has thanked: 20 times
Been thanked: 4 times
Contact:

Re: programming pic microcontroller

Post by kalim007 »

Yes, I have used +5V with 47k register in pin 1.

kersing
Valued Contributor
Valued Contributor
Posts: 2045
Joined: Wed Aug 27, 2008 10:31 pm
Location: Netherlands
Has thanked: 553 times
Been thanked: 1081 times
Contact:

Re: programming pic microcontroller

Post by kersing »

Have you connected power to both pin 11 and 32 and ground to both 12 and 31?
“Integrity is doing the right thing, even when no one is watching.”

― C.S. Lewis

kalim007
Posts: 67
Joined: Mon Jan 28, 2013 6:00 am
Has thanked: 20 times
Been thanked: 4 times
Contact:

Re: programming pic microcontroller

Post by kalim007 »

Yes, I did add +5V to pin 11 and 32, ground with pin 12 and 31. I am using same voltage source for entire microcontroller biasing. When I design input circuit interface, I used the same voltage source. Is this OK?

kersing
Valued Contributor
Valued Contributor
Posts: 2045
Joined: Wed Aug 27, 2008 10:31 pm
Location: Netherlands
Has thanked: 553 times
Been thanked: 1081 times
Contact:

Re: programming pic microcontroller

Post by kersing »

I think you need to post your circuit diagram if you want us to help solve this puzzle.
“Integrity is doing the right thing, even when no one is watching.”

― C.S. Lewis

kalim007
Posts: 67
Joined: Mon Jan 28, 2013 6:00 am
Has thanked: 20 times
Been thanked: 4 times
Contact:

Re: programming pic microcontroller

Post by kalim007 »

Here I uploading the circuit diagram in pdf format. I forgot to draw crystal oscillator that was in between pin 16 & 17.
Attachments
circuit.pdf
(84.26 KiB) Downloaded 358 times

kersing
Valued Contributor
Valued Contributor
Posts: 2045
Joined: Wed Aug 27, 2008 10:31 pm
Location: Netherlands
Has thanked: 553 times
Been thanked: 1081 times
Contact:

Re: programming pic microcontroller

Post by kersing »

I would add a 100nF capacitor between 5V and GND at both 11/12 and 31/32 and one 10uF for the total circuit to stabilize the power supply.

Have you checked (with a multimeter) the 5V pins are actually getting 5V and the GND pins are connected to the power supply GND? I am asking because some breadboards have a 'split' in the 5V rail.
“Integrity is doing the right thing, even when no one is watching.”

― C.S. Lewis

kalim007
Posts: 67
Joined: Mon Jan 28, 2013 6:00 am
Has thanked: 20 times
Been thanked: 4 times
Contact:

Re: programming pic microcontroller

Post by kalim007 »

Yes, I checked voltage with multi meter, I found voltage is 4.95V most of the case. OK, I am going to add the capacitors that you mentioned. I am using same voltage source for all power supply, do you think this could be a problem?

kersing
Valued Contributor
Valued Contributor
Posts: 2045
Joined: Wed Aug 27, 2008 10:31 pm
Location: Netherlands
Has thanked: 553 times
Been thanked: 1081 times
Contact:

Re: programming pic microcontroller

Post by kersing »

Using the same 5V source for all 5V references in your circuit is fine.

Could you post your flowcode file so we can check the chip settings?
“Integrity is doing the right thing, even when no one is watching.”

― C.S. Lewis

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: programming pic microcontroller

Post by medelec35 »

I can't see your crystal connected on your circuit diagram.
Can you add it please?
With 16F877A:
crystal (and caps) should be connected to pins 13 & 14 (osc1 & osc2)
Not 16 & 17!

Also If I was you I would look at the data sheet for your Crystal as 26pf maybe a bit high?
On EB006 they are 10pf.
Not sure if that would cause an issue or not?
Try to connect to 13 & 14 1st

Martin
Martin

kersing
Valued Contributor
Valued Contributor
Posts: 2045
Joined: Wed Aug 27, 2008 10:31 pm
Location: Netherlands
Has thanked: 553 times
Been thanked: 1081 times
Contact:

Re: programming pic microcontroller

Post by kersing »

medelec35 wrote: crystal (and caps) should be connected to pins 13 & 14 (osc1 & osc2)
Not 16 & 17!
Why oh why didn't I notice this...

Glad you did Martin :-)
“Integrity is doing the right thing, even when no one is watching.”

― C.S. Lewis

kalim007
Posts: 67
Joined: Mon Jan 28, 2013 6:00 am
Has thanked: 20 times
Been thanked: 4 times
Contact:

Re: programming pic microcontroller

Post by kalim007 »

Thanks for pointing the oscillator connection. I have changed those connection to pin 13 and 14. I have not added 100 nF capacitor yet. I thought everything will work. But it did not. Output is not working the way I expected. I made some changes in port selection now. Now input is in port B and output in port A. I am attaching the flowcode code file for you to see.

Thanks in advance for your help.
Attachments
Test-2.fcf
Simple alarm system
(8.5 KiB) Downloaded 273 times

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: programming pic microcontroller

Post by medelec35 »

Your welcome.
kalim007 wrote: Output is not working the way I expected.
If you can state what your expecting and state what actually happened, we can help you further

Could it be you have left the i.p's to float (nothing connected when switch is not activated)?

If using an i/p, it must not be allow to float (with exception of touch switch application)
To prevent this each used input must be connected to either +5V or 0V via a pull-up or pull-down-resistor.
If allowed to float then i/p will drift above the logic 1 threshold giving unpredictable results

E.g if you want switch to change i/p from 0 to +5V.
Connect a resistor (4k7 to 15K) from i/p to 0V. connect switch from i/p to +5V

When switch is open, i/p is pulled down to 0V.
When switch is closed, i/p is pulled up to +5V

We always recommend before starting a new project, to just to do a 1Hz flash test.
e.g with LED and current limiting resistor connected to port B1:

Loop while 1
1>B1
delay 500ms
0>B1
delay 500ms

THis will determine if osc is running and at the correct speed.

For more information take a look here:
http://www.matrixmultimedia.com/mmforum ... =26&t=6936

Martin
Martin

kalim007
Posts: 67
Joined: Mon Jan 28, 2013 6:00 am
Has thanked: 20 times
Been thanked: 4 times
Contact:

Re: programming pic microcontroller

Post by kalim007 »

Thank you for your wonderful reply. Let me explain my project first. There are three inputs in port B (RB0, RB1, RB2) and two outputs in port A (RA0, RA1). This is a simple alarm system. When RB0 is active, LED in RA0 should turn ON. That means, alarm system is ON. One can disarm the alarm by activating RB1 switch. This is first step.

Second, when alarm is ON (i.e. LED in RA0 is ON), if RB2 is activated, that will activate LED in RA1. This state indicates alarm is buzzing. Now only one way alarm can be turn off that is by activating RB1 input.

If alarm is turned OFF, by activating switch RB2 will not activate RA1.

If you look at the program I am using only 3 i/o from port B and 2 i/o from port A, I do not think I have to do anything for other ports that I am not using in main program.

I am going to test using 1 Hz flasher. I will update my progress soon.

Thanks and best regards,

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: programming pic microcontroller

Post by medelec35 »

Your welcome.
kalim007 wrote: If you look at the program I am using only 3 i/o from port B and 2 i/o from port A, I do not think I have to do anything for other ports that I am not using in main program.
Correct. Any unused pins can be ignored. No pull-ups are necessary.

With your description, I will take a look at your flowchart.

Martin
Martin

kalim007
Posts: 67
Joined: Mon Jan 28, 2013 6:00 am
Has thanked: 20 times
Been thanked: 4 times
Contact:

Re: programming pic microcontroller

Post by kalim007 »

Hello,
I have tested 1 Hz flasher. It works pretty fine in breadboard. I used 100nF capacitor in both side of VDD and VSS. Circuit works without the these capacitors too. I have not tested my original circuit yet. I will update here as soon as I test it. Looks like things will go in right direction.

Many many thanks for your help.

Edit: I also have used 10pF capacitor with oscillator instead of 27pF.

kalim007
Posts: 67
Joined: Mon Jan 28, 2013 6:00 am
Has thanked: 20 times
Been thanked: 4 times
Contact:

Re: programming pic microcontroller

Post by kalim007 »

I have tested my circuit again in breadboard and it did not work. I do not know why? Did you find anything in software side? 1 Hz flasher program works pretty well though. I can explain what happen. If I activate input 1 (RB0), no LED turn ON. If I activate input 2 (RB1), both LED turns ON and stays on as long as I keep input ON. If I activate input 3 (RB2), no activity in LED.
Any opinion or direction for debugging?

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: programming pic microcontroller

Post by medelec35 »

Hi kalim007,
Can you post a circuit diagram please.
I have checked on hardware and its all working exactly as you have described.
When sw connected to B0 went from off to on, A0 did indeed Light. Moving B0 switch back to off LED stayed on.

When sw connected to B2 went from off to on, LED connected to A1 also lit.

When sw connected to B1 went from off to on, both LED's went off.

So the problem is probably with your hardware.

Wrong connections, Pull-ups wrong value. A suggestion would be to measure voltages on the i/p's and o/p's to make sure they are correct.

Martin
Martin

kalim007
Posts: 67
Joined: Mon Jan 28, 2013 6:00 am
Has thanked: 20 times
Been thanked: 4 times
Contact:

Re: programming pic microcontroller

Post by kalim007 »

Thanks Martin,
I also have a feeling that my circuit may have connection problem. I will test it tonight. I have attached the circuit diagram here.
Attachments
circuit.pdf
simple alarm system
(124.18 KiB) Downloaded 226 times

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: programming pic microcontroller

Post by medelec35 »

one difference between yours and my hardware is you have got pull-up resistors, so ports stay at +5V. When you close a switch, port will be pulled to 0V

With my hardware, I have got pull down resistors connected to the i/ps and when switches are closed, thee i/p goes from 0V to +5V.
Mine is done that way since your decisions are for active high. e.g you have got IF alarm_ state. (no value)

If you do not use a value
E.g instead of If alarm_state=0
you use If alarm_state
Then it will always be true for any value except 0
So the decision will only be true when the switch is open and not closed.

If not changed your hardware then try closing all your switches as a default then open them to switch on alarm etc.
So in your case RB0 is active when switch is in the off or open position.
Martin

kalim007
Posts: 67
Joined: Mon Jan 28, 2013 6:00 am
Has thanked: 20 times
Been thanked: 4 times
Contact:

Re: programming pic microcontroller

Post by kalim007 »

Thank you all for your wonderful help. Everything worked fine. Somehow (after searching in google) I got an idea that pic microcontrollers are active LOW. So, based on that impression, I designed pull up resistors for input. Actually, resistors should be pulled-down.

I am very happy with this forum. If there is any other way, I can say thank you, pls let me know.

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: programming pic microcontroller

Post by medelec35 »

Your welcome.
kalim007 wrote: Somehow (after searching in google) I got an idea that pic microcontrollers are active LOW. So, based on that impression, I designed pull up resistors for input. Actually, resistors should be pulled-down.
Actually you can use either pull-up or pull-down. Sensors like hall effects within motors sometimes require pull-up resistors, as they short to ground when a magnet goes near it to detect Revs.
you just need to alter your flowchart accordingly.

There are internal weak pull-up resistors that can be activated, on certain pins, so you only then need the switch.
kalim007 wrote: I am very happy with this forum. If there is any other way, I can say thank you, pls let me know.
Glad your happy as we do like to help when we can.
If a post has helped you. When your logged in, Just click on the 'Thumbs Up' icon top right of the post.

Martin
Martin

Post Reply