This is the device firmware for the imagingBoard on the DIY 3D Printable Raspberry Pi Raman Spectrometer. For more details please visit: http://hackaday.io/project/1279
main.cpp@0:984447b91a04, 2014-08-15 (annotated)
- Committer:
- flatcat
- Date:
- Fri Aug 15 10:35:34 2014 +0000
- Revision:
- 0:984447b91a04
- Child:
- 1:a220fd937508
http://hackaday.io/project/1279
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
flatcat | 0:984447b91a04 | 1 | #include "mbed.h" |
flatcat | 0:984447b91a04 | 2 | |
flatcat | 0:984447b91a04 | 3 | // *** BE SURE TO TEST BEFORE AND AFTER FOR 'IDLING'... CLEAR THE CCD EVERY OTHER FRAME TO TRY AND ELIMINATE NOISE BUILDUP |
flatcat | 0:984447b91a04 | 4 | //From http://www.ing.iac.es/~docs/ins/das/ins-das-29/integration.html |
flatcat | 0:984447b91a04 | 5 | //"Idling" vs. integrating |
flatcat | 0:984447b91a04 | 6 | //Charge from light leaks and thermal noise builds up on the detector between observations. If this charge is integrated by the detector, it may not be completely |
flatcat | 0:984447b91a04 | 7 | //cleared away by the clear cycle of the next observation. In that case, the observation will be contaminated by extra counts. (Often, this appears as a ramp in the |
flatcat | 0:984447b91a04 | 8 | //background leading up to a saturated region in the low-numbered rows.) |
flatcat | 0:984447b91a04 | 9 | //To avoid this problem, the detector is made to clear itself continuously between observations. This is called "idling", and is reported as such on the mimic. |
flatcat | 0:984447b91a04 | 10 | |
flatcat | 0:984447b91a04 | 11 | PwmOut shiftGate(PB_8); |
flatcat | 0:984447b91a04 | 12 | PwmOut icg(PB_3); |
flatcat | 0:984447b91a04 | 13 | PwmOut masterClock(PB_4); |
flatcat | 0:984447b91a04 | 14 | AnalogIn imageIn(A0); |
flatcat | 0:984447b91a04 | 15 | AnalogOut imageOut(A5); |
flatcat | 0:984447b91a04 | 16 | DigitalOut myled(LED1); |
flatcat | 0:984447b91a04 | 17 | Serial raspi(USBTX, USBRX); |
flatcat | 0:984447b91a04 | 18 | |
flatcat | 0:984447b91a04 | 19 | int masterFreq_period = 2; //microseconds |
flatcat | 0:984447b91a04 | 20 | int masterFreq_width = 1; //microseconds |
flatcat | 0:984447b91a04 | 21 | int icgFreq_period = 500000; //microseconds |
flatcat | 0:984447b91a04 | 22 | int icgFreq_width = 250000; //microseconds <------------- LOWER THIS NUMBER TO INCREASE SENSITIVITY |
flatcat | 0:984447b91a04 | 23 | int shiftGate_delay = 287; //microseconds |
flatcat | 0:984447b91a04 | 24 | int shiftGate_period = 200; //microseconds |
flatcat | 0:984447b91a04 | 25 | int shiftGate_width = 100; //microseconds |
flatcat | 0:984447b91a04 | 26 | |
flatcat | 0:984447b91a04 | 27 | #define MV(x) ((0xFFF*x)/3300) |
flatcat | 0:984447b91a04 | 28 | |
flatcat | 0:984447b91a04 | 29 | int main() |
flatcat | 0:984447b91a04 | 30 | { |
flatcat | 0:984447b91a04 | 31 | // set the masterClock |
flatcat | 0:984447b91a04 | 32 | masterClock.period_us(masterFreq_period); |
flatcat | 0:984447b91a04 | 33 | masterClock.pulsewidth_us(masterFreq_width); |
flatcat | 0:984447b91a04 | 34 | |
flatcat | 0:984447b91a04 | 35 | // set the ICG clock and have it start 82.76ms after the shiftGate - this will sync the clocks up so the ICQ is going low slightly before the shiftGate is going high |
flatcat | 0:984447b91a04 | 36 | icg.period_us(icgFreq_period); |
flatcat | 0:984447b91a04 | 37 | icg.pulsewidth_us(icgFreq_width); // <------------- LOWER THIS NUMBER TO INCREASE SENSITIVITY |
flatcat | 0:984447b91a04 | 38 | |
flatcat | 0:984447b91a04 | 39 | // set the shiftGate and have it start 15us after the masterClock - this will sync the clocks up so the shiftGate is going high just as a clock cycle is going high |
flatcat | 0:984447b91a04 | 40 | wait_us(shiftGate_delay); |
flatcat | 0:984447b91a04 | 41 | shiftGate.period_us(shiftGate_period); |
flatcat | 0:984447b91a04 | 42 | shiftGate.pulsewidth_us(shiftGate_width); |
flatcat | 0:984447b91a04 | 43 | |
flatcat | 0:984447b91a04 | 44 | raspi.baud(921600); |
flatcat | 0:984447b91a04 | 45 | // do something while it's having fun.. |
flatcat | 0:984447b91a04 | 46 | while(1) { |
flatcat | 0:984447b91a04 | 47 | // wait(.0001); |
flatcat | 0:984447b91a04 | 48 | // uint16_t meas = imageIn.read_u16(); |
flatcat | 0:984447b91a04 | 49 | // if (meas < MV(1000)) { |
flatcat | 0:984447b91a04 | 50 | // myled = 1; |
flatcat | 0:984447b91a04 | 51 | // printf("BINGO: %d \r\n", meas); |
flatcat | 0:984447b91a04 | 52 | // } |
flatcat | 0:984447b91a04 | 53 | // myled = 0; |
flatcat | 0:984447b91a04 | 54 | imageOut.write(imageIn.read()); |
flatcat | 0:984447b91a04 | 55 | } |
flatcat | 0:984447b91a04 | 56 | } |
flatcat | 0:984447b91a04 | 57 |