Oliver Broad
/
MAX110
Simple readout code for MAX110/111 14-bit ADC
main.cpp@0:177a872748b8, 2012-07-08 (annotated)
- Committer:
- oliverb
- Date:
- Sun Jul 08 16:49:43 2012 +0000
- Revision:
- 0:177a872748b8
- Child:
- 1:46c26c1de51f
One MHz, binary count, readback test, comments
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
oliverb | 0:177a872748b8 | 1 | #include "mbed.h" |
oliverb | 0:177a872748b8 | 2 | // Use SPI port to write an 8 bit pattern to MIC5821 open collector driver device. |
oliverb | 0:177a872748b8 | 3 | // MBED led1 lights if pattern read back from MIC5821 matches pattern written |
oliverb | 0:177a872748b8 | 4 | // Ordinarily the device would be write-only but loopback may be usefull in testing. |
oliverb | 0:177a872748b8 | 5 | // Cascade output is NOT tristate. Strobe is NOT a CS/SS signal, needs a pulse. |
oliverb | 0:177a872748b8 | 6 | // |
oliverb | 0:177a872748b8 | 7 | // Note that the MIC has a speed limit, 3.3MHz at 5v, mine works OK at 1MHz at 3.3v |
oliverb | 0:177a872748b8 | 8 | // Also input has CMOS thresholds so it may not recognise MBED logic HI when powered |
oliverb | 0:177a872748b8 | 9 | // from 5v so power it from Vout. |
oliverb | 0:177a872748b8 | 10 | // |
oliverb | 0:177a872748b8 | 11 | // Data is clocked in on rising edges so SPI 0,0 or SPI 1,1. |
oliverb | 0:177a872748b8 | 12 | |
oliverb | 0:177a872748b8 | 13 | SPI spi(p5, p6, p7); // mosi, miso, sclk |
oliverb | 0:177a872748b8 | 14 | |
oliverb | 0:177a872748b8 | 15 | DigitalOut strobe(p21); |
oliverb | 0:177a872748b8 | 16 | DigitalOut led(LED1); |
oliverb | 0:177a872748b8 | 17 | |
oliverb | 0:177a872748b8 | 18 | int main() { |
oliverb | 0:177a872748b8 | 19 | spi.format(8,0); |
oliverb | 0:177a872748b8 | 20 | spi.frequency(1000000); |
oliverb | 0:177a872748b8 | 21 | char leds,prev; |
oliverb | 0:177a872748b8 | 22 | leds=0; |
oliverb | 0:177a872748b8 | 23 | while(1) { |
oliverb | 0:177a872748b8 | 24 | prev=spi.write(leds)+1; |
oliverb | 0:177a872748b8 | 25 | led=(prev == leds); |
oliverb | 0:177a872748b8 | 26 | leds++; |
oliverb | 0:177a872748b8 | 27 | strobe=1; |
oliverb | 0:177a872748b8 | 28 | wait_us(1); |
oliverb | 0:177a872748b8 | 29 | strobe=0; |
oliverb | 0:177a872748b8 | 30 | wait(0.5); |
oliverb | 0:177a872748b8 | 31 | } |
oliverb | 0:177a872748b8 | 32 | } |