PDA

View Full Version : Help needed to troubleshoot



ssocs45
- 25th February 2004, 12:47
Hi everyone, I would like some help to solve a problem with a project that I知 working on. Hope someone can point out what I知 doing wrong and help correct the mistake. Basically I知 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 a schematic below 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

NavMicroSystems
- 25th February 2004, 14:13
according to your schematic the output of the voltage divider is connected to AN1 (Pin6) but you are reading on AN0 (Pin7) "ADCIN 0"

Change your Code to:

CMCON=0
ADCON=0

ADCIN 1, ADVAL

You should put some current limiting resistors in series with the LEDs (470R - 1k)

Does the 10k resistor in the divider match the range of the LDR ?

rgds

Melanie
- 26th February 2004, 17:56
Just glancing at your schematic, put Resistors (anywhere between 220R and 390R) in series with your LED's. You don't want to stress out the driver stages in your PIC.

Dwayne
- 26th February 2004, 18:00
Hello !


Please take my answer with a grain of salt, because I am EXTREMELY new with these chips. My knowledge is extremely limtied. But I think (Please someone correct me if I am wrong, and tell me why) you may have to change your TRISCIO value to somethign else...

Yours->>TRISIO=%10000000

I *think* the new one should be:

TRISCO=%00001010 to make your IO port 1 a AD instead of a input/output.

Dwayne (sorry if I am in error)