Author Topic: Blinking Circuit Works in Simulation but Fails in Breadboard  (Read 3800 times)

0 Members and 1 Guest are viewing this topic.

Offline ArkoniteTopic starter

  • Newbie
  • Posts: 3
  • Country: ph
Blinking Circuit Works in Simulation but Fails in Breadboard
« on: December 06, 2022, 12:36:31 pm »
Hello,

I have this blinking circuit that is programmed in C and uses the PIC16F84A. I already got it to work in Proteus 8 but my problem is that I can't get it to work on a breadboard. I'm posting here right now to ask for guidance on whether I have missing or incorrect circuit connections. I also already connected the VDD and VSS when testing on a breadboard.

Attached below is a picture of my simulation and code which works as follows:
If switch 2 and 3 is close, led D6 and D8 will light up.
If switch 1,2, and 3 is close, only led D6 will light up.
If switch 2,3, and 4 is close, only led D8 will light up.
Otherwise, any other switch combination will cause no led to light up.

« Last Edit: December 06, 2022, 12:38:20 pm by Arkonite »
 

Offline jpanhalt

  • Super Contributor
  • ***
  • Posts: 3313
  • Country: us
Re: Blinking Circuit Works in Simulation but Fails in Breadboard
« Reply #1 on: December 06, 2022, 01:18:32 pm »
1) The 16F84A does not have an internal oscillator.  What are you using?  Related to that, you have OSC1/CLKIN grounded.  Will that work?
2) I would add small resistors in series with each LED to limit current.
 
The following users thanked this post: Arkonite

Offline ledtester

  • Super Contributor
  • ***
  • Posts: 3032
  • Country: us
Re: Blinking Circuit Works in Simulation but Fails in Breadboard
« Reply #2 on: December 06, 2022, 01:27:07 pm »
I don't see a timing capacitor in your circuit. Here's what the PIC16F84A datasheet says about using an RC-oscillator for a clock (page 23):

https://ww1.microchip.com/downloads/aemDocuments/documents/MCU08/ProductDocuments/DataSheets/35007C.pdf

1656379-0
 
The following users thanked this post: Arkonite

Offline Ian.M

  • Super Contributor
  • ***
  • Posts: 12658
Re: Blinking Circuit Works in Simulation but Fails in Breadboard
« Reply #3 on: December 06, 2022, 01:28:21 pm »
Your circuit's no good.  The PIC16F84A does *NOT* have an internal oscillator so its sitting there doing diddly-squat!  You'll need to provide either an external clock signal, a crystal + load capacitors, or a RC network as per PIC16F84A datasheet section 6.2 Oscillator Configurations.  As MikroC doesn't support setting CONFIG words in your code, you'll also have to choose a suitable CONFIG that lets your chosen oscillator type actually work  in your programmer utility whenever you program the chip.  See: datasheet section 6.1 Configuration Bits. 

*NONE* of the oscillator modes can work with OSC1 grounded! |O

N.B. RC oscillator mode is only suitable for use with the fig. 6-3 circuit, and cannot be used with an external clock.

--
I hate intensely dislike this new editor! - https://www.eevblog.com/forum/supporters-lounge/editing/
« Last Edit: December 06, 2022, 01:32:57 pm by Ian.M »
 
The following users thanked this post: Arkonite

Offline ArkoniteTopic starter

  • Newbie
  • Posts: 3
  • Country: ph
Re: Blinking Circuit Works in Simulation but Fails in Breadboard
« Reply #4 on: December 28, 2022, 03:46:09 pm »
Thanks to everyone for their help last time. After some changes in the code and circuit, I managed to make it work on a breadboard, but I ran into some problems after connecting the output of my IR sensor to the PIC16F84A Port A pins, which are set as input. I tested the IR sensor, and it works fine, but the moment I connect it to the breadboard, the LED indicator lights up permanently for some reason, which should really only be triggered if there is an object nearby that reflects the IR lights emitted. I have attached below a picture of the exact IR sensor that I used, and if I base it on the circuit, it seems like the PIC sends back a voltage to light up the indicator LED of the IR. I have 4 IR sensors connected to 4 Port A pins, and every single one of their indicator LEDs lights up after being connected. So my questions are as follows:


