mirror of
git://projects.qi-hardware.com/nn-usb-fpga.git
synced 2025-01-10 19:50:14 +02:00
78 lines
2.8 KiB
C++
78 lines
2.8 KiB
C++
#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, 0x00, ADC_SPI_CLKDIV_MAX, ADC_CMD_SET_SPI_CLKDIV);
|
|
usleep (1000);
|
|
jz_adc_config(ADCBuffer, 0x00, 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, 0x00, ADC_SPI_CLKDIV_MAX, ADC_CMD_SET_AUTOSELFT_1);
|
|
printf("[%08X]", ADCBuffer[0]);fflush (stdout);
|
|
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< 512; i++)
|
|
printf("[%08X]", ADCBuffer[i]);
|
|
fflush (stdout);
|
|
|
|
/******************************* TEST 2 ***********************************/
|
|
printf("\n\nINIT TEST2: Autoselft (Vref-) -> Return 0x0000 \n");
|
|
jz_adc_config(ADCBuffer, 0x00, ADC_SPI_CLKDIV_MAX, ADC_CMD_SET_AUTOSELFT_2);
|
|
printf("[%08X]", ADCBuffer[0]);fflush (stdout);
|
|
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< 512; i++)
|
|
printf("[%08X]", ADCBuffer[i]);
|
|
fflush (stdout);
|
|
|
|
/******************************* TEST 3 ***********************************/
|
|
printf("\n\nINIT TEST3: Autoselft (Vref+) -> Return 0x03FF \n");
|
|
jz_adc_config(ADCBuffer, 0x00, ADC_SPI_CLKDIV_MAX, ADC_CMD_SET_AUTOSELFT_3);
|
|
printf("[%08X]", ADCBuffer[0]);fflush (stdout);
|
|
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< 512; i++)
|
|
printf("[%08X]", ADCBuffer[i]);
|
|
fflush (stdout);
|
|
|
|
printf("\n\nTESTS complete\n");
|
|
}
|
|
|
|
void ADCw::powerDownADC()
|
|
{
|
|
jz_adc_config(ADCBuffer, 0x00, 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, 0x00, 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;
|
|
}
|