
Originally Posted by
richard
- did not touch VREFs,
What do you mean by this , you have changes pos vref to fvr buffer1- used FVR 4x with 5 VDC in,
which will turn out to be a mistake since pots use vdd as top input , by doing this you have lost 20% of their travel range...
I meant, did not touch VREF-, sorry.
If I use VREF+ = VDD, my ADC readings stop at 1000 or so.
If I use VREF+ = FVRx4, my readings reach 1023.
Weird.
...
- used FOSC / 128,way too slow , while not out of acceptable range fosc/32 is more reasonable
...
I've switched to 32 as well.
...used average of 16 ADC readings,
not sure about that , its not necessary either if every thing else is ok ...
If I don't use averages, I jump all over like this:
Code:
OldADC1:00847 ADCin:00844 Diff:00003
OldADC1:00844 ADCin:00847 Diff:00003
OldADC1:00847 ADCin:00844 Diff:00003
OldADC1:00844 ADCin:00848 Diff:00004
OldADC1:00848 ADCin:00845 Diff:00003
OldADC1:00845 ADCin:00848 Diff:00003
OldADC1:00848 ADCin:00844 Diff:00004
...
- used USART to show results
- added PAUSEUS 1 after all ADC operations - THIS NEEDS TO BE VERIFIED IF IT'S NECESSARY, it was just to make sure things worked.
it does nothing useful ...
I removed them.
...my schema , added another supply rail straddling 10k pot , without series wiper resistor to an2
not no none nil caps across an inputs
typical raw readings
Code:
R 827 669
R 826 669
R 826 669
R 826 668
R 825 669
R 827 669
R 826 669
R 826 669
R 826 668
R 825 668
R 827 670
R 826 669
R 825 668
R 827 669
R 827 669
Envious emote...
...
DEFINE ADC_BITS 10 ' 10-bit Analog to digital
DEFINE ADC_SAMPLEUS 5 ' Set sampling time in uS...
Reduced mine from 50 down to 5 as well
I just noticed that my temps on the 16F18855 goes over 100c when ADC runs; that's insane. I have no other routines running. If I stop ADC, it comes back down to 30ies.

I took everything non-essential off the breadboard (just kept my 2 power LEDs):

Code:
#CONFIG
__config _CONFIG1, _FEXTOSC_OFF & _RSTOSC_HFINT32 & _CLKOUTEN_OFF & _CSWEN_OFF & _FCMEN_ON
__config _CONFIG2, _MCLRE_ON & _PWRTE_OFF & _LPBOREN_OFF & _BOREN_ON & _BORV_LO & _ZCD_OFF & _PPS1WAY_OFF & _STVREN_ON & _DEBUG_OFF
__config _CONFIG3, _WDTCPS_WDTCPS_11 & _WDTE_OFF & _WDTCWS_WDTCWS_7 & _WDTCCS_LFINTOSC
__config _CONFIG4, _WRT_OFF & _SCANE_available & _LVP_OFF
__config _CONFIG5, _CP_OFF & _CPD_OFF
#ENDCONFIG
DEFINE OSC 32
DEFINE ADC_BITS 10 ' 10-bit Analog to digital
DEFINE ADC_SAMPLEUS 5 ' Set sampling time in uS
DEFINE HSER_RXREG PORTC
DEFINE HSER_RXBIT 7
DEFINE HSER_TXREG PORTC
DEFINE HSER_TXBIT 6
DEFINE HSER_RCSTA 90h ' Enable serial port & continuous receive
DEFINE HSER_TXSTA 24h ' Enable transmit, BRGH = 1
Define HSER_BAUD 115200
DEFINE HSER_CLROERR 1 ' Clear overflow automatically
DEFINE HSER_SPBRGH 0
DEFINE HSER_SPBRG 68
;--- Setup registers -----------------------------------------------------------
BAUDCON.3 = 1 ' Enable 16 bit baudrate generator
FVRCON = %10000011 ' FIXED VOLTAGE REFERENCE CONTROL REGISTER
' bit 7 FVREN: Fixed Voltage Reference Enable bit
' 1 = Fixed Voltage Reference is enabled
' bit 1-0 ADFVR<1:0>: ADC FVR Buffer Gain Selection bit
' 11 = ADC FVR Buffer Gain is 4x, (4.096V)(2)
'ADCON0 = %10000100 ' ADC CONTROL REGISTER 0
' bit 7 ADON: ADC Enable bit
' 0 = ADC is disabled
' 1 = ADC is enabled
' bit 2 ADFRM0: ADC results Format/alignment Selection
' 1 = ADRES and ADPREV data are right-justified
' 0 = ADRES and ADPREV data are left-justified, zero-filled
ADCLK = %00001111 ' ADC CLOCK SELECTION REGISTER
' bit 5-0 ADCCS<5:0>: ADC Conversion Clock Select bits
' 001111 = FOSC/32
ADREF = %00000011 ' ADC REFERENCE SELECTION REGISTER
' bit 4 ADNREF: ADC Negative Voltage Reference Selection bit
' 0 = VREF- is connected to AVSS
' bit 1-0 ADPREF: ADC Positive Voltage Reference Selection bits
' 11 = VREF+ is connected to FVR_buffer 1
' 00 = VREF+ is connected to VDD
ANSELA = %00000010 ' Pin A1 = ADC (B5K)
ANSELB = %00000000
ANSELC = %00000000
TRISA = %00000010 ' Pin A1 = ADC input 1
TRISB = %00000000 ' Pin B7 = ...not available, ICSPDAT
' Pin B6 = ...not available, ICSPCLK
TRISC = %11000000 ' Pin C7 = RX *** Datasheet requirement, INPUT ***
' Pin C6 = TX *** Datasheet requirement, INPUT ***
ADCinput var WORD
ADCdiff var WORD
OldADC1 var WORD
Pause 500 ' Let PIC and LCD stabilize
ADCinput = 0
ADCdiff = 0
OldADC1 = 9999
Mainloop:
rem ADC1, B5K pot
adcin 1, ADCinput
ADCinput = ADCinput >> 6 ' tried left justified for fun
if ADCinput < oldADC1 then ' Calculate change in ADC
ADCdiff = oldadc1 - ADCinput
else
ADCdiff = ADCinput - oldadc1
endif
IF ADCdiff > 2 then ' Check for Diff over 2
hserout [ "OldADC1:", DEC5 oldadc1, " ", _
"ADCin:", DEC5 ADCinput, " ", _
"Diff:", DEC5 ADCdiff, 10]
while TXSTA.1 = 0 ' Check TRMT bit
wend
oldADC1 = ADCinput
else
if ADCinput <> oldadc1 then ' ADC value diff than previous
if ADCinput = 0 then ' Reached end of rotation
hserout [ "OldADC1:", DEC5 oldadc1, " ", _
"ADCin:", DEC5 ADCinput, " ", _
"Diff:", DEC5 ADCdiff, " ", 10]
while TXSTA.1 = 0 ' Check TRMT bit
wend
oldADC1 = ADCinput
else
if ADCinput = 1023 then ' Reached start of rotation
hserout [ "OldADC1:", DEC5 oldadc1, " ", _
"ADCin:", DEC5 ADCinput, " ", _
"Diff:", DEC5 ADCdiff, 10]
while TXSTA.1 = 0 ' Check TRMT bit
wend
oldADC1 = ADCinput
endif
endif
endif
endif
GOTO Mainloop
end
I know I can join those Ifs to check for end of rotation, I just wanted to keep code simple to make sure everything was getting picked up.
Averages was why sometimes it would not reach 0 or 1023.
It works, but it has jumps of 3 now. Gonna see if more caps can reduce that.
No clue why ADC is running so hot, specs say 85c is normal operating temp.
The mounting holes are "slightly" warm, never noticed that before.
Bookmarks