Hello,
First I want to say that this is a nice forum finding solutions for PBP.
Here is my queston about an Analog to digital conversion.
I want to put an conversion in the variable word_temp_int, but this ain't seem to work. Every result of the AD conversion is 0.
Using a PIC16F870.
This code is in my interrupt routine, the routine is 500 ms. The varaiable word_wachttijd_aantal is decreased with every interrupt.
Code:
if (word_wachttijd_aantal == 12) and (byte_status == 1) then
adcon0.0 = 1 ' AD converter on
endif
if (word_wachttijd_aantal == 11) and (byte_status == 1) then
word_pot_adc = 0 ' reset value potmeter
adcon0.2 = 1 ' start AD conversion
endif
if (word_wachttijd_aantal < 11) and (byte_status == 1) then
if adcon0.2 == 0 then ' test AD conversion ready
word_temp_int.highbyte = ADRESH ' store AD value
word_temp_int.lowbyte = ADRESL ' store AD value
word_pot_adc = word_pot_adc * 9 ' some calculations
word_pot_adc = word_pot_adc + word_temp_int
word_pot_adc = word_pot_adc / 10
endif
adcon0.2 = 1 ' start new AD conversion
endif
The AD converter is put on when word_wachttijd_aantal is equal to 12.
500 ms later the AD converter is started when word_wachttijd_aantal is equal to 11.
500 ms later the AD converter is stored in word_pot_adc because word_wachttijd_aantal is less than 11 and adscon0.2 is equal to 0 a long time ago.
After the AD value is stored in word_pot_adc a new AD conversion is started.
If I put de code untherneath here at the same place it works fine.
Code:
test:
adcon0.0 = 1 ' AD converter on
pause 500 ' wait 500ms is
adcon0.2 = 1 ' start AD conversion
ADC:
pause 5 ' wait 5ms aquisition time
if adcon0.2 = 1 Then ADC ' test if AD conversie is ready
word_pot_adc.highbyte = ADRESH ' store AD value
word_pot_adc.lowbyte = ADRESL
adcon0.0 = 0 ' AD converter off
goto test
Bookmarks