Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Odd PIC Copy Problem

Status
Not open for further replies.

bobledoux

Member
In my ten years of PIC programming I just came across and odd problem.

I have a PIC 12F683 running in a hardware application. A friend asked for a PIC copy for his use.

So I pulled up the software and copied a new PIC.--It didn't work. I copied to a second PIC and again, it didn't work.

I copied the software from the working PIC to a new PIC. The new PIC didn't work.

I compared the hex files from the good and bad PIC's and they are identical.

I checked configuration bits and again, they are the same.

What am I missing?
 
Post your software here and I will try it. If it is in assembly, I would prefer that, as hex files make me a little nervous.

John
 
The issue appears to be the ADC.

The ADC is used to read an optointerruptor with the light sensor powered from VDD through a 47K resistor. The non-interrupted values are read differently between the two PIC's The working PIC reads the ADC input voltage as 0.77 volts. The non-working PIC reads the input voltage as 2.67 volts. In both cases the compiled code is identical. This suggests the ADC is not being properly implemented.
 
I have not used the ADC on my 12F683's, so I can't offer any insight into whether anything has changed.

John
 
The issue appears to be the ADC.

The ADC is used to read an optointerruptor with the light sensor powered from VDD through a 47K resistor. The non-interrupted values are read differently between the two PIC's The working PIC reads the ADC input voltage as 0.77 volts. The non-working PIC reads the input voltage as 2.67 volts. In both cases the compiled code is identical. This suggests the ADC is not being properly implemented.

What are you setting the reference as? - it's much more likely a mistake in the code or hardware than an undiscovered bug in the PIC.
 
I did something similar.... Two identical pic16f877a's one worked the other didn't... It eventually came to pass that I was reading the wrong ADC port ADC_CH1 instead of ADC_CH0
The capacitance on one chip allowed cross talk so it appeared as if it was working... So to cap it.. The working one, wasn't working correctly and the non working one ... was.

Weird Eh!!

Could be a pin fault though...
 
There has been no changes made to any thing in that chip that would make code that worked not work.
The op has something else going on here hardware not the same or something

Only changes made
The PIC12F683 parts you have received conform
functionally to the Device Data Sheet (DS41211D),
except for the anomalies described below.
Microchip intends to address all issues listed here in
future revisions of the PIC12F683 silicon.
1. Module: Resets (when WDT times out)
If the OPTION_REG bits, PS<2:0>, are clear,
multiple spurious Resets can occur when the WDT
times out. These Resets can occur even when the
PSA bit is clear, assigning the prescaler to the
Timer0.
Work around
If a CLRWDT instruction is issued before the WDT
times out and before the OPTION register is
modified, this problem is eliminated.
Date Codes that pertain to this issue:
All engineering and production devices.
2. Module: ECCP with Auto-Shutdown
(Silicon Rev. A1 and B1)
The PIC12F683 Rev. A1 silicon for the ECCP
Auto-Shutdown is connected to the CMIF flag. See
Figure 8-2 on the following page.
Rev. A1’s auto-shutdown connection to CMIF
causes the auto-shutdown to incorrectly operate
synchronously. Additionally, reads of CMCON0 will
incorrectly clear an auto-shutdown event.
Work around
Rev. A1 Silicon
1) Poll the COUT bit until it is low.
2) Read CMCON1 to precondition CMIF.
3) If CMCON0 is read while COUT is changing,
repeat steps 1 and 2.
Fix
Rev. B1 Silicon
The Silicon Rev. B1 device (now shipping) has
moved the auto-shutdown connection from CxIF to
CxOUT. This will eliminate the synchronous
shutdown and simplify the use of the comparator
for a shutdown event. Figure 1 shows the function
of auto-shutdown before and after the device
revision.
 
Problem Confirmed

The ADC input voltage is read differently by the two PIC's. See attached drawing.

We have an opto-interruptor consisting of an LED and optotransistor. The sensing transistor is fed from VDD, 5 volts, through R8, a 47K resistor.

I have taken two PIC 12F683's and programmed them with the same code and placed them in the same piece of hardware.

PIC #1 reads the ADC input, AN3 (GP4) as 0.77 volts with light beam unobstructed and 1.47 volts with light beam blocked.

