Re: Stable ADC readings
Ah ok I see, you read a voltage then act upon. Cool, I did something like that awhile back but it was for car remote starter purpose (Door lock, alarm bypass, Windows roll-up/down) Oh well, those were the days 
Yes MCLR must be tied to Vdd. 4.7K is fine.
not sure of what you want to do and how it should flash your LEDs but try this one
Code:
bmf_comm1 VAR PORTB.0
bmf_comm2 VAR PORTB.1
LEDBlinkRate CON 200
'Variables
bmfsD VAR WORD
bmfs1D VAR WORD
iled var byte
'configuration du port pour lire l'entrée analogique
TRISA = %00000011 ' RA0 et RA1 en entrée
TRISB = %11111100 ' RB0 et RB1 en sortie
DEFINE ADC_BITS 10 ' Set number of bits in result
DEFINE ADC_CLOCK 3 ' Set clock source (rc = 3)
DEFINE ADC_SAMPLEUS 50 ' Set sampling time in
ADCON1 = %10000010 ' RA0 à RA3
test_depart:
PORTB = 3 ' Turn ON PORTB<1:0>
pause LEDBlinkRate '
val_leds:
PORTB = 0 ' Turn OFF PORTB<1:0>
PAUSE LEDBlinkRate
ADCIN 0,BMFSd ' Read CH0
ADCIN 1,BMFS1d ' Read CH1
if (bmfsD > 1000) Then val_leds
if (bmfsD > 750) Then boucle_led
if (bmfsD > 500) Then boucle1_led
if (bmfsD > 250) Then boucle2_led
goto test_depart
boucle_led:
PORTB = 1
for ILED = 0 to 5
PORTB = PORTB ^ 3
PAUSE LEDBlinkRate
NEXT
goto val_leds
boucle1_led:
High bmf_comm1
pause LEDBlinkRate
goto val_leds
boucle2_led:
high bmf_comm2
PAUSE LEDBlinkRate
Goto val_leds
End
seems to work for me here, 4MHz oscillator, some different led blinking opattern depending of the value of AN0.
Last edited by mister_e; - 24th August 2011 at 22:54.
Steve
It's not a bug, it's a random feature.
There's no problem, only learning opportunities.
Bookmarks