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.

Need help to troubleshoot

Status
Not open for further replies.

ssocs45

New Member
Hi everyone, I would like some help to solve a problem with a project that I’m working on. Hope someone can point out what I’m doing wrong and help correct the mistake. Basically I’m doing a project using PIC12F675 which blinks one of the two LEDs depending on how much voltage is fed in the ADC pin (Analog to Digital Conversion pin). I have used a LDR ( Light Dependent Resistor ) in series with a resistor as in a voltage divider concept and taking the voltage from the center of the LDR and resistor as the input for the ADC pin. The function of this whole circuit is to tell if the light ambience in the room is below or above a predetermined amount. It should blink Green for above and Red for below the predetermined amount. (I have attached a schematic for a clearer picture)

This is how I have programmed the PIC12F675 using PIC Basic Pro. Thanks in advance for the help:)

LED1 con 4
LED2 CON 5

CMCON=7
ANSEL=%00001000
TRISIO=%10000000
ADVAL VAR BYTE
K VAR WORD
ROCK VAR WORD
ROCK=%01010101

CHECK:

ADCIN 0, ADVAL

notdone:

IF ADVAL > ROCK THEN
GOTO MMM
ELSE
GOTO MM2
ENDIF

MMM: FOR K = 1 TO 2
HIGH LED1
HIGH LED2
PAUSE 250
LOW LED2
LOW LED1
PAUSE 250
NEXT K
GOTO CHECK

MM2: HIGH LED1
PAUSE 250
LOW LED1
PAUSE 250

GOTO CHECK

END
 

Attachments

  • schematic_515.jpg
    schematic_515.jpg
    9.6 KB · Views: 424

ivancho

New Member
I have not checked throughly the datasheet on the PIC so I am not familiar with the name of its registers. But here are some things I want to point out.

First..... MAke sure that you put a limiting resistor on those LED, you may damage your PIC and burn the LED if not.

Second.... You are comaparing a WORD size variable to a BYTE size variabel when you are doing the IF ADVAL > ROCK THEN

Third...... According to the datasheet the maximum impedance recomended for analog sources is 2.5kOhms

Fourth..... YOu have not set the ADCON0 register. You need to do this and justify left the A-D conversion. And set your voltage reference pin.

Fifth....... Yout TRISIO is a 6-bit wide register. You must declare those pins with the LEDS outputs, and the one with the Analoge Voltage INPUT, like TRISIO = %110000

Sixth.... Make sure you have configured the PIC to run on internal oscilator.

Seventh..... Your ROCK variable is set to 85. That is your threshold voltage will be 0.415V (that is (5V/2^10)*85). When the voltage divider made by the LDR and resistor is 0.415V the condition IF ADVAL > ROCK THEN will be true. Is this the threshold voltage you really want?

Eight....... When you use the command ADCIN will use the ADC and not as a comparator. So you don't have to set the CMCON register.

Good Luck

Ivancho
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Top