Nigel Goodwin said:You're not showing all the circuit, what about the power supply and decoupling capacitors?.
Here is the full circuit. And I did powered up the PIC with 5V on VDD (Pin 1) and Ground to CSS (Pin 8).
Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
Nigel Goodwin said:You're not showing all the circuit, what about the power supply and decoupling capacitors?.
mramos1 said:Try 100uF or larger (a little larger) for C2.
Good-eye Nigel.
What is the power source? Wallwart or battery?
Yes, I have it built exactly same way. Same effect.mramos1 said:Sorry, I meant 100uF on C2 only, .1 on C1. But a battery should be fine either way.
Have you actually built this? Or is it all simulation (grant it that was pretty cool)?
I'm using simplified programm, it doesn't actully uses any input. It just tries to turn 2 LEDs on at the same time. See below.mramos1 said:Did you drop the scope on the input pin and make sure it is not moving around (I see the voltage on the video says it is). Can you step through the software and get a hint where it is doing the toggle?
I haven't figure out a vay to step through teh program yet...mramos1 said:I load the list files sometimes with compiler code and step and many times see the problem right away.
That's what I assume also. That is where I need help.mramos1 said:Anyway when I have weird things happen with PICS, it is always something simple I missed. Not turning off something, MCLR, CMCON, ADCON1, noise, etc.
mramos1 said:Do not give up, others will pop in and help you find it. I just do not see it and no time to dig out datasheet and build one.
@ DEVICE PIC12F683,MCLR_OFF,INTRC_OSC_NOCLKOUT,WDT_OFF,BOD_OFF
@ DEVICE PWRT_ON,FCMEN_OFF,IESO_OFF,PROTECT_ON
GrnLED VAR GPIO.0
RedLED VAR GPIO.1
'A/D Parameters
DEFINE OSC 8
DEFINE ADC_BITS 8 ' Use 10-bit A/D as 8-bit A/D
DISABLE INTERRUPT
ANSEL.3 = 1 ' Set ANS3 as analog input pin
ANSEL.4 = 0 ' Set A/D clock
ANSEL.5 = 1
ANSEL.6 = 0
ADCON0.0 = 1 ' Turn On A/D
ADCON0.2 = 1 ' A/D channel 3
ADCON0.3 = 1 ' ?
ADCON0.6 = 0 ' VDD is voltage reference
ADCON0.7 = 0 ' Left Justify result
'GPIO port pins 0, 1 as outputs
TRISIO.0 = 0
TRISIO.1 = 0
PauseUs 100
start:
HIGH GrnLED
PauseUs(10)
HIGH RedLED
PauseUs(500)
goto start
@ DEVICE PIC12F683,MCLR_OFF,INTRC_OSC_NOCLKOUT,WDT_OFF,BOD_OFF
@ DEVICE PWRT_ON,FCMEN_OFF,IESO_OFF,PROTECT_ON
GrnLED CON 0 ' Green LED
RedLED CON 1 ' Red LED
Vin VAR BYTE ' Allocate A/D variable
DEFINE OSC 8
DEFINE ADC_BITS 8 ' Use 10-bit A/D as 8-bit A/D
DEFINE ADC_CLOCK 3 ' Set clock source (3=rc)
DEFINE ADC_SAMPLEUS 50 ' Set sampling time in uS
DISABLE INTERRUPT
ADCON0.0 = 1 ' Turn On A/D
ADCON0.2 = 1 ' A/D channel 3
ADCON0.3 = 1 ' ?
ADCON0.6 = 0 ' VDD is voltage reference
ADCON0.7 = 0 ' Left Justify result
ANSEL = %00111000 ' Set AN3 analog, rest digital
CMCON0 = 7 ' Analog comparators off
'GPIO port pins 0, 1 as outputs
TRISIO.0 = 0
TRISIO.1 = 0
PAUSE 10
start:
ADCON0.1 = 1 ' Start conversion
WHILE ADCON0.1 = 1 ' Wait for conversion to finish
PAUSE 10
WEND
Vin = ADRESH 'Write conversion result
PAUSE 10
'Display results
IF Vin < 70 THEN
LOW GrnLED
HIGH RedLED
ENDIF
IF Vin > 69 AND Vin < 120 THEN
HIGH GrnLED
HIGH RedLED
ENDIF
IF Vin > 119 AND Vin < 180 THEN
HIGH GrnLED
LOW RedLED
ENDIF
IF Vin > 179 THEN
LOW GrnLED
TOGGLE RedLED
ENDIF
PAUSE 250
GOTO start
MrSpock said:How can I convert ADC rconversion result (VAR Vin) into the actual number of volts? Is there a formula to do so? I noticed it's not a linear dependency. ]
Nigel Goodwin said:It is a linear function, 0V should give a 0 output, and a voltage equal to Vref (5V in your case) should give 1023 out. So multiply it by 5, then divide by 1023, to give the result in volts.
@ DEVICE PIC12F683,MCLR_OFF,INTRC_OSC_NOCLKOUT,WDT_OFF,BOD_OFF
@ DEVICE PWRT_ON,FCMEN_OFF,IESO_OFF,PROTECT_ON
GrnLED CON 0 ' Green LED
RedLED CON 1 ' Red LED
Vin VAR BYTE ' Allocate A/D variable
Sample VAR WORD
DEFINE OSC 8
DEFINE ADC_BITS 8 ' Use 10-bit A/D as 8-bit A/D
DEFINE ADC_CLOCK 3 ' Set clock source (3=rc)
DEFINE ADC_SAMPLEUS 50 ' Set sampling time in uS
DISABLE INTERRUPT
ADCON0.0 = 1 ' Turn On A/D
ADCON0.2 = 1 ' A/D channel 3
ADCON0.3 = 1 ' ?
ADCON0.6 = 0 ' VDD is voltage reference
ADCON0.7 = 0 ' Left Justify result
ANSEL = %00111000 ' Set AN3 analog, rest digital
CMCON0 = 7 ' Analog comparators off
'GPIO port pins 0, 1 as outputs
TRISIO.0 = 0
TRISIO.1 = 0
PAUSE 10
start:
ADCON0.1 = 1 ' Start conversion
WHILE ADCON0.1 = 1 ' Wait for conversion to finish
PAUSE 10
WEND
sample = ADRESH 'Write conversion result
PAUSE 10
Vin = sample * 5 / 1023
'Display results
if Vin < 2 then
LOW GrnLED
HIGH RedLED
endif
if Vin > 2 AND Vin < 3 then
HIGH GrnLED
HIGH RedLED
endif
if Vin > 3 AND Vin < 4 then
HIGH GrnLED
LOW RedLED
endif
if Vin > 4 then
LOW GrnLED
TOGGLE RedLED
endif
Pause 250
goto start
I mean in the code Vin never get passed 2 volts. RedLED is always HIGH.mramos1 said:Would 8 bits be 255 for 5 volts? Is that what you mean by 2 volts?
mramos1 said:Do you know if the voltage on that pin is over 2 volts (take a meter to it). What value is the PIC returning and what voltage do you have?
MrSpock said:Yes, I have a voltage dividing potentiometer attached to the input (Pin 3). It gives 0V to 5V voltage range. I confirmed it with the voltmeter.
Unfortunatelly I don't know how to debug the circuit. Would be nice to see the actual value of the conversion result while circuit is running.
Nigel Goodwin said:Use a spare pin as a serial output port, squirt it out to your PC and display it in HyperTerminal.