Root/Software/sie_cg/templates/basic (copy)/jz_adc_peripheral.h

1/* ADC Peripheral.h
2
3Copyright (C) 2010 Carlos Camargo cicamargoba@unal.edu.co
4                               Andres Calderon andres.calderon@emqbit.com
5
6This program is free software; you can redistribute it and/or modify
7it under the terms of the GNU General Public License as published by
8the Free Software Foundation; either version 2 of the License, or
9(at your option) any later version.
10
11This program is distributed in the hope that it will be useful,
12but WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14GNU General Public License for more details.
15
16You should have received a copy of the GNU General Public License
17along with this program; if not, write to the Free Software
18Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
19
20#ifndef __adc_peripheral_h__
21#define __adc_peripheral_h__
22
23#include "jz47xx_mmap.h"
24
25#define ADC_CMD_NONE 0x00 /* Nothing to do */
26#define ADC_CMD_SET_SPI_CLKDIV 0x00 /* Set clock divider for ADC sclk */
27#define ADC_CMD_SET_BUFFER_SIZE 0x00 /* Set clock divider for ADC sclk */
28
29#define ADC_CMD_SET_CHANNEL0 0x30 /* Set channel 0 */
30#define ADC_CMD_READ_CHANNEL0 0x20 /* Read channel 0 */
31
32#define ADC_CMD_SET_CHANNEL1 0x31 /* Set channel 1 */
33#define ADC_CMD_READ_CHANNEL1 0x21 /* Read channel 1 */
34
35#define ADC_CMD_SET_CHANNEL2 0x32 /* Set channel 2 */
36#define ADC_CMD_READ_CHANNEL2 0x22 /* Read channel 2 */
37
38#define ADC_CMD_SET_CHANNEL3 0x33 /* Set channel 3 */
39#define ADC_CMD_READ_CHANNEL3 0x23 /* Read channel 3 */
40
41#define ADC_CMD_SET_CHANNEL4 0x34 /* Set channel 4 */
42#define ADC_CMD_READ_CHANNEL4 0x24 /* Read channel 4 */
43
44#define ADC_CMD_SET_CHANNEL5 0x35 /* Set channel 5 */
45#define ADC_CMD_READ_CHANNEL5 0x25 /* Read channel 5 */
46
47#define ADC_CMD_SET_CHANNEL6 0x36 /* Set channel 6 */
48#define ADC_CMD_READ_CHANNEL6 0x26 /* Read channel 6 */
49
50#define ADC_CMD_SET_CHANNEL7 0x37 /* Set channel 7 */
51#define ADC_CMD_READ_CHANNEL7 0x27 /* Read channel 8 */
52
53#define ADC_CMD_SET_POWER_DOWN 0X38 /* Set ADC power down mode (1uA) */
54
55#define ADC_CMD_SET_FAST_CONV 0X39 /* Initialize ADC Fast Convertion(<10us)*/
56
57#define ADC_CMD_SET_LOW_CONV 0X3A /* Initialize ADC Slow Convertion(<40us)*/
58
59#define ADC_CMD_SET_AUTOSELFT_1 0x3B /* Set Autoselft ADC {(Vref+)-(Vref-)}/2*/
60#define ADC_CMD_READ_AUTOSELFT_1 0x2B /* Read Autoselft ADC 1 (0x0200) */
61
62#define ADC_CMD_SET_AUTOSELFT_2 0x3C /* Set Autoselft ADC (Vref-) */
63#define ADC_CMD_READ_AUTOSELFT_2 0x2C /* Read Autoselft ADC 2 (0x0000) */
64
65#define ADC_CMD_SET_AUTOSELFT_3 0x3D /* Set Autoselft ADC (Vref+) */
66#define ADC_CMD_READ_AUTOSELFT_3 0x2D /* Read Autoselft ADC 3 (0x03FF) */
67
68#define ADC_SPI_CLKDIV_MIN 0x08 /* 50/(2*9) -> 2.78MHz (MAX=2.8MHz) */
69#define ADC_SPI_CLKDIV_MAX 0xFF /* 50/(2*256) -> 97.65KHz */
70
71#define ADC_MAX_BUFFER 0x3FE/* 1022 reads/commands */
72
73
74typedef unsigned char uchar;
75
76void ADCTest();
77void ADCPowerDown();
78JZ_REG * ADCTakeSamples(int CHANNEL);
79void ADCConfig(uchar CMD);
80int ADCCheckBufferFull();
81
82uchar ADC_SPI_CLKDIV;
83int ADC_BUFFER_LEN;
84int ADC_BUFFER_OFFSET;
85uchar ADC_MUX_CHANNELS;
86
87#endif
88

Archive Download this file

Branches:
master



interactive