Demo code for the MAX11301WING. Programs a +5V on Port 0, -5V on Port 1 and a single-ended ADC on Port 9.
Dependencies: MAX113XX_Pixi max32630fthr
Fork of MAX11301_Demo by
main.cpp@0:6727152ebfbb, 2017-08-17 (annotated)
- Committer:
- coreyharris
- Date:
- Thu Aug 17 15:24:05 2017 +0000
- Revision:
- 0:6727152ebfbb
- Child:
- 1:c161bde4496f
Functional MAX11301 demo, sweeping from 0->0xFFF on the DAC and reading the values back with the ADC
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
coreyharris | 0:6727152ebfbb | 1 | #include "mbed.h" |
coreyharris | 0:6727152ebfbb | 2 | #include "max32630fthr.h" |
coreyharris | 0:6727152ebfbb | 3 | #include "MAX113XX_Pixi.h" |
coreyharris | 0:6727152ebfbb | 4 | #include "MAX11301Hex.h" |
coreyharris | 0:6727152ebfbb | 5 | |
coreyharris | 0:6727152ebfbb | 6 | MAX32630FTHR pegasus(MAX32630FTHR::VIO_3V3); |
coreyharris | 0:6727152ebfbb | 7 | |
coreyharris | 0:6727152ebfbb | 8 | |
coreyharris | 0:6727152ebfbb | 9 | int main() |
coreyharris | 0:6727152ebfbb | 10 | { |
coreyharris | 0:6727152ebfbb | 11 | Serial pc(USBTX, USBRX); |
coreyharris | 0:6727152ebfbb | 12 | pc.baud(115200); |
coreyharris | 0:6727152ebfbb | 13 | |
coreyharris | 0:6727152ebfbb | 14 | DigitalOut rLed(LED1, LED_OFF); |
coreyharris | 0:6727152ebfbb | 15 | DigitalOut gLed(LED2, LED_OFF); |
coreyharris | 0:6727152ebfbb | 16 | DigitalOut bLed(LED3, LED_OFF); |
coreyharris | 0:6727152ebfbb | 17 | |
coreyharris | 0:6727152ebfbb | 18 | I2C i2cBus(I2C1_SDA, I2C1_SCL); // I2C bus |
coreyharris | 0:6727152ebfbb | 19 | |
coreyharris | 0:6727152ebfbb | 20 | MAX113XX_I2C * pixi; |
coreyharris | 0:6727152ebfbb | 21 | pixi = new MAX113XX_I2C(i2cBus, MAX113XX_I2C::MAX11301, 0x38, P5_5); |
coreyharris | 0:6727152ebfbb | 22 | |
coreyharris | 0:6727152ebfbb | 23 | uint16_t adcData; |
coreyharris | 0:6727152ebfbb | 24 | float adcVoltage; |
coreyharris | 0:6727152ebfbb | 25 | |
coreyharris | 0:6727152ebfbb | 26 | while(1) { |
coreyharris | 0:6727152ebfbb | 27 | |
coreyharris | 0:6727152ebfbb | 28 | for( int idx = 0; idx <= 0xFFF; idx++ ) { |
coreyharris | 0:6727152ebfbb | 29 | |
coreyharris | 0:6727152ebfbb | 30 | pixi->dacWrite(MAX113XX_Pixi::PORT0, idx); |
coreyharris | 0:6727152ebfbb | 31 | pixi->singleEndedADCRead(MAX113XX_Pixi::PORT9, adcData); |
coreyharris | 0:6727152ebfbb | 32 | adcVoltage = -5 + 2.4414e-3 * adcData; |
coreyharris | 0:6727152ebfbb | 33 | |
coreyharris | 0:6727152ebfbb | 34 | pc.printf("ADC Voltage is %1.3f V, Count is 0x%x \r\n", adcVoltage, idx); |
coreyharris | 0:6727152ebfbb | 35 | } |
coreyharris | 0:6727152ebfbb | 36 | |
coreyharris | 0:6727152ebfbb | 37 | pc.printf("\r\n\r\nSweep complete, starting new sweep \r\n\r\n"); |
coreyharris | 0:6727152ebfbb | 38 | wait(2.0); |
coreyharris | 0:6727152ebfbb | 39 | |
coreyharris | 0:6727152ebfbb | 40 | } |
coreyharris | 0:6727152ebfbb | 41 | } |
coreyharris | 0:6727152ebfbb | 42 |