1
0
mirror of git://projects.qi-hardware.com/nn-usb-fpga.git synced 2025-01-10 19:20:14 +02:00
nn-usb-fpga/Examples/ADC/QT_src/jz_test_adc.c
2010-04-05 14:06:50 -05:00

111 lines
3.7 KiB
C

/* ADC TEST
Copyright (C) 2010 Carlos Camargo cicamargoba@unal.edu.co
Andres Calderon andres.calderon@emqbit.com
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
#include <stdio.h>
#include <unistd.h>
#include "jz47xx_gpio.h"
#include "jz47xx_mmap.h"
#include "jz_adc_peripheral.h"
#define TEST_PORT JZ_GPIO_PORT_B
#define TEST_PIN 26
int
main ()
{
int i,j;
JZ_PIO *pio;
JZ_REG *virt_addr;
pio = jz_gpio_map (TEST_PORT);
jz_gpio_as_func (pio, TEST_PIN, 0);
virt_addr = (JZ_REG *) (jz_mmap (0x13010000) + 0x18);
if (*virt_addr != 0x0FFF7700)
{
*virt_addr = 0x0FFF7700;
printf ("Configuring CS2 32 bits and 0 WS: %08X\n", *virt_addr);
}
else
printf ("CS2, already configured: %08X\n", *virt_addr);
virt_addr = (JZ_REG *) jz_mmap (0x14000000);
/*************************Clean FPGA RAM memory****************************/
for (i = 0; i < 512; i++) //RAMB16_s9_s9 has 2048 bytes 8-bit
{
virt_addr[i] = 0x00000000; //Clean 4 register by cicle
}
/****************Configure ADC register on FPGA RAM memory*****************/
uchar LENB = 0x01; // 1 read/cmd
jz_adc_config(virt_addr, LENB, ADC_SPI_CLKDIV_MAX, ADC_CMD_SET_SPI_CLKDIV);
usleep (100);
jz_adc_config(virt_addr, LENB, ADC_SPI_CLKDIV_MAX, ADC_CMD_SET_FAST_CONV);
usleep (100);
printf("\nADC in Fast Convertion Mode (10us) and Fs=9.8KHz (Min)\n");
LENB = ADC_MAX_BUFFER; // 254 read/cmd
/******************************* TEST 1 ***********************************/
printf("\nINIT TEST1: Autoselft {(Vref+) - (Vref-)}/2 -> Return 0x0200 \n");
jz_adc_config(virt_addr, LENB, ADC_SPI_CLKDIV_MAX, ADC_CMD_SET_AUTOSELFT_1);
usleep (100);
jz_adc_config(virt_addr, LENB, ADC_SPI_CLKDIV_MAX, ADC_CMD_READ_AUTOSELFT_1);
printf("[%08X]", virt_addr[0]);
while(jz_adc_check_buffer(virt_addr))
{
printf("[%08X]-", virt_addr[0]);
fflush (stdout);
usleep (10000);
}
for(i=1; i< LENB/2+1; i++)
printf("[%08X]", virt_addr[i]);
/******************************* TEST 2 ***********************************/
printf("\n\nINIT TEST2: Autoselft (Vref-) -> Return 0x0000 \n");
jz_adc_config(virt_addr, LENB, ADC_SPI_CLKDIV_MAX, ADC_CMD_SET_AUTOSELFT_2);
usleep (100);
jz_adc_config(virt_addr, LENB, ADC_SPI_CLKDIV_MAX, ADC_CMD_READ_AUTOSELFT_2);
while(jz_adc_check_buffer(virt_addr)){usleep (100);}
for(i=1; i< LENB/2+1; i++)
printf("[%08X]", virt_addr[i]);
/******************************* TEST 3 ***********************************/
printf("\n\nINIT TEST3: Autoselft (Vref+) -> Return 0x03FF \n");
jz_adc_config(virt_addr, LENB, ADC_SPI_CLKDIV_MAX, ADC_CMD_SET_AUTOSELFT_3);
usleep (100);
jz_adc_config(virt_addr, LENB, ADC_SPI_CLKDIV_MAX, ADC_CMD_READ_AUTOSELFT_3);
while(jz_adc_check_buffer(virt_addr)){usleep (100);}
for(i=1; i< LENB/2+1; i++)
printf("[%08X]", virt_addr[i]);
printf("\n\nTESTS complete\n");
LENB = 0x01; // 1 read/cmd
jz_adc_config(virt_addr, LENB, ADC_SPI_CLKDIV_MAX, ADC_CMD_SET_POWER_DOWN);
printf("\nADC in Power Down Mode \n");
return 0;
}