PIC #2 reads 2.77 volts with light beam unobstructed and VDD (5.03 volts) with the light beam blocked.

So, why the difference in ADC input voltages?
 
be80be:

WDT is disabled.
Comparator is used but for other functions
No auto shutdown

The only variable I see might be the 10K max input impedance.

I'll review ADC implementation code to ensure it is correct.

I don't see anywhere I change the function of pin AN3 (GP4) that would impact current draw on that pin.

Thnx
 
As you still haven't posted your code, we can't really help you.

But why are you using the ADC to read a digital input anyway? - the point of the opto-isolator is that it's a digital ON/OFF connection.
 
If he wants to measure light intensity maybe, But it's not real useful for that . If light intensity is what the OP is after a photo resistor would be better,Lot more range.
 
I've attached a file showing the ADC operation and setup. The program is 400 instructions long so I chose to extract pertinent portions. The word "Trigger" in software refers to the opto-interruptor switch and its open or closed state.

The ADC is right justified and 10 bits. In PIC #1 the ADC input voltage was about 0.8 volts with switch open and 1.5 volts with switch closed. As a result ADRESH =0 with switch open and does not equal 0 with switch closed. So I used the Z flag to test for switch state.

In PIC #2 and #3, the ADC input voltage was 2.77 volts with switch open and 5.00 volts with trigger closed. To make the software work I had to change the ADC so if bit 0 and bit 1 of ADRESH were set the switch is reported as closed. This software change is not shown in code. It was tested and it worked for these two PIC's.

There was no change to hardware and software between the three PIC's. Only the input impedance appears to have changed.
 
Last edited:
I wanted to use a digital logic input for the switch. But I could not adjust the photo- transistor resistor so the voltage range would swing between TTL limits. Therefore, I was forced to use the ADC because my comparator was already being used for other purposes.
 
There two things wrong with what you posted the 880 on the led side is way to high change that to 220 ohm and lower the phototransistor resistor to 10k

It will switch high to low the input pin will be high till the photo transistor is on

If the led resistor is to high the photo-interrupter will not work as a switch, LED never get bright enough to turn the transistor on fully so you'll read high voltages levels like your posting.

There are some of these that that need a 100 ohm on the Led side to work right.

I would read as a switch using these values
View attachment 61957
 
Last edited:
CONFIG fuses? I know they are usually included in the HEX file, but some programmers overwrite the config settings with the settings in the programmer checkbox.

If the new chips you are programming get wrong config they will not work.

As a test, program that same HEX file back into the working PIC. If it stops working you will know it is something like config fuses and NOT the PIC itself.
 
Roman, the config bits were set by directive, not pull down menu.

I think be80be has hit it. I must be running the photo transistor in linear mode so each PIC reads the input differently.

The original factory circuit used 1.2k current limiting resistor on the IRLED and 47K on the photo transistor. The circuit is powered by a 9 volt ANSI-1604 battery. The original unit employed CMOS logic hardware. I reverse engineered the functions and replaced the hardware with a PIC.

The sensor unit is potted and I didn't know the component specs. I tested the IRLED with various load resistors. A 220 ohm resistor drew 17 ma. My final choice of 820 ohms drew 4.7 ma.

With the 820 and 47K ohm combination, my first PIC read 0.22 volts with LED unblocked and 4.88 volts with the light beam blocks. Vdd was 5.0 volts. This allowed the use of a digital logic input pin.

When I programmed a second PIC the sensor output voltage range was no longer digital so I implemented the ADC to allow adjusting for the unique PIC variation. The second PIC ranged from 0.8 volts to 1.5 volts for input.

I started this thread when the third PIC ranged from 2.77 volts to 5 volts.

In each case the PIC was programmed identically. But each PIC appears to have had a different input pin impedance so the reported voltage range differed drastically.

It appears I need to increase current flow in the IRLED and reduce the resistance on the photo transistor to ensure it operates in switching mode.

Thanks all.
 
There are some photo-interrupters that need as much as 50mA to switch right but most are happy with 20 to 25mA I would stay at 20mA and power at 5 volts same as the pic

When testing some photo-interrupters I have saved from copiers I used a pot to set the best switching performance
 
Status
Not open for further replies.

Latest threads

Back
Top