source: firmware/FSC/src/ad7719_adc.h@ 13147

Last change on this file since 13147 was 10697, checked in by neise, 14 years ago
File size: 3.1 KB
Line 
1#ifndef __AD7719_ADC_H
2#define __AD7719_ADC_H
3//-----------------------------------------------------------------------------
4
5#include "typedefs.h"
6#include "application.h"
7#include "num_conversion.h"
8//-----------------------------------------------------------------------------
9// SPI INTERFACE of AD7719
10// SCLK:
11// SCLK HIGH & LOW cycle min 100ns --> 5MHz maximum SCLK frequency
12// FSC runs at 8MHz CPU clock ... so 4MHz SPI clock is the theoretocal maximum anyway.
13// SCLK should idle high --> mode 3
14//
15// CS falling edge & SCLK falling edge, may be at the same time ...
16//
17
18// There is a delay in all communications between AD7719 and ATmega.
19// I guess this is not needed at all.
20// This switch is able to get them in again
21#define AD7719_COM_DELAY_NEEDED
22
23// Bit Definitions
24#define ADC_RDY PD6
25#define ADC_RST PD7
26#define AD7719_IS_READY() (!(PIND & (1<<PD6))) // TRUE if PD6=0 AD_RDY is inverted logic.
27
28// Port Definitions
29#define ADC_PRT PORTD
30#define ADC_DDR DDRD
31#define ADC_PIN PIND
32
33
34// ON CHIP REGISTER ADDRESSES
35#define STATUS_RD 0x40
36
37#define MODE_WR 0x01
38#define MODE_RD 0x41
39
40#define AD0CON_WR 0x02
41#define AD0CON_RD 0x42
42
43#define AD1CON_WR 0x03
44#define AD1CON_RD 0x43
45
46#define FILTER_WR 0x04
47#define FILTER_RD 0x44
48
49#define AD0DAT_RD 0x45
50#define AD1DAT_RD 0x46
51
52#define IOCON_WR 0x07
53#define IOCON_RD 0x47
54
55#define AD0OFS_WR 0x08
56#define AD0OFS_RD 0x48
57
58#define AD1OFS_WR 0x09
59#define AD1OFS_RD 0x49
60
61#define AD0GAIN_WR 0x0A
62#define AD0GAIN_RD 0x4A
63
64#define AD1GAIN_WR 0x0B
65#define AD1GAIN_RD 0x4B
66
67#define ID_RD 0x4F
68
69// REGISTER INIT VALUES
70
71 //Init Configure and Initialize AD7719
72 //http://designtools.analog.com/dt/adc/codegen/ad7719.html
73
74#define IOCON_INIT_HIGH 0x03 //0000.0011 // I-sources I1 and I2 are switched on, thats all
75#define IOCON_INIT_LOWBYTE 0x00
76
77#define FILTER_INIT 0x52 //0x52 euro use 50Hz = -171dB and 60Hz = -58dB Rejectjon Updaterate = 4Hz
78 // 0x52=82 decimal. f_ADC=16.6Hz; t_ADC=60ms; t_settle = 120ms
79
80#define AD1CON_INIT 0x31 //0011.0001
81 // AD1EN is set --> AUX ADc is used for Temp measurement.
82 // ACH = 011 --> Tempsensor
83 // U/#B = 0 --> bipolar, but i'm not entirely sure if this is correct.
84 // ARN = 1 --> input range is REFIN2 , but when tempsensor is chosen, internal ref is used ...
85
86#define AD0CON_INIT 0x8E // 1000.1110
87 // AD0EN is set --> main ADC is swtiched on
88 // WL is cleared --> 24bit
89 // CH = 00 --> AIN1 , AIN2 used
90 // U/#B = 1 --> unipolar
91 // RN=110 --> input range = +-1.28V --> whatever this means in ratiometric measurements.
92
93
94#define MODE_IDLE 0x01
95#define MODE_SINGLE 0x02
96#define MODE_CONT 0x03
97#define MODE_INTERNAL_ZERO_CAL 0x04 // not tested
98#define MODE_INTERNAL_FULL_CAL 0x05 // not tested
99
100// since the ADC is chopped, one should wait 3 conversions
101// after the muxer was switched, until the reading is okay.
102#define READINGS_UNTIL_AD7719_SETTLED 3
103
104void ad7719_init(void);
105void startconv(U08 continuous);
106void stopconv(void);
107U32 read_adc(void);
108//-----------------------------------------------------------------------------
109#endif
Note: See TracBrowser for help on using the repository browser.