Laser Sensing Display for UI interfaces in the real world
Fork of skinGames_forktest by
hardwareIO/lockin.h@31:5f039cbddee8, 2012-09-23 (annotated)
- Committer:
- mbedalvaro
- Date:
- Sun Sep 23 10:11:43 2012 +0000
- Revision:
- 31:5f039cbddee8
- Child:
- 34:1244fa3f2559
this is quite nice, but I am going to make a deep modification of the bouncing principle: instead of depending on the penetration, it will just be a factor over the speed (perfect elastic bouncing being factorElastic=1, and perfectly absorption=0);
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mbedalvaro | 31:5f039cbddee8 | 1 | #ifndef MBED_LOCKIN_H |
mbedalvaro | 31:5f039cbddee8 | 2 | #define MBED_LOCKIN_H |
mbedalvaro | 31:5f039cbddee8 | 3 | |
mbedalvaro | 31:5f039cbddee8 | 4 | #include "mbed.h" |
mbedalvaro | 31:5f039cbddee8 | 5 | #include "adc.h" |
mbedalvaro | 31:5f039cbddee8 | 6 | |
mbedalvaro | 31:5f039cbddee8 | 7 | #define MBEDFREQUENCY 96000 //frequency of the mBed in KHz |
mbedalvaro | 31:5f039cbddee8 | 8 | |
mbedalvaro | 31:5f039cbddee8 | 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 | 31:5f039cbddee8 | 10 | |
mbedalvaro | 31:5f039cbddee8 | 11 | #define LOCKIN_ADC_PIN p18 //ADC pin : connect to lockin "output" |
mbedalvaro | 31:5f039cbddee8 | 12 | |
mbedalvaro | 31:5f039cbddee8 | 13 | #define LOCKIN_REF_PIN p23 //PWM pin : connect to lockin reference signal. |
mbedalvaro | 31:5f039cbddee8 | 14 | #define LOCKIN_LASER_PIN p25 //PWM pin : connect to laser control - note: the red laser by default, but could be a fourth IR laser... |
mbedalvaro | 31:5f039cbddee8 | 15 | // p21 to p25 are used by the PWM timers even if only 2 pin are connected to the circuit |
mbedalvaro | 31:5f039cbddee8 | 16 | |
mbedalvaro | 31:5f039cbddee8 | 17 | #define BUFFER_SIZE 15 |
mbedalvaro | 31:5f039cbddee8 | 18 | #define BUFFER_SIZE_MEDIAN 5 |
mbedalvaro | 31:5f039cbddee8 | 19 | #define DELAY_BUFFER_MEDIAN 0 |
mbedalvaro | 31:5f039cbddee8 | 20 | |
mbedalvaro | 31:5f039cbddee8 | 21 | |
mbedalvaro | 31:5f039cbddee8 | 22 | class Lockin { |
mbedalvaro | 31:5f039cbddee8 | 23 | public: |
mbedalvaro | 31:5f039cbddee8 | 24 | // default constructor (untouched!) |
mbedalvaro | 31:5f039cbddee8 | 25 | // Lockin(); |
mbedalvaro | 31:5f039cbddee8 | 26 | |
mbedalvaro | 31:5f039cbddee8 | 27 | // initialization of object modes (could have parameters): |
mbedalvaro | 31:5f039cbddee8 | 28 | void init(); |
mbedalvaro | 31:5f039cbddee8 | 29 | |
mbedalvaro | 31:5f039cbddee8 | 30 | void initPWM(); //setup the laser and reference signal used by the lockin |
mbedalvaro | 31:5f039cbddee8 | 31 | void setPWMFrequency(float freq); //change the shared period of the pwm signals |
mbedalvaro | 31:5f039cbddee8 | 32 | void setLaserPhaseShift(float phaseShift); //change the phase shift of the laser (from 0 to 1) |
mbedalvaro | 31:5f039cbddee8 | 33 | void setLockinPhaseShift(float phaseShift); //change the phase shift of the lock-in (from 0 to 1) |
mbedalvaro | 31:5f039cbddee8 | 34 | //future works: |
mbedalvaro | 31:5f039cbddee8 | 35 | //add function to change frequency or offset with a potentiometer for exemple |
mbedalvaro | 31:5f039cbddee8 | 36 | //or scan the best frequency... |
mbedalvaro | 31:5f039cbddee8 | 37 | |
mbedalvaro | 31:5f039cbddee8 | 38 | void setLaserPower(bool power); //change PWM settings to turn on/off the laser |
mbedalvaro | 31:5f039cbddee8 | 39 | |
mbedalvaro | 31:5f039cbddee8 | 40 | |
mbedalvaro | 31:5f039cbddee8 | 41 | unsigned short getSmoothValue(); //return the average of the value stored on the buffer |
mbedalvaro | 31:5f039cbddee8 | 42 | unsigned short getLastValue(); //return the last conversion of the ADC |
mbedalvaro | 31:5f039cbddee8 | 43 | unsigned short getMedianValue(); //return the median value of the buffer |
mbedalvaro | 31:5f039cbddee8 | 44 | //it is just a begining; we can add more complex method for denoising for exemple |
mbedalvaro | 31:5f039cbddee8 | 45 | //maybe, needs function to start and stop the lockin |
mbedalvaro | 31:5f039cbddee8 | 46 | |
mbedalvaro | 31:5f039cbddee8 | 47 | void clearBuffer(); |
mbedalvaro | 31:5f039cbddee8 | 48 | |
mbedalvaro | 31:5f039cbddee8 | 49 | //can be private |
mbedalvaro | 31:5f039cbddee8 | 50 | //void catchInterupt(uint32_t value); |
mbedalvaro | 31:5f039cbddee8 | 51 | |
mbedalvaro | 31:5f039cbddee8 | 52 | //variables |
mbedalvaro | 31:5f039cbddee8 | 53 | unsigned short buffer[BUFFER_SIZE]; // does not need to be a float - in fact values are from 0 to 4096 (i.e., |
mbedalvaro | 31:5f039cbddee8 | 54 | //unsigned short int buffer[BUFFER_SIZE]; // this is two bytes (0 to 65535) |
mbedalvaro | 31:5f039cbddee8 | 55 | unsigned short orderedBuffer[BUFFER_SIZE_MEDIAN]; // for computation of the MEDIAN value |
mbedalvaro | 31:5f039cbddee8 | 56 | int buffer_pos; |
mbedalvaro | 31:5f039cbddee8 | 57 | |
mbedalvaro | 31:5f039cbddee8 | 58 | float refFrequency; // frequency of sensing laser and lock-in (in KHz) |
mbedalvaro | 31:5f039cbddee8 | 59 | //Phase shift of the pwm signals (from 0 to 1): |
mbedalvaro | 31:5f039cbddee8 | 60 | //it corresponds to a percentage of the half of a period |
mbedalvaro | 31:5f039cbddee8 | 61 | //(no phase shift ==> 0% / 90deg phase shift ==> 100%) |
mbedalvaro | 31:5f039cbddee8 | 62 | float phaseShiftLaser; // phase shift of the sensing laser |
mbedalvaro | 31:5f039cbddee8 | 63 | float phaseShiftLockin; // phase shift of the lock-in reference |
mbedalvaro | 31:5f039cbddee8 | 64 | |
mbedalvaro | 31:5f039cbddee8 | 65 | int refFreq; //frequency of the lockin |
mbedalvaro | 31:5f039cbddee8 | 66 | int offsetRef; //offset between the laser signal and the lockin reference signal |
mbedalvaro | 31:5f039cbddee8 | 67 | int halfRefFreq; |
mbedalvaro | 31:5f039cbddee8 | 68 | |
mbedalvaro | 31:5f039cbddee8 | 69 | private: |
mbedalvaro | 31:5f039cbddee8 | 70 | // PWM match register value are saved as private |
mbedalvaro | 31:5f039cbddee8 | 71 | // to avoid computation when turn on/off for exemple |
mbedalvaro | 31:5f039cbddee8 | 72 | int _currentMR[6]; |
mbedalvaro | 31:5f039cbddee8 | 73 | |
mbedalvaro | 31:5f039cbddee8 | 74 | |
mbedalvaro | 31:5f039cbddee8 | 75 | }; |
mbedalvaro | 31:5f039cbddee8 | 76 | |
mbedalvaro | 31:5f039cbddee8 | 77 | extern Lockin lockin; |
mbedalvaro | 31:5f039cbddee8 | 78 | |
mbedalvaro | 31:5f039cbddee8 | 79 | #endif |