This is a library for the Texas Instruments PGA112
PGA122_Driver.h@0:4cb6d8393e9d, 2019-01-21 (annotated)
- Committer:
- rvasquez6089
- Date:
- Mon Jan 21 19:00:25 2019 +0000
- Revision:
- 0:4cb6d8393e9d
- Child:
- 1:b3fee6ce395f
Not tested yet, but will soon. Should work just fine.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
rvasquez6089 | 0:4cb6d8393e9d | 1 | #ifndef PGA112_DRIVER_H |
rvasquez6089 | 0:4cb6d8393e9d | 2 | #define PGA112_DRIVER_H |
rvasquez6089 | 0:4cb6d8393e9d | 3 | #include "mbed.h" |
rvasquez6089 | 0:4cb6d8393e9d | 4 | #define CMD_WRITE 0x2A |
rvasquez6089 | 0:4cb6d8393e9d | 5 | |
rvasquez6089 | 0:4cb6d8393e9d | 6 | #define GAIN_1 0x0 |
rvasquez6089 | 0:4cb6d8393e9d | 7 | #define GAIN_2 0x1 |
rvasquez6089 | 0:4cb6d8393e9d | 8 | #define GAIN_4 0x2 |
rvasquez6089 | 0:4cb6d8393e9d | 9 | #define GAIN_8 0x3 |
rvasquez6089 | 0:4cb6d8393e9d | 10 | #define GAIN_16 0x4 |
rvasquez6089 | 0:4cb6d8393e9d | 11 | #define GAIN_32 0x5 |
rvasquez6089 | 0:4cb6d8393e9d | 12 | #define GAIN_64 0x6 |
rvasquez6089 | 0:4cb6d8393e9d | 13 | #define GAIN_128 0x7 |
rvasquez6089 | 0:4cb6d8393e9d | 14 | |
rvasquez6089 | 0:4cb6d8393e9d | 15 | #define CAL_1 0xC // Channel 12 |
rvasquez6089 | 0:4cb6d8393e9d | 16 | #define CAL_2 0xD // Channel 13 |
rvasquez6089 | 0:4cb6d8393e9d | 17 | #define CAL_3 0xE // Channel 14 |
rvasquez6089 | 0:4cb6d8393e9d | 18 | #define CAL_4 0xF // Channel 15 |
rvasquez6089 | 0:4cb6d8393e9d | 19 | #define VCAL_CH0 0x0 // channel 0 |
rvasquez6089 | 0:4cb6d8393e9d | 20 | #define CH_1 0x1 // channel 1 |
rvasquez6089 | 0:4cb6d8393e9d | 21 | |
rvasquez6089 | 0:4cb6d8393e9d | 22 | |
rvasquez6089 | 0:4cb6d8393e9d | 23 | /** This is library to drive the PGA112. Basic funcitons have been implemented. |
rvasquez6089 | 0:4cb6d8393e9d | 24 | * |
rvasquez6089 | 0:4cb6d8393e9d | 25 | */ |
rvasquez6089 | 0:4cb6d8393e9d | 26 | |
rvasquez6089 | 0:4cb6d8393e9d | 27 | class PGA112 |
rvasquez6089 | 0:4cb6d8393e9d | 28 | { |
rvasquez6089 | 0:4cb6d8393e9d | 29 | public: |
rvasquez6089 | 0:4cb6d8393e9d | 30 | /** Create a PGA object |
rvasquez6089 | 0:4cb6d8393e9d | 31 | * This takes a pointer object of an SPI bus. Becareful, this is not thread safe |
rvasquez6089 | 0:4cb6d8393e9d | 32 | * and may cause hanging |
rvasquez6089 | 0:4cb6d8393e9d | 33 | * |
rvasquez6089 | 0:4cb6d8393e9d | 34 | * @param SPI_BUS pointer to SPI object |
rvasquez6089 | 0:4cb6d8393e9d | 35 | * @param Chip_Select chip select line for the PGA. pointer plz |
rvasquez6089 | 0:4cb6d8393e9d | 36 | */ |
rvasquez6089 | 0:4cb6d8393e9d | 37 | PGA112(SPI *SPI_BUS, DigitalOut *Chip_Select); |
rvasquez6089 | 0:4cb6d8393e9d | 38 | /** This will set the gain for the PGA |
rvasquez6089 | 0:4cb6d8393e9d | 39 | * Please only use binary gains.....1,2,4,8,16,32,64,128 |
rvasquez6089 | 0:4cb6d8393e9d | 40 | * |
rvasquez6089 | 0:4cb6d8393e9d | 41 | * @param gain_set parameter to set gain, see comment for acceptable gain values |
rvasquez6089 | 0:4cb6d8393e9d | 42 | */ |
rvasquez6089 | 0:4cb6d8393e9d | 43 | void set_gain(int gain_set); |
rvasquez6089 | 0:4cb6d8393e9d | 44 | /** Sets the channel selection |
rvasquez6089 | 0:4cb6d8393e9d | 45 | * CAL_1 0xC // Channel 12 GND |
rvasquez6089 | 0:4cb6d8393e9d | 46 | * CAL_2 0xD // Channel 13 0.9*Vcal |
rvasquez6089 | 0:4cb6d8393e9d | 47 | * CAL_3 0xE // Channel 14 0.1*Vcal |
rvasquez6089 | 0:4cb6d8393e9d | 48 | * CAL_4 0xF // Channel 15 Vref (2.5000 volts) |
rvasquez6089 | 0:4cb6d8393e9d | 49 | * VCAL_CH0 0x0 // channel 0 Vcal (5.0000 volts) |
rvasquez6089 | 0:4cb6d8393e9d | 50 | * CH_1 0x1 // channel 1 |
rvasquez6089 | 0:4cb6d8393e9d | 51 | * |
rvasquez6089 | 0:4cb6d8393e9d | 52 | * @param channel_set the channel you want to select. See above table for values |
rvasquez6089 | 0:4cb6d8393e9d | 53 | */ |
rvasquez6089 | 0:4cb6d8393e9d | 54 | void set_channel(int channel_set); |
rvasquez6089 | 0:4cb6d8393e9d | 55 | /** Sets the channel to CAL1 channel which is connected to GND |
rvasquez6089 | 0:4cb6d8393e9d | 56 | */ |
rvasquez6089 | 0:4cb6d8393e9d | 57 | void set_CAL1(); |
rvasquez6089 | 0:4cb6d8393e9d | 58 | /** Sets the channel to CAL2 channel which is connected to 0.9*Vcal (Vcal = 5) |
rvasquez6089 | 0:4cb6d8393e9d | 59 | */ |
rvasquez6089 | 0:4cb6d8393e9d | 60 | void set_CAL2(); |
rvasquez6089 | 0:4cb6d8393e9d | 61 | /** Sets the channel to CAL3 channel which is connected to 0.1*Vcal (Vcal = 5) |
rvasquez6089 | 0:4cb6d8393e9d | 62 | */ |
rvasquez6089 | 0:4cb6d8393e9d | 63 | void set_CAL3(); |
rvasquez6089 | 0:4cb6d8393e9d | 64 | /** Sets the channel to CAL4 channel which is connected to Vref (2.5V) |
rvasquez6089 | 0:4cb6d8393e9d | 65 | */ |
rvasquez6089 | 0:4cb6d8393e9d | 66 | void set_CAL4(); |
rvasquez6089 | 0:4cb6d8393e9d | 67 | private: |
rvasquez6089 | 0:4cb6d8393e9d | 68 | SPI *PGA; |
rvasquez6089 | 0:4cb6d8393e9d | 69 | DigitalOut *CS; |
rvasquez6089 | 0:4cb6d8393e9d | 70 | int gain; |
rvasquez6089 | 0:4cb6d8393e9d | 71 | int channel; |
rvasquez6089 | 0:4cb6d8393e9d | 72 | char gain_chan; |
rvasquez6089 | 0:4cb6d8393e9d | 73 | }; |
rvasquez6089 | 0:4cb6d8393e9d | 74 | #endif |