Hi,
I attached the program and changes made by considering inputs from members. Thank you so much. However, how can I avoid overflow for 12-bit ADC for voltage[value]=(ADC_value[value]/4095)*5?
Regards
FR
Hi,
I attached the program and changes made by considering inputs from members. Thank you so much. However, how can I avoid overflow for 12-bit ADC for voltage[value]=(ADC_value[value]/4095)*5?
Regards
FR
CSS:
#use rs232(baud=9600,UART2)
#include <float.h>
#fuses HS, NOWDT, NOPROTECT, PUT64, BORV27
//correct - Power On Reset Timer value 64ms, Brownout reset at 2.7V
#use delay(clock=20000000) //20 MHz crystal
#use rs232(baud=9600,UART2)
#define LED PIN_B10
//#define VSS_VDD
#define WDT_OFF=0
void main()
{
setup_adc_ports(sAN0 | sAN1 | sAN2 | sAN3 | sAN4 | sAN5 | sAN6 | sAN7 | sAN8 | sAN9 | sAN10 | sAN11 | sAN12 | sAN13 | sAN14 | sAN15, VSS_VDD);
setup_adc(ADC_CLOCK_DIV_64 | ADC_TAD_MUL_2);
setup_adc_ports(ALL_ANALOG);
// Built-in A/D setup function
setup_adc(ADC_CLOCK_INTERNAL);
// Built-in A/D setup function
const int8 channel_1[]=1,2,3,4,5,6,7,8,9,10,11,12,13;
int16 ADC_value1[sizeof(channel_1)];
int16 value;
float voltage[sizeof(channel_1)];
//I/O ports configurations(1:input, 0:output)
set_tris_a(0x0000); //set port_a as output
set_tris_b(0xFFFF); //set port_b as analog input/ADC
set_tris_c(0x0000); //set port_c as output
set_tris_d(0x0000); //set port_d as output
set_tris_f(0x0000); //set port_f as output
set_tris_g(0x0000); //set port_g as output
output_a(0x0000); //clear port_a to all 0s
output_c(0x0000); //clear port_c to all 0s
output_d(0xFFFF); //clear port_d to all 1s-portD dafault at HIGH state
output_f(0x0000); //clear port_f to all 0s
output_g(0x0000); //clear port_g o all 0s
while(TRUE)
{
//pair 16_1
//sample start
//Excitation_pair 16_1 (+I)
output_high(pin_G15);
output_low(pin_A15);
//excitation_pair 16_1 (-I)
output_low(pin_F0);
output_high(pin_G0);
delay_ms(2.5);
//S&H
output_d(0b1100000000000001);
for (value=0;value<sizeof(channel_1);value++)
{
set_adc_channel(channel_1[value]);
ADC_value1[value]=read_adc();
voltage[value] = (ADC_value1[value]/4095.0) * 5.0;
}
for(value=0;value<sizeof(channel_1); value++)
{
printf("%4.3f\r\n", voltage[value]);
}
printf("9.999\r\n");
}
}