Laser Sensing Display for UI interfaces in the real world
Fork of skinGames_forktest by
hardwareIO/lockin.h@0:345b3bc7a0ea, 2012-03-28 (annotated)
- Committer:
- mbedalvaro
- Date:
- Wed Mar 28 14:40:01 2012 +0000
- Revision:
- 0:345b3bc7a0ea
- Child:
- 1:a4050fee11f7
This version (using rigid frame, base and child classes, etc) works, but the blob is strangely smaller. Need to check this.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mbedalvaro | 0:345b3bc7a0ea | 1 | #ifndef MBED_LOCKIN_H |
mbedalvaro | 0:345b3bc7a0ea | 2 | #define MBED_LOCKIN_H |
mbedalvaro | 0:345b3bc7a0ea | 3 | |
mbedalvaro | 0:345b3bc7a0ea | 4 | #include "mbed.h" |
mbedalvaro | 0:345b3bc7a0ea | 5 | #include "adc.h" |
mbedalvaro | 0:345b3bc7a0ea | 6 | |
mbedalvaro | 0:345b3bc7a0ea | 7 | #define MBEDFREQUENCY 96000 //frequency of the mBed in KHz |
mbedalvaro | 0:345b3bc7a0ea | 8 | |
mbedalvaro | 0:345b3bc7a0ea | 9 | //#define I_Volts_SAT 5 // this is 5V (the saturation voltage for the APD+LockIn+ADC, being it the arduino (when in normal mode) or the SPI. This saturation voltage could be different for each mode!? |
mbedalvaro | 0:345b3bc7a0ea | 10 | |
mbedalvaro | 0:345b3bc7a0ea | 11 | #define LOCKIN_ADC_PIN p18 //ADC pin : connect to lockin output |
mbedalvaro | 0:345b3bc7a0ea | 12 | #define LOCKIN_LASER_PIN p22 //PWM pin : connect to laser input |
mbedalvaro | 0:345b3bc7a0ea | 13 | #define LOCKIN_REF_PIN p25 //PWM pin : connect to lockin input |
mbedalvaro | 0:345b3bc7a0ea | 14 | // p21 to p25 are used by the PWM timers even if only 2 pin are connected to the circuit |
mbedalvaro | 0:345b3bc7a0ea | 15 | |
mbedalvaro | 0:345b3bc7a0ea | 16 | #define BUFFER_SIZE 15 |
mbedalvaro | 0:345b3bc7a0ea | 17 | #define BUFFER_SIZE_MEDIAN 5 |
mbedalvaro | 0:345b3bc7a0ea | 18 | #define DELAY_BUFFER_MEDIAN 0 |
mbedalvaro | 0:345b3bc7a0ea | 19 | |
mbedalvaro | 0:345b3bc7a0ea | 20 | |
mbedalvaro | 0:345b3bc7a0ea | 21 | class Lockin { |
mbedalvaro | 0:345b3bc7a0ea | 22 | public: |
mbedalvaro | 0:345b3bc7a0ea | 23 | // default constructor (untouched!) |
mbedalvaro | 0:345b3bc7a0ea | 24 | // Lockin(); |
mbedalvaro | 0:345b3bc7a0ea | 25 | |
mbedalvaro | 0:345b3bc7a0ea | 26 | // initialization of object modes (could have parameters): |
mbedalvaro | 0:345b3bc7a0ea | 27 | void init(); |
mbedalvaro | 0:345b3bc7a0ea | 28 | |
mbedalvaro | 0:345b3bc7a0ea | 29 | void initPWM(); //setup the laser and reference signal used by the lockin |
mbedalvaro | 0:345b3bc7a0ea | 30 | void setPWMFrequency(float freq); //change the shared period of the pwm signals |
mbedalvaro | 0:345b3bc7a0ea | 31 | void setLaserPhaseShift(float phaseShift); //change the phase shift of the laser (from 0 to 1) |
mbedalvaro | 0:345b3bc7a0ea | 32 | void setLockinPhaseShift(float phaseShift); //change the phase shift of the lock-in (from 0 to 1) |
mbedalvaro | 0:345b3bc7a0ea | 33 | //future works: |
mbedalvaro | 0:345b3bc7a0ea | 34 | //add function to change frequency or offset with a potentiometer for exemple |
mbedalvaro | 0:345b3bc7a0ea | 35 | //or scan the best frequency... |
mbedalvaro | 0:345b3bc7a0ea | 36 | |
mbedalvaro | 0:345b3bc7a0ea | 37 | void setLaserPower(bool power); //change PWM settings to turn on/off the laser |
mbedalvaro | 0:345b3bc7a0ea | 38 | |
mbedalvaro | 0:345b3bc7a0ea | 39 | |
mbedalvaro | 0:345b3bc7a0ea | 40 | float getSmoothValue(); //return the average of the value stored on the buffer |
mbedalvaro | 0:345b3bc7a0ea | 41 | float getLastValue(); //return the last conversion of the ADC |
mbedalvaro | 0:345b3bc7a0ea | 42 | float getMedianValue(); //return the median value of the buffer |
mbedalvaro | 0:345b3bc7a0ea | 43 | //it is just a begining; we can add more complex method for denoising for exemple |
mbedalvaro | 0:345b3bc7a0ea | 44 | //maybe, needs function to start and stop the lockin |
mbedalvaro | 0:345b3bc7a0ea | 45 | |
mbedalvaro | 0:345b3bc7a0ea | 46 | void clearBuffer(); |
mbedalvaro | 0:345b3bc7a0ea | 47 | |
mbedalvaro | 0:345b3bc7a0ea | 48 | //can be private |
mbedalvaro | 0:345b3bc7a0ea | 49 | //void catchInterupt(uint32_t value); |
mbedalvaro | 0:345b3bc7a0ea | 50 | |
mbedalvaro | 0:345b3bc7a0ea | 51 | //variables |
mbedalvaro | 0:345b3bc7a0ea | 52 | float buffer[BUFFER_SIZE]; |
mbedalvaro | 0:345b3bc7a0ea | 53 | int buffer_pos; |
mbedalvaro | 0:345b3bc7a0ea | 54 | |
mbedalvaro | 0:345b3bc7a0ea | 55 | float refFrequency; // frequency of sensing laser and lock-in (in KHz) |
mbedalvaro | 0:345b3bc7a0ea | 56 | //Phase shift of the pwm signals (from 0 to 1): |
mbedalvaro | 0:345b3bc7a0ea | 57 | //it corresponds to a percentage of the half of a period |
mbedalvaro | 0:345b3bc7a0ea | 58 | //(no phase shift ==> 0% / 90deg phase shift ==> 100%) |
mbedalvaro | 0:345b3bc7a0ea | 59 | float phaseShiftLaser; // phase shift of the sensing laser |
mbedalvaro | 0:345b3bc7a0ea | 60 | float phaseShiftLockin; // phase shift of the lock-in reference |
mbedalvaro | 0:345b3bc7a0ea | 61 | |
mbedalvaro | 0:345b3bc7a0ea | 62 | int refFreq; //frequency of the lockin |
mbedalvaro | 0:345b3bc7a0ea | 63 | int offsetRef; //offset between the laser signal and the lockin reference signal |
mbedalvaro | 0:345b3bc7a0ea | 64 | int halfRefFreq; |
mbedalvaro | 0:345b3bc7a0ea | 65 | |
mbedalvaro | 0:345b3bc7a0ea | 66 | private: |
mbedalvaro | 0:345b3bc7a0ea | 67 | // PWM match register value are saved as private |
mbedalvaro | 0:345b3bc7a0ea | 68 | // to avoid computation when turn on/off for exemple |
mbedalvaro | 0:345b3bc7a0ea | 69 | int _currentMR[6]; |
mbedalvaro | 0:345b3bc7a0ea | 70 | |
mbedalvaro | 0:345b3bc7a0ea | 71 | |
mbedalvaro | 0:345b3bc7a0ea | 72 | }; |
mbedalvaro | 0:345b3bc7a0ea | 73 | |
mbedalvaro | 0:345b3bc7a0ea | 74 | extern Lockin lockin; |
mbedalvaro | 0:345b3bc7a0ea | 75 | |
mbedalvaro | 0:345b3bc7a0ea | 76 | #endif |