Laser Sensing Display for UI interfaces in the real world
Fork of skinGames_forktest by
Diff: hardwareIO/lockin.h
- Revision:
- 0:345b3bc7a0ea
- Child:
- 1:a4050fee11f7
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/hardwareIO/lockin.h Wed Mar 28 14:40:01 2012 +0000 @@ -0,0 +1,76 @@ +#ifndef MBED_LOCKIN_H +#define MBED_LOCKIN_H + +#include "mbed.h" +#include "adc.h" + +#define MBEDFREQUENCY 96000 //frequency of the mBed in KHz + +//#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!? + +#define LOCKIN_ADC_PIN p18 //ADC pin : connect to lockin output +#define LOCKIN_LASER_PIN p22 //PWM pin : connect to laser input +#define LOCKIN_REF_PIN p25 //PWM pin : connect to lockin input +// p21 to p25 are used by the PWM timers even if only 2 pin are connected to the circuit + +#define BUFFER_SIZE 15 +#define BUFFER_SIZE_MEDIAN 5 +#define DELAY_BUFFER_MEDIAN 0 + + +class Lockin { +public: + // default constructor (untouched!) + // Lockin(); + + // initialization of object modes (could have parameters): + void init(); + + void initPWM(); //setup the laser and reference signal used by the lockin + void setPWMFrequency(float freq); //change the shared period of the pwm signals + void setLaserPhaseShift(float phaseShift); //change the phase shift of the laser (from 0 to 1) + void setLockinPhaseShift(float phaseShift); //change the phase shift of the lock-in (from 0 to 1) + //future works: + //add function to change frequency or offset with a potentiometer for exemple + //or scan the best frequency... + + void setLaserPower(bool power); //change PWM settings to turn on/off the laser + + + float getSmoothValue(); //return the average of the value stored on the buffer + float getLastValue(); //return the last conversion of the ADC + float getMedianValue(); //return the median value of the buffer + //it is just a begining; we can add more complex method for denoising for exemple + //maybe, needs function to start and stop the lockin + + void clearBuffer(); + + //can be private + //void catchInterupt(uint32_t value); + + //variables + float buffer[BUFFER_SIZE]; + int buffer_pos; + + float refFrequency; // frequency of sensing laser and lock-in (in KHz) + //Phase shift of the pwm signals (from 0 to 1): + //it corresponds to a percentage of the half of a period + //(no phase shift ==> 0% / 90deg phase shift ==> 100%) + float phaseShiftLaser; // phase shift of the sensing laser + float phaseShiftLockin; // phase shift of the lock-in reference + + int refFreq; //frequency of the lockin + int offsetRef; //offset between the laser signal and the lockin reference signal + int halfRefFreq; + +private: + // PWM match register value are saved as private + // to avoid computation when turn on/off for exemple + int _currentMR[6]; + + +}; + +extern Lockin lockin; + +#endif \ No newline at end of file