Hardware IO control: mirrors, lock in
Diff: lockin.h
- Revision:
- 0:c19dc1d8b225
diff -r 000000000000 -r c19dc1d8b225 lockin.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lockin.h Mon Oct 17 13:23:06 2011 +0000 @@ -0,0 +1,73 @@ +#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 3 + + +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 + //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