rereading the methods to get around the problem option 1 actully looks the best way , but i am not sure how to do this
but it appears that by setting the ADC f/OSC conversion clock to the FRC internal , then putting the CPU into low power mode ( SLEEP mode ) , then doing a sample , then exit low power mode (SLEEP mode) by using the watchdog timer ( no other way i can see to make sleep mode exit)
i am guessing this may work but not sure ,
1. set up watchdog timer to be enabled by software bit ( _WDTE_SWDTEN ) ;WDT controlled by the SWDTEN bit in the WDTCON register) in config1 word
2. set WDTCON with 1ms timeout and enable watchdog timer lowest time
3. do asm command of sleep - to enter low power mode ( NAP 0 = too long a time about 18ms)
4. do adcin command which should complete a sample in 1.6uS
5.turn off watchdog timer
so the assumption is that the adcin command will work in low power mode and sample will complete in a max of 1ms
test to see !!!!!!!!!!!!
but anyone else can advise then please do
Cheers sheldon
item 1
Code:
' config for 16F1947
#CONFIG
;----- CONFIG1 Options --------------------------------------------------
__config _CONFIG1, _FOSC_INTOSC & _WDTE_SWDTEN & _PWRTE_ON & _MCLRE_ON & _CP_OFF & _CPD_OFF & _BOREN_OFF & _CLKOUTEN_OFF & _IESO_OFF & _FCMEN_OFF
;----- CONFIG2 Options --------------------------------------------------
__config _CONFIG2, _LVP_OFF & _BORV_HI & _STVREN_ON & _PLLEN_ON & _WRT_OFF & _VCAPEN_OFF
#ENDCONFIG
item 2 - 5
Code:
ADCON0 = %00010001 ' enable ADC AN4 , ADCON1 setup at start of program
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
WDTCON = %00000001 ' start watchdog timer set for 1ms so that sleep mode is exit after doing adcin commands
asm
SLEEP ;'Put cpu into low power mode
endasm
ADCIN 4 ,Value ' Read PortA.5 value into variable , this applies the fixed voltage ref (via ADCON0,ADCON1,FVRCON)
WDTCON = %00000000 ' stop watchdog timer after adcin commands
gosub Average ' Go do running average of ADC reading
y = y+1 ' Increment loop counter
wend
Bookmarks