Hi all.
I have done A/d to with success with 16f877 and16f887 now I have a problem with 18f4550 the value is fluctuating so much even in the high rail I still get values between 1023 and 1018 and in the low rail some times go up to 8. I think it's a TAD problem but I let you guys help me out.
Here is the code(nothing fancy just read and display):
Code:==========================MCU SETUP============================================ DEFINE OSC 48 Include "modedefs.bas" '***************************LCD DEFINE******************************* DEFINE LCD_DREG PORTD 'LCD data port DEFINE LCD_DBIT 0 'LCD data starting bit 0 or 4 DEFINE LCD_RSREG PORTD 'LCD register select port DEFINE LCD_RSBIT 5 'LCD register select bit , RS=PORTE.2 DEFINE LCD_EREG PORTD 'LCD enable port DEFINE LCD_EBIT 7 'LCD enable bit E=portE.0 DEFINE LCD_RWREG PORTD 'LCD read/write port DEFINE LCD_RWBIT 6 'LCD read/write bit R/W=POTRD.1 DEFINE LCD_BITS 4 'LCD bus size 4 or 8 DEFINE LCD_LINES 4 'Number lines on LCD DEFINE LCD_COMMANDUS 2000 'Command delay time in us DEFINE LCD_DATAUS 50 '****************************************************************** DEFINE ADC_BITS 10 ' ADCIN resolution (Bits) DEFINE ADC_CLOCK 3 ' Work around that sets Vref bits in ADCON1 DEFINE ADC_SAMPLEUS 50 ' ADC sampling time (uSec) '==========================I/O SETUP============================================ TRISD=0 TRISE=0 TRISC=%10000000 TRISA=%11111111 TRISB=0 ADCON1=14 ADCON2=%10000000 '================================variables====================================== adcval var word TX VAR PORTC.6 RX VAR PORTC.7 '==============================BAUD SETUP======================================= N96 con 16416 ' Inverted 19200 baud for the lcd rs232 T192 con 32 '19200 TTL T96 CON 84'9600 TTL T38 CON 6'38K '==========================I/O SETUP============================================ '======================LCD LINES SETUP========================================== L1 CON 1 'LINE1 L2 CON $C0'LINE2 L3 CON $94'LINE3 L4 CON $D4'LINE4 CLEAR '============================================================================= PAUSE 500 loop: LCDOUT $FE,l1 PAUSE 50 LCDOUT "a/d test" MAIN: gosub adc0 lcdout $fe,l2 lcdout "pot:" ,dec adcval," " pause 600 GOTO MAIN '=================================ADC0========================================== ADC0: ADCin 0, adcval pause 50 RETURN '============================================================================== END
can you please help have a 0.1uf between the input and ground of AN0 the power supply is solid do not change.
ground wire from PS to MCU and to analog input.
anything I'm missing.
tried to change
DEFINE ADC_CLOCK 3 to 0 then 2 then 6 with no help.
Bookmarks