#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");
}
}
int32 newVar;
newVar=ADC_value1[value];
newVar*=5000;
newVar/=4096; //note not 4095
voltage[value] = newVar; //voltage = 0 to 5000 I.E. mV
#include <18F4580.h>
#device ADC=8
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=20000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)
#define button (PIN_B0)
void main()
{
setup_adc_ports(ALL_ANALOG);
setup_adc(ADC_CLOCK_DIV_64 | ADC_TAD_MUL_8);
set_TRIS_B(0x0F);
const int8 channel_1[] = 0,1,2,3,4,5,6,7;
int start;
int16 ADC_value1[sizeof(channel_1)];
//int16 ADC_value[sizeof(channel_1)];
int32 value1;
int32 voltage[sizeof(channel_1)];
SETUP_ADC_PORTS(ALL_ANALOG);
//while(TRUE)
for(start=0; start<=2;start++)// acquire 8 measurements in 10 ONLY
{
LOOP1:
if(input_state(PIN_B2) ==0)//if not pres==0, LED ON/OFF 0.5sec
{
delay_ms(100);
output_b(00000000);
delay_ms(100);
output_b(11000000);
goto LOOP1;
//break;
}
else // if pressed (HIGH) start acquisition
{
// Collect ADC_DATA IN CHANNEL_1
for(value1 = 0; value1 < sizeof(channel_1); value1++)
// Read from 8 adc channels
{
set_adc_channel(channel_1[value1]);
ADC_value1[value1] = read_adc(); // ADC readings
delay_ms(500);
voltage[value1] = ADC_value1[value1] * (5 / 4096);
// Convert ADC data to mV
}
// Print all ADC data
for(value1 = 0; value1 < sizeof(channel_1); value1++)
// Display 8 voltage values
{
printf("%4.3w\r\n", voltage[value1]);
}
printf("9.999\r\n");
}
}
}
#include <30F6014A.h>
#include <float.h>
#include <string.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
#use rs232(baud=9600,UART2)
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;
int16 voltage;
int32 newVar;
newVar=(int32)ADC_value1[value];
newVar*=5000;
newVar/=4096; //note not 4095
voltage[value] = (int16) newVar; //voltage = 0 to 5000 I.E. mV
//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)
{
//read from chnnel 0, 0++ (1,2,3...13)
for (value=0;value<sizeof(channel_1);value++)
{
set_adc_channel(channel_1[value]);
ADC_value1[value]=read_adc();
voltage[value] = (ADC_value1[value]*5000/4096);
}
//display value from channels 0...7
for (value=0;value<sizeof(channel_1);value++)
{
//printf("%4.3f",voltage[value]);
printf("%4.3f\r\n",voltage[value]);
}
//printf("9.999");
printf("9.999\r\n");
}
}
In the time being I tried to try to read dc voltage 4.788V from multichannel ADCs but only channel AN0 seems working, others it display -16.000 Why is this happening? Does the dspic require delay to read from other ADCs?
A 10uS delay is advised as being safe, you may be able to use less if you check the device data sheet.
As long as you've got a nice low source impedance 10uS is probably fine, but you need considerably longer delays if your source impedance is higher - usually 2K is the maximum suggested source impedance for most PIC's.
#include <30F6014A.h>
#device ADC=12
#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,ERRORS)
void main()
{
SETUP_ADC(adc_OFF);
setup_adc_ports(sAN0 | sAN1 | sAN2 , VSS_VDD);
setup_adc(ADC_CLOCK_DIV_64 | ADC_TAD_MUL_2);
setup_adc(ADC_CLOCK_INTERNAL);
// Built-in A/D setup function
setup_adc_ports(ALL_ANALOG);
// Build-in A/D setup function
signed int32 ert_adc_value_0;
signed int32 ert_voltages_0;
while(true)
{
//sample at Channel_0
set_adc_channel(0); //read from channel 0
delay_us(10); //delay is required after setting channel and bef.read
ert_adc_value_0=read_adc(); //starts conversion & stored
ert_voltages_0=(ert_adc_value_0)*5000/4096;// last result of last conversion
printf("Ch0=%u\r\n",ert_voltages_0);
}
}
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?