I think, 20 samples is enough.
How can I obtain this 20 samples and storage as numbers for calculation?
Thanks Kuba
I think, 20 samples is enough.
How can I obtain this 20 samples and storage as numbers for calculation?
Thanks Kuba
The assumption of 2.45us was based on the fact that Vdd is 5Volts and the source impedance less than 2.5Kohm.
What will be the clock of the your controller?
Ioannis
I will use osc. 20MHz
Kuba
Lets then suppose you have the analog input at AN0.
Now in the array you have 40 samples (two groups of 20) and you can compare them.Code:ADCON0=%00000001 ' Channel 0, ADC on ADCON1=%00001110 ' AN0 as analog,rest as digital ADCON2=%10010101 ' Right justify result and Fosc/16 analog_res_array VAR WORD[40] counter VAR BYTE start_array VAR BYTE ' first element of the array to store samples stop_array VAR BYTE ' last element of the array to store samples start_array=0:stop_array=19 ' first group of 20 samples gosub adc_routine start_array=20:stop_array=39 ' second group of 20 samples gosub adc_routine ...... adc_routine: for counter=start_array to stop_array high adcon0.1 while adcon0.1:wend analog_res_array[counter]=adresh*256+adresl next counter return
Note that code is untested, but you get the idea.
Ioannis
Last edited by Ioannis; - 22nd April 2014 at 17:58.
Thanks for your help.
Kuba
Hi,
I have code for 10 Bit AD converter with array storage four samples.
If I send results from array separately, I see all numbers of array results on LCD, (Example 1.)
But If I send all results from array together, LCD show number 0. (Example 2.)
My question is, what is wrong, how correct this code, how can I send all results from array to LCD?
Thanks
Kuba
Example 1.
Lcdout DEC array[0]," ", Dec array[1]," ", Dec array[2]," ", Dec array[3]
Example 2.
Lcdout DEC array[counter]
This is my code:
Define LCD_DREG PORTB
Define LCD_DBIT 4
Define LCD_RSREG PORTC
Define LCD_RSBIT 4
Define LCD_EREG PORTC
Define LCD_EBIT 5
' Define ADCIN parameters
Define ADC_BITS 10 ' Set number of bits in result
Define ADC_CLOCK 3 ' Set clock source (3=rc)
Define ADC_SAMPLEUS 3 ' Set sampling time in uS
TRISA = %11111111 ' Set PORTA to all input
TRISB = %00000000 ' Set PORTB to all output
TRISC = %00000000 ' Set PORTC to all output
ADCON1 = %10000010 ' Set PORTA analog and right justify result
Pause 500 ' Wait .5 second
array Var Word [4]
counter VAR Byte
Start_array VAR Byte
Stop_array VAR Byte
Start_array =0 : Stop_array = 3
adc_runtime:
for counter = Start_array to Stop_array
ADCIN 0, array[counter] ' Read channel 0 to array[counter]
next counter
Pause 100 ' Wait .1 second
Lcdout $fe, 1 ' Clear LCD
Lcdout DEC array[counter]
Pause 100 ' Wait .1 second
Goto adc_runtime ' Do it forever
End
Use example 1 as example 2 will only display array[4] or you could do something like this
adc_runtime:
Lcdout $fe, 1 ' Clear LCD
for counter = Start_array to Stop_array
ADCIN 0, array[counter] ' Read channel 0 to array[counter]
Lcdout DEC array[counter]," "
next counter
Pause 100 ' Wait .1 second
Try it a see what happens
Steve Earl www.datageo.co.uk
Bookmarks