thanks Darrel,
I have put this code in for the AN4 sensor only , however it seems i will have to do this for other A/D services for this rev of chip ????
your DT_INTS-14.bas is included as part of this code for timer0 , and the variable GIE was already in use ,
timer0 setup as 8ms timer , and this A/D routine is called from it after incrementing counters of timer0 = 5sec duration to do a read of the Voltage level
couple of questions
1. Is the duration of the sample time of 20us seemed long for 1 A/D channel ? as the spec sheet for conversion using FRC is about 1.6us average - a max period of 6uS
2. i thought the sleep instruction ( low power mode ) may need to be issued prior to the conversion starting , or are all commands after a sleep command not actioned till sleep mode is terminated ?
3. as this now monitors the interrupt for sleep to finish , then the duration of this routine must be shorter than any other generated interrupts using DT_INT14 else this will not work ??
the code as it stands now
waiting on a Battery power duration test to complete to see if this works ok
Cheers
Sheldon
Code:
Get_volts :
ADON VAR ADCON0.0 ; A/D converter Enable
GoDone VAR ADCON0.1 ; A/D conversion in progress
ADIE VAR PIE1.6 ; A/D Interrupt Enable
ADIF VAR PIR1.6 ; A/D Interrupt Flag
GIEsave VAR BIT ; Saves state of GIE
ADCON0 = %00010001 ' enable ADC AN4 ,( ADCON1 setup at start of program , Right Justify, FRC clock )
y = 0 ' ensure 0
While Y < 10 ' do 10 voltage reads
' silicon bug in rev2 of 16F1947 , requires ADC to be done in lowpower mode and with FDC osc clock internal
' also ADCIN command wont work in sleep mode , interupts exit sleep mode
PAUSEUS 20 ; Acquisition time
GIEsave = GIE ; Save state of Global Interrupts ( GIE defined in DT_INTS-14.bas )
GIE = 0 ; Disable Global interrupts
ADON = 0 ; reset A/D module
ADON = 1 ; turn on A/D module
ADIF = 0 ; Clear Analog Interrupt Flag
ADIE = 1 ; Enable Analog Interrupt
GoDone = 1 ; Start Analog conversion
@ SLEEP ; go to SLEEP
ADIE = 0 ; Disable Analog Interrupt
GIE = GIEsave ; Restore Global Interrupt state ( GIE defined in DT_INTS-14.bas )
value.HighByte = ADRESH ; Get A/D result
value.LowByte = ADRESL
' ADCIN 4 ,Value ' Leave out for Rev 2 of 16F1947 - Read PortA.5 value into variable , this applies the fixed voltage ref (via ADCON0,ADCON1,FVRCON)
gosub Average ' Go do running average of ADC reading
y = y+1 ' Increment loop counter
wend
Bookmarks