1. Is it normal for voltage to be present at the pins of the PIC even though it is set as an input?
2. Do I have to set these Port A pins with a voltage "low" in the code?
3. Should the 5 volt VCC of the IR sensor be independent of the VCC of the PIC16 so that they won't share a common ground?
 

Offline Ian.M

  • Super Contributor
  • ***
  • Posts: 12658
Re: Blinking Circuit Works in Simulation but Fails in Breadboard
« Reply #5 on: December 28, 2022, 04:35:37 pm »
1. Is it normal for voltage to be present at the pins of the PIC even though it is set as an input?
2. Do I have to set these Port A pins with a voltage "low" in the code?
3. Should the 5 volt VCC of the IR sensor be independent of the VCC of the PIC16 so that they won't share a common ground?
  • *NO*   Most likely the pins you think are inputs aren't.  Unlike AVRs, PICs use 0 bits in the direction register (in your case TRISA) to select outputs and 1 bits for inputs.
  • No.  Unlike AVRs,  the value written to the port for output has no effect on input pins.
  • No.  They *MUST* share a common ground for the PIC to read the sensor output, and should share a common supply, so the PIC pins are never exposed to voltages significantly greater than its Vdd supply.  However it is permissible to power just the PIC via a low Vf drop diode (e.g a smalll Schottky one) so when performing in-circuit programming, the programmer doesn't have to supply power to the rest of the circuit.
« Last Edit: December 28, 2022, 04:41:52 pm by Ian.M »
 

Offline jpanhalt

  • Super Contributor
  • ***
  • Posts: 3313
  • Country: us
Re: Blinking Circuit Works in Simulation but Fails in Breadboard
« Reply #6 on: December 28, 2022, 07:13:39 pm »
To which pin on PORTA is it attached? 
 

Offline ArkoniteTopic starter

  • Newbie
  • Posts: 3
  • Country: ph
Re: Blinking Circuit Works in Simulation but Fails in Breadboard
« Reply #7 on: December 29, 2022, 12:41:18 pm »
To which pin on PORTA is it attached?  
One IR sensor is attached for Ra0, Ra1, Ra2, and Ra3.

After more testing, I have confirmed that initially, the Port A pins set as input have a very low voltage of approximately 0 volt, so it works well. I tested the IR sensor, and it matches the product description given, which I have attached below. I measured the voltage at the pins of the PIC16 when it is connected to the IR output, and for some reason there is a value of 1 volt and the indicator LED of the IR lights up. I really don't understand why this is so, because if there is no object in front of the IR, it should have a value of 5 V and the LED should be off. I suspect that there might be something wrong with how I set up my pull-down resistor. (The switches in the schematic below represent the output of the IR sensor.)

Also, do I really need a pull-down resistor? Is it possible to just directly connect the output of the IR to the PIC16 pins?
 

Offline Ian.M

  • Super Contributor
  • ***
  • Posts: 12658
Re: Blinking Circuit Works in Simulation but Fails in Breadboard
« Reply #8 on: December 29, 2022, 12:53:31 pm »
Well, that's certainly *NOT* how you should connect those sensors.  They aren't switches, and cant be connected as switches.

Each requires a three wire connection, from its labelled pins OUT, GND and VCC, to a PIC input and its power pins.

  • OUT connects to a single PIC I/O pin configured as an input and should *NOT* have an external pulldown resistor.
  • VCC connects to PIC VDD, (and +5V power supply) with all sensors wired in parallel.
  • GND connects to PIC VSS, (and supply ground/0V) with all sensors wired in parallel.
« Last Edit: December 29, 2022, 12:55:18 pm by Ian.M »
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf