SOLVED: Noisy VDD/VSS using DC-DC converter. ADC stopped bouncing after using a 7805.
https://picbasic.co.uk/forum/showthr...527#post156527
--------------------------------------------------------------------
16F18877
- Using fixed input on ADC pin (1K to VDD, 1K to VSS - simulating pot at 50%)
- The ADC will drift from 498 to 509.
HSEROUTs on Serial Communicator:
Is there anything in the registers that I can "tune" for the ADC?
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 CCP1_REG 0 ' Must clear unused CCP pins or else unpredictable results
DEFINE CCP1_BIT 0
define CCP2_REG 0
DEFINE CCP2_BIT 0
DEFINE CCP3_REG 0
DEFINE CCP3_BIT 0
define CCP4_REG 0
DEFINE CCP4_BIT 0
define CCP5_REG 0 ' Must clear unused CCP pins or else unpredictable results
DEFINE CCP5_BIT 0
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
BAUDCON.3 = 1 ' Enable 16 bit baudrate generator
RA4PPS = 0 ' Disable CCP5
RB0PPS = 0 ' Disable CCP4
RB5PPS = 0 ' Disable CCP3
RC1PPS = 0 ' Disable CCP2
RC2PPS = 0 ' Disable CCP1
IOCAP = %00000000 'IOC Positive Edge, low-to-high
IOCAN = %00000000 'IOC Negative Edge, from high-to-low
IOCBP = %00000000 'IOC Positive Edge, low-to-high
IOCBN = %00000000 'IOC Negative Edge, from high-to-low
IOCCP = %00000000 'IOC Positive Edge, low-to-high
IOCCN = %00000000 'IOC Negative Edge, from high-to-low
'IOCDP = %00000000 '...not available
'IOCDN = %00000000 '...not available
'IOCEP = %00000000 '...not available
'IOCEN = %00000000 '...not available
WPUA = %00000000 ' Pull-up resistors
WPUB = %00000000
WPUC = %00000000
WPUD = %00000000
WPUE = %00000000
INLVLA = %00000000 ' TTL input level
INLVLB = %00000000
INLVLC = %00000000
INLVLD = %00000000
'INLVLE = %00000000 ' ...only available on E3 / MCLR pin
ADCON0 = %10000100 ' ADC CONTROL REGISTER 0
ADCLK = %00111111 ' ADC CLOCK SELECTION REGISTER
'ADPCH = %00011010 ' Channel 26 - D2
ANSELA = %00000000
ANSELB = %00000000
ANSELC = %00000000
ANSELD = %00000110 ' Pin D2 = ADC input, NavCom
' Pin D1 = ADC input, Glareshield
ANSELE = %00000000
TRISA = %00000000
TRISB = %00000000
TRISC = %00000000
TRISD = %00000110
TRISE = %00000000
include "I:\Project_v2\PBP\PBP_Includes\USART.bas"
ADCInput var word
LowADC var word
HighADC var word
Pause 1 ' Let PIC stabilize
LowADC = 1023
HighADC = 0
AdcInput = 0
Mainloop:
adcin 26, AdcInput
if AdcInput < LowADC then LowADc = AdcInput
if AdcInput > HighADC then HighADC = AdcInput
hserout [ "Low=", dec5 LowADC, " High=", DEC5 HighADC, 10 ]
goto mainloop
end
I was getting desperate with the drift on the pots, so I thought I'd do a control run using resistors.
I expected it to remain the same or very close, but I'm still getting drift.
Bookmarks