I tried but it did not worked, I think Im missing something, but I can't figure it out.
pointers to adc examples for the 12f675/683 are welcome. Thanks
I tried but it did not worked, I think Im missing something, but I can't figure it out.
pointers to adc examples for the 12f675/683 are welcome. Thanks
Hi,Peu
I remember CMCON = 7 is used on my 16F628 to DISABLE all Analogic inputs ...
Verify if the same config. word for 12F675...
your Pb seems to be here ...
Alain
with this new header:
DEFINE ADC_BITS 10
DEFINE ADC_CLOCK 3
DEFINE ADC_SAMPLEUS 50
'cmcon=7
ADCON0=%11000011 'dec 195
ansel=%001
it still does not work ... any idea?
All you need to set is ADCON0.7 = 1 for right justification. PBP will
handle channel select bits and ADON.
Try this.
Assuming you have your config fuse options & oscillator setupCode:DEFINE ADC_BITS 10 DEFINE ADC_CLOCK 3 DEFINE ADC_SAMPLEUS 50 number VAR word CMCON = 7 ' Comparators off ANSEL = %00000001 ' GPIO.0 A/D in, rest digital ADCON0.7 = 1 ' Right justify for 10-bit TRISIO = %00000001 ' GPIO.0 = input, rest outputs Pause 100 Loop: ADCIN 0, number ' (0-1023) IF (number > 0) AND (number < 400) Then GPIO 1=1 GPIO.2=0 GPIO.4=0 EndIF IF (number > 401) AND (number < 800) Then GPIO.1=0 GPIO.2=1 GPIO.4=0 EndIF IF (number > 801) AND (number < 1024) Then GPIO.1=0 GPIO.2=0 GPIO.4=1 EndIF number = 0 GoTo loop End
properly, this should work.
You can find several more 12F675 A/D examples here;
http://www.microengineeringlabs.com/...ples.htm#x4pbp
Bruce:
Thanks var word
loop:
thanks=$FFFF '
it works, now I need to adjust the code because the led dont work as expected, but I put a serout after the adcin and the terminal reads the different values OK!!!
goto loop
Code:DEFINE ADC_BITS 10 DEFINE ADC_CLOCK 3 DEFINE ADC_SAMPLEUS 50 number VAR word CMCON = 7 ' Comparators off ANSEL = %00000001 ' GPIO.0 A/D in, rest digital ADCON0.7 = 1 ' Right justify for 10-bit GPIO = %00000000 ' Initialize outputs TRISIO = %00000001 ' GPIO.0 = input, rest outputs PAUSE 100 Loop: ADCIN 0, number ' (0-1023) IF (number > 0) AND (number < 400) Then GPIO = %00000010 'GPIO.1=1 'GPIO.2=0 'GPIO.4=0 EndIF IF (number > 401) AND (number < 800) Then GPIO = %00000100 'GPIO.1=0 'GPIO.2=1 'GPIO.4=0 EndIF IF (number > 801) AND (number < 1024) Then GPIO = %00010000 'GPIO.1=0 'GPIO.2=0 'GPIO.4=1 EndIF number = 0 GoTo loop
MASTER !
I trully appreciate your prompt answers, thank you very much !!!![]()
Hi
After looking to the examples above I have the following I want to do
As this is my first ADC code I need some tips and maybe some help
I want to do the following
ADC on GPIO.0 8 bit
I have a DC voltage between 0.5V and 2V approx
Which is varying all the time
I need to encode the DC variation by a tone between 67hz and 250hz
with 2-4 hertz incremental/value
The DC values needs to be stored in EEprom at setup
(example button is pushed at powerup to enter setup)
30 DC values should correspond to 30 tones (30 tone's might be set fix in the code)
So example:
0.55V = 67hz
0.64V = 71hz
0.71V = 74hz
etc...
Once setup and running: if a DC value is between or equal next value it has to
output the tone ( set in the code)
with a kind of hysteresis for the tone duration and before next sample)
and a Serout to check the values
Can anyone help me ?
Walter
Bookmarks