1
0
mirror of git://projects.qi-hardware.com/nn-usb-fpga.git synced 2025-01-10 14:50:14 +02:00
nn-usb-fpga/Examples/ADC/QT_src/ADCw.cpp

75 lines
2.7 KiB
C++
Raw Normal View History

2010-04-05 22:06:50 +03:00
#include "ADCw.h"
ADCw::ADCw()
{
ADCBuffer = jz_adc_init();
/*************************Clean FPGA RAM memory****************************/
for (int i = 0; i < 512; i++) //RAMB16_s9_s9 has 2048 bytes 8-bit
{
ADCBuffer[i] = 0x00000000; //Clean 4 register by cicle
}
}
void ADCw::testADC()
{
/****************Configure ADC register on FPGA RAM memory*****************/
jz_adc_config(ADCBuffer, 0x01, ADC_SPI_CLKDIV_MAX, ADC_CMD_SET_SPI_CLKDIV);
usleep (1000);
jz_adc_config(ADCBuffer, 0x01, ADC_SPI_CLKDIV_MAX, ADC_CMD_SET_FAST_CONV);
usleep (1000);
printf("\nADC in Fast Convertion Mode (10us) and Fs=9.8KHz (Min)\n");
int LENB = 0xFE; // 254 read/cmd
/******************************* TEST 1 ***********************************/
printf("\nINIT TEST1: Autoselft {(Vref+) - (Vref-)}/2 -> Return 0x0200 \n");
jz_adc_config(ADCBuffer, 0x01, ADC_SPI_CLKDIV_MAX, ADC_CMD_SET_AUTOSELFT_1);
usleep (1000);
jz_adc_config(ADCBuffer, LENB, ADC_SPI_CLKDIV_MAX, ADC_CMD_READ_AUTOSELFT_1);
printf("[%08X]", ADCBuffer[0]);fflush (stdout);
while(jz_adc_check_buffer(ADCBuffer)){usleep (10);}
for(int i=1; i< LENB/2+1; i++)
printf("[%08X]", ADCBuffer[i]);
fflush (stdout);
/******************************* TEST 2 ***********************************/
printf("\n\nINIT TEST2: Autoselft (Vref-) -> Return 0x0000 \n");
jz_adc_config(ADCBuffer, 0x01, ADC_SPI_CLKDIV_MAX, ADC_CMD_SET_AUTOSELFT_2);
usleep (1000);
jz_adc_config(ADCBuffer, LENB, ADC_SPI_CLKDIV_MAX, ADC_CMD_READ_AUTOSELFT_2);
printf("[%08X]", ADCBuffer[0]);fflush (stdout);
while(jz_adc_check_buffer(ADCBuffer)){usleep (10);}
for(int i=1; i< LENB/2+1; i++)
printf("[%08X]", ADCBuffer[i]);
fflush (stdout);
/******************************* TEST 3 ***********************************/
printf("\n\nINIT TEST3: Autoselft (Vref+) -> Return 0x03FF \n");
jz_adc_config(ADCBuffer, 0x01, ADC_SPI_CLKDIV_MAX, ADC_CMD_SET_AUTOSELFT_3);
usleep (1000);
jz_adc_config(ADCBuffer, LENB, ADC_SPI_CLKDIV_MAX, ADC_CMD_READ_AUTOSELFT_3);
printf("[%08X]", ADCBuffer[0]);fflush (stdout);
while(jz_adc_check_buffer(ADCBuffer)){usleep (10);}
for(int i=1; i< LENB/2+1; i++)
printf("[%08X]", ADCBuffer[i]);
fflush (stdout);
printf("\n\nTESTS complete\n");
}
void ADCw::powerDownADC()
{
jz_adc_config(ADCBuffer, 0x01, ADC_SPI_CLKDIV_MAX, ADC_CMD_SET_POWER_DOWN);
printf("\nADC in Power Down Mode \n");
}
JZ_REG* ADCw::takeSamplesADC(int LENB, uchar CLKDIV, int CHANNEL)
{
jz_adc_config(ADCBuffer, 0x01, CLKDIV, ADC_CMD_SET_CHANNEL0+CHANNEL);
usleep (1000);
jz_adc_config(ADCBuffer, LENB, CLKDIV, ADC_CMD_READ_CHANNEL0+CHANNEL);
//while(jz_adc_check_buffer(ADCBuffer)){usleep (400000);printf("[%08X]", ADCBuffer[0]);fflush (stdout);}
while(jz_adc_check_buffer(ADCBuffer)){usleep (10);}
return ADCBuffer;
}