#include<ADuC845.h>
#include<stdio.h>
#include<math.h>
unsigned int ADC_array[400], ADC_array_aux[400];
float frekans, frekans_aux;
float Vref = 5.145, Vref_aux = 5.025;
int i, j, k, V;
int zero_indexes[50], zero_indexes_aux[50];
sbit LED = 0x0B4;
double rms, rms_aux;
int ilk_sifir_gecis, son_sifir_gecis;
void serial_init()
{
T3CON = 0x81; // timer 3
T3FD = 0x12; // 38400 baud
SCON = 0x52; // T3CON=81 (38400baud), T3CON=82 (19200baud),
T3CON=83 (9600baud)
}
void ADC_init()
{
ADC0CON1 = 0x87; // Buffer Bypass, Bipolar, +-2.56V
SF = 0x03; // ADC rate = 1365.33Hz
ADC0CON2 = 0x40; // Refin+/-, Ain1-Aincom
printf("%3.3f V\n",ADC0CON2);
ADC1CON = 0x41; // Refin+/-, Bipolar, Ain2-Aincom (AUXILIARY ADC)
printf("***************************\n");
printf("\nADCs calibration START\n");
ADCMODE = 0x74; // Offset calibration
ADCMODE = 0x75; // Gain calibration
printf("ADCs calibration OK\n");
printf("***************************\n");
ADCMODE = 0x3B; // Continuous conv, Chopping DISABLE, Notch DISABLE, Primary ADC, Auxiliary ADC
}
unsigned int ADC_read()
{
unsigned int ADC = 0;
while(! RDY0){} // Wait for RDY0 = 1
ADC = ADC0H*0x10000+ADC0M*0x100+ADC0L; // ADC data
RDY0 = 0; // clear ready bit
return ADC;
}
unsigned int Aux_ADC_read()
{
unsigned int ADC = 0;
while(! RDY1){} // Wait for RDY0 = 1
ADC = ADC1H*0x100+ADC1M; // ADC data
RDY1 = 0; // clear ready bit
return ADC;
}
void main (void)
{
serial_init(); // Configure serial port for 38400 Baud
ADC_init(); // Configure ADC
while(1) {
ADCMODE = 0x3B; // Continuous conv, Chopping DISABLE, Notch DISABLE, Primary ADC, Auxiliary ADC
for(i=1;i<400;i++)
{
ADC_array[i] = ADC_read();
ADC_array_aux[i] = Aux_ADC_read();
}
/**** Sending received data to terminal ****/
for(i=1;i<400;i++)
{
printf("%X %X\n",ADC_array[i], ADC_array_aux[i]);
V = ((5.0/65536)*ADC_array[i])-2.5;
printf("%3.3f V\n",V);
}
/****** Finding Zero Transitions and Frequency ******/
j = 0; k = 0;
for(i=1;i<51;i++)
zero_indexes[i] = 0;
zero_indexes_aux[i] = 0;
for(i=1;i<400;i++)
{
if((ADC_array[i]<0x8000 && ADC_array[i+1]>0x8000) || (ADC_array[i]>0x8000 && ADC_array[i+1]<0x8000))
{
j++;
zero_indexes[j] = i;
}
if((ADC_array_aux[i]<0x8000 && ADC_array_aux[i+1]>0x8000) || (ADC_array_aux[i]>0x8000 && ADC_array_aux[i+1]<0x8000))
{
k++;
zero_indexes_aux[k] = i;
}
}
frekans = (1365.33/2)*((j-1.0)/(zero_indexes[j]-zero_indexes[1]));
frekans_aux = (1365.33/2)*((k-1.0)/(zero_indexes_aux[k]-zero_indexes_aux[1]));
/*******************************************************/
/*************** Finding RMS Values ***************/
rms = 0;
ilk_sifir_gecis = zero_indexes[1];
son_sifir_gecis = zero_indexes[j];
for(i=ilk_sifir_gecis;i<son_sifir_gecis+1;i++)
rms = rms + pow((((Vref/65536)*ADC_array[i])-(Vref/2)),2);
rms = sqrt(rms/(son_sifir_gecis - ilk_sifir_gecis + 1));
rms_aux = 0;
ilk_sifir_gecis = zero_indexes_aux[1];
son_sifir_gecis = zero_indexes_aux[k];
for(i=ilk_sifir_gecis;i<son_sifir_gecis+1;i++)
rms_aux = rms_aux + pow((((Vref_aux/65536)*ADC_array_aux[i])-(Vref_aux/2)),2);
rms_aux = sqrt(rms_aux/(son_sifir_gecis - ilk_sifir_gecis + 1));
/*******************************************************/
/******** Bulunan değerlerin Terminale basılması *******/
printf("\nVRMS = %2.4f V VRMS_aux = %2.4f V Ratio Error (%%) = %2.3f\nFrekans = %2.1f Hz Frekans_aux = %2.1f Hz\n",rms,rms_aux,100*(rms_aux-rms)/rms,frekans,frekans_aux);
LED ^= 1;
/*******************************************************/
}
}
Tengo una placa de evaluación ADuc845 y no vi ningún valor de entrada en el terminal. ¿Puede alguien ayudarme?