hemnath
Advanced Member level 3
Hardware Connections:
18LF2520 --------- LTC2410
PIN C4 ---------- SDO
PIN C3 --------- SCK
PIN C1 --------- CS
test code:
When i run this code, I get the output of 709931 in the display. When the change the input voltage at LTC2410, the display value is not changing.
Please help
18LF2520 --------- LTC2410
PIN C4 ---------- SDO
PIN C3 --------- SCK
PIN C1 --------- CS
test code:
Code:
#include "18F2520.h"
#fuses INTRC, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP // Internal oscillator
#use delay(clock=1000000) // 1Mhz
#define A2D_CSI PIN_C1
#define A2D_SCLK PIN_C3
#define A2D_SDO PIN_C4
int32 Read_A2D(void)
{
int32 A2D_COUNTS;
int i;
output_high(A2D_SCLK);
delay_us(100);
output_high(A2D_CSI);
output_low(A2D_SCLK);
output_low(A2D_CSI);
while((input(A2D_SDO))==1); //wait for /EOC to go low...
for(i=4;i>0;i--) //I don't need to use these first 4 bits
{
output_high(A2D_SCLK);
delay_us(5);
output_low(A2D_SCLK);
delay_us(5);
}
for(i=20;i>0;i--) //Set i = number of bits to read
{
output_high(A2D_SCLK);
delay_us(5);
shift_left(&A2D_COUNTS,4,input(A2D_SDO));
output_low(A2D_SCLK);
delay_us(5);
}
output_high(A2D_CSI);
return A2D_COUNTS;
}
void main()
{
int32 A2D_value;
setup_adc_ports(NO_ANALOGS|VSS_VDD); // No analogs
setup_adc(ADC_OFF|ADC_TAD_MUL_0);
setup_comparator (NC_NC_NC_NC); // Disable comparator
while(1)
{
A2D_value = Read_A2D();
delay_ms(200);
// display the adc value on lcd
}
}
When i run this code, I get the output of 709931 in the display. When the change the input voltage at LTC2410, the display value is not changing.
Please help