mirror of
git://projects.qi-hardware.com/nn-usb-fpga.git
synced 2025-04-21 12:27:27 +03:00
Fixing multi-channel mode.
This commit is contained in:
Binary file not shown.
@@ -2,9 +2,10 @@
|
||||
|
||||
ADCw::ADCw()
|
||||
{
|
||||
BUFFER_OFFSET = 8;
|
||||
BUFFER_OFFSET = 9;
|
||||
ADC_SPI_CLKDIV=ADC_SPI_CLKDIV_MAX; //Set clock to minimum speed
|
||||
BUFFER_LEN=10;
|
||||
BUFFER_LEN=16;
|
||||
MUX_CHANNELS =0;
|
||||
|
||||
ADCBuffer = jz_adc_init();
|
||||
|
||||
@@ -25,7 +26,6 @@ void ADCw::testADC()
|
||||
printf("\nINIT TEST1: Autoselft {(Vref+) - (Vref-)}/2 -> Return 0x0200 \n");
|
||||
adcConfig(ADC_CMD_SET_AUTOSELFT_1);
|
||||
adcConfig(ADC_CMD_READ_AUTOSELFT_1);
|
||||
while(adcCheckBufferFull())usleep (10);
|
||||
for(int i=BUFFER_OFFSET; i< BUFFER_LEN/2+BUFFER_OFFSET; i++)
|
||||
printf("[%08X]", ADCBuffer[i]);
|
||||
fflush (stdout);
|
||||
@@ -34,7 +34,6 @@ void ADCw::testADC()
|
||||
printf("\n\nINIT TEST2: Autoselft (Vref-) -> Return 0x0000 \n");
|
||||
adcConfig(ADC_CMD_SET_AUTOSELFT_2);
|
||||
adcConfig(ADC_CMD_READ_AUTOSELFT_2);
|
||||
while(adcCheckBufferFull())usleep (10);
|
||||
for(int i=BUFFER_OFFSET; i< BUFFER_LEN/2+BUFFER_OFFSET; i++)
|
||||
printf("[%08X]", ADCBuffer[i]);
|
||||
fflush (stdout);
|
||||
@@ -60,17 +59,18 @@ JZ_REG* ADCw::takeSamplesADC(int CHANNEL)
|
||||
{
|
||||
adcConfig(ADC_CMD_SET_CHANNEL0+CHANNEL);
|
||||
adcConfig(ADC_CMD_READ_CHANNEL0+CHANNEL);
|
||||
while(adcCheckBufferFull())usleep (10);
|
||||
return (JZ_REG*)(ADCBuffer+BUFFER_OFFSET);
|
||||
}
|
||||
|
||||
void ADCw::adcConfig(uchar CMD)
|
||||
{
|
||||
ADCBuffer[0] = ((BUFFER_LEN+(BUFFER_OFFSET-1)*2) << 16) + (ADC_SPI_CLKDIV<<8) + CMD;
|
||||
usleep (100);
|
||||
ADCBuffer[0] = (((MUX_CHANNELS<<6) + CMD)<<24) + \
|
||||
((BUFFER_LEN+(BUFFER_OFFSET-1)*2) << 8) + \
|
||||
(ADC_SPI_CLKDIV);
|
||||
while(adcCheckBufferFull()) usleep (10);
|
||||
}
|
||||
|
||||
int ADCw::adcCheckBufferFull()
|
||||
{
|
||||
return ADCBuffer[0]&0x20;
|
||||
return ADCBuffer[0]&0x20000000;
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ public:
|
||||
JZ_REG * takeSamplesADC(int CHANNEL);
|
||||
void setClockDiv(uchar value){ ADC_SPI_CLKDIV = value;}
|
||||
void setBufferLen(int value){ BUFFER_LEN = value;}
|
||||
|
||||
void setMuxChannels(uchar value){ MUX_CHANNELS = value;}
|
||||
private:
|
||||
void adcConfig(uchar CMD);
|
||||
int adcCheckBufferFull();
|
||||
@@ -25,6 +25,7 @@ private:
|
||||
uchar ADC_SPI_CLKDIV;
|
||||
int BUFFER_LEN;
|
||||
int BUFFER_OFFSET;
|
||||
uchar MUX_CHANNELS;
|
||||
};
|
||||
|
||||
#endif // ADCW_H
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#############################################################################
|
||||
# Makefile for building: ADC
|
||||
# Generated by qmake (2.01a) (Qt 4.6.2) on: Fri Apr 9 10:33:37 2010
|
||||
# Generated by qmake (2.01a) (Qt 4.6.2) on: Mon Apr 12 21:21:04 2010
|
||||
# Project: ADC1.pro
|
||||
# Template: app
|
||||
# Command: /home/juan64bits/ebd/ECB/openwrt-xburst/build_dir/target-mipsel_uClibc-0.9.30.1/qt-everywhere-opensource-src-4.6.2/bin/qmake -spec ../../../../openwrt-xburst/build_dir/target-mipsel_uClibc-0.9.30.1/qt-everywhere-opensource-src-4.6.2/mkspecs/qws/linux-openwrt-g++ -unix -o Makefile ADC1.pro
|
||||
|
||||
@@ -25,6 +25,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
|
||||
|
||||
#define ADC_CMD_NONE 0x00 /* Nothing to do */
|
||||
#define ADC_CMD_SET_SPI_CLKDIV 0x00 /* Set clock divider for ADC sclk */
|
||||
#define ADC_CMD_SET_BUFFER_SIZE 0x00 /* Set clock divider for ADC sclk */
|
||||
|
||||
#define ADC_CMD_SET_CHANNEL0 0x30 /* Set channel 0 */
|
||||
#define ADC_CMD_READ_CHANNEL0 0x20 /* Read channel 0 */
|
||||
@@ -68,7 +69,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
|
||||
#define ADC_SPI_CLKDIV_MIN 0x08 /* 50/(2*9) -> 2.78MHz (MAX=2.8MHz) */
|
||||
#define ADC_SPI_CLKDIV_MAX 0xFF /* 50/(2*256) -> 97.65KHz */
|
||||
|
||||
#define ADC_MAX_BUFFER 0x3F0/* 1008 reads/commands */
|
||||
#define ADC_MAX_BUFFER 0x3FE/* 1022 reads/commands */
|
||||
|
||||
#define CS2_PORT JZ_GPIO_PORT_B
|
||||
#define CS2_PIN 26
|
||||
|
||||
@@ -17,12 +17,12 @@ MainWindow::MainWindow(QWidget *parent)
|
||||
timer1->start(50);
|
||||
connect(timer1, SIGNAL(timeout()), this, SLOT(updateGraph()));
|
||||
|
||||
CHANNEL = 1;
|
||||
ADC1 = new ADCw;
|
||||
ADC1->testADC();
|
||||
ADC1->setBufferLen(120);
|
||||
ADC1->setClockDiv(ADC_SPI_CLKDIV_MAX); //Maximun speed
|
||||
printf("\nTaking 300 samples each 50ms from Channel 0,1 at Fs=99KHz \n");
|
||||
ADC1->setBufferLen(240);
|
||||
ADC1->setClockDiv(ADC_SPI_CLKDIV_MIN); //Max. speed
|
||||
ADC1->setMuxChannels(1);
|
||||
printf("\nTaking 120 samples by channel at Fs=99KHz (trigger=50ms)\n");
|
||||
}
|
||||
|
||||
MainWindow::~MainWindow()
|
||||
@@ -36,26 +36,12 @@ void MainWindow::updateGraph()
|
||||
|
||||
int tempD;
|
||||
|
||||
//CHANNEL 0
|
||||
dataADC=ADC1->takeSamplesADC(0);
|
||||
for(int i=0; i< 120/2; i++)
|
||||
{
|
||||
//printf("[%08X]",dataADC[i]);
|
||||
tempD = dataADC[i]&0xFFFF;
|
||||
for(int i=0; i< 240/2; i++)
|
||||
{
|
||||
tempD = dataADC[i]&0x0FFF;
|
||||
ui->Graph->addPoint1(tempD+0x3ff);
|
||||
tempD = dataADC[i]>>16;
|
||||
ui->Graph->addPoint1(tempD+0x3ff);
|
||||
}
|
||||
CHANNEL = 1;
|
||||
|
||||
//CHANNEL 1
|
||||
dataADC=ADC1->takeSamplesADC(1);
|
||||
for(int i=0; i< 120/2; i++)
|
||||
{
|
||||
//printf("[%08X]",dataADC[i]);
|
||||
tempD = dataADC[i]&0xFFFF;
|
||||
ui->Graph->addPoint2(tempD);
|
||||
tempD = dataADC[i]>>16;
|
||||
tempD = (dataADC[i]>>16)&0x0FFF;
|
||||
ui->Graph->addPoint2(tempD);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user