Hi,
I made a simple 12 bit ADC using LTC1298 in SPI with 16f887 and works perfect. I tried the same setup same pins with a 18F4550 but won't work.
the 16F887 code is:
Code:
'==========================MCU SETUP============================================
DEFINE OSC 20
Include "modedefs.bas"
CM1CON0 = 0
CM2CON0 = 0
ANSEL = 0 ' set ANx as analog
ANSELH = 0
'============================I/O SETUP==========================================
TRISA = %11111111
TRISB = %00000001
TRISC = %00010000
TRISD = 0
TRISE = 0
SDI VAR PORTC.4
SCL VAR PORTC.6
CS VAR PORTC.7
SDO VAR PORTC.5
pot_v var word ' Current Pot Value
SLCD VAR PORTD.7
'===============================VARIABLES======================================
MUX1 var bit
MUX2 var bit
MUX3 var bit
MUX4 var bit
null var bit
dummy var word
ADCVAL VAR WORD
I VAR WORD'Numbe of samples taken
'================================usuart========================================9+
CLEAR
'=============================================================================
adcval=0
mux1=1:mux2=1:mux3=0:mux4=1
PAUSE 500
loop:
LCDOUT $FE,1
PAUSE 50
LCDOUT "PRO POT TESTER V1.0 "
gosub adc
MAIN:
gosub adc
lcdout $fe,$D4
LCDOUT "P VAL",DEC POT_V," ","I",DEC I," "
GOTO MAIN
'====================READ ADC===================================================
ADC:
CS=0
SHIFTOUT SDO,SCL,5,[MUX1\1]
SHIFTOUT SDO,SCL,5,[MUX2\1]
SHIFTOUT SDO,SCL,5,[MUX3\1]
SHIFTOUT SDO,SCL,5,[MUX4\1]
SHIFTin SDI,SCL,6,[null\1]
SHIFTin SDI,SCL,6,[adcval\12]
cs=1
dummy = adcval*2442
pot_v = div32 1000
I=I+1
RETURN
'===============================================================================
END
the above code works good with the 16F887 then I tried this which is the same with the 18F4550:
Code:
'===========================CONFIGURATION=======================================
'CONFIG FOSC = HSPLL_HS, PLLDIV = 5 , CPUDIV = OSC1_PLL2
'CONFIG FCMEN = ON , PWRT = OFF, BOR = ON, VREGEN = ON , WDT = OFF,PBADEN = OFF
'CONFIG CCP2MX = OFF, LPT1OSC = OFF , LVP=OFF, ICPRT = OFF,STVREN = OFF
'==========================MCU SETUP============================================
DEFINE OSC 48
Include "modedefs.bas"
TRISA = %11111111
TRISB = %00000001
TRISC = %00010000
TRISD = 0
TRISE = 0
ADCON1=15
PORTD=0
PORTE=0
PORTC=0
'===============================================================================
'==============================BAUD SETUP=======================================
N38 CON 16390'38.4K RS232 BAUD RATE FOR SERIAL COMMUNICATION WITH LCD
'==========================I/O SETUP============================================
SLCD var PORTD.7'SERIAL OUTPUT TO THE LCD:PIN#25
START VAR PORTA.2'START BUTTON:PIN#
SDI VAR PORTC.4
SCL VAR PORTC.6
CS VAR PORTC.7
SDO VAR PORTC.5
'===============================================================================
'===================================VARIABLES===================================
pot_v var word ' Current Pot Value
ADCVAL VAR WORD'ADC VALUE
MAXVALUE VAR WORD' POT MAX VALUE-POT FIXED VALUE
MINVALUE VAR WORD' POT FIXED VALUE-POT MIN VALUE
MUX1 var bit'ADC SETUP BIT1
MUX2 var bit'ADC SETUP BIT2
MUX3 var bit'ADC SETUP BIT3
MUX4 var bit'ADC SETUP BIT4
null var bit'ADC NULL BIT
dummy var word'DUMMMMMMMMMY VARIABLE USED FOR CALCULATIONS
fixed_V VAR WORD 'Start up Pot Value
PMIN VAR WORD 'POT MIN VALUE
PMAX VAR WORD'POT MAX VALUE
I VAR WORD'Number of samples taken
CLEAR
'==============================================================================
PAUSE 1000
SEROUT2 SLCD,N38,[$FE,$58]'CLEAR DISPLAY
PAUSE 10
'===============================================================================
adcval=0 :
mux1=1:mux2=1:mux3=0:mux4=1
PAUSE 500
loop:
SEROUT2 SLCD,N38,[$FE,$47,1,1,"PRO POT TESTER V1.0"]'DISPLAY CHARACTHERS
MAIN:
gosub adc
SEROUT2 SLCD,N38,[$FE,$47,1,4,"P VAL:",DEC POT_V,"/I:",DEC I," "]
GOTO MAIN
'====================READ ADC===================================================
ADC:
CS=0
SHIFTOUT SDO,SCL,5,[MUX1\1]
SHIFTOUT SDO,SCL,5,[MUX2\1]
SHIFTOUT SDO,SCL,5,[MUX3\1]
SHIFTOUT SDO,SCL,5,[MUX4\1]
SHIFTin SDI,SCL,6,[null\1]
SHIFTin SDI,SCL,6,[adcval\12]
cs=1
dummy = adcval*2442
pot_v = div32 1000
I=I+1
RETURN
'===============================================================================
END
but I'm not reading the ADC in the 18F4550. The only difference is the serial LCD but I tried with both but no luck. I guess is something to do with : DEFINE SHIFT_PAUSEUS 100 if so what the value supposed to be?
in advance thanks for any help you can provide.
Best regards,
Joe
Bookmarks