Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of scoreLight_Advanced by
lockin.h
00001 #ifndef MBED_LOCKIN_H 00002 #define MBED_LOCKIN_H 00003 00004 #include "mbed.h" 00005 #include "adc.h" 00006 00007 #define MBEDFREQUENCY 96000 //frequency of the mBed in KHz 00008 00009 //#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!? 00010 00011 #define LOCKIN_ADC_PIN p18 //ADC pin : connect to lockin "output" 00012 00013 #define LOCKIN_REF_PIN p23 //PWM pin : connect to lockin reference signal. 00014 #define LOCKIN_LASER_PIN p25 //PWM pin : connect to laser control - note: the red laser by default, but could be a fourth IR laser... 00015 // p21 to p26 are used by the PWM timers even if only 2 pin are connected to the circuit 00016 00017 #define BUFFER_SIZE 15 00018 #define BUFFER_SIZE_MEDIAN 5 00019 #define DELAY_BUFFER_MEDIAN 0 00020 00021 00022 class Lockin { 00023 public: 00024 // default constructor (untouched!) 00025 // Lockin(); 00026 00027 // initialization of object modes (could have parameters): 00028 void init(); 00029 00030 void initPWM(); //setup the laser and reference signal used by the lockin 00031 void setPWMFrequency(float freq); //change the shared period of the pwm signals 00032 void setLaserPhaseShift(float phaseShift); //change the phase shift of the laser (from 0 to 1) 00033 void setLockinPhaseShift(float phaseShift); //change the phase shift of the lock-in (from 0 to 1) 00034 //future works: 00035 //add function to change frequency or offset with a potentiometer for exemple 00036 //or scan the best frequency... 00037 00038 void setLaserPower(bool power); //change PWM settings to turn on/off the laser 00039 00040 void setADC_forLockin(int mode); //1 set, 0 reset 00041 00042 unsigned short getSmoothValue(); //return the average of the value stored on the buffer 00043 unsigned short getLastValue(); //return the last conversion of the ADC 00044 unsigned short getMedianValue(); //return the median value of the buffer 00045 //it is just a begining; we can add more complex method for denoising for exemple 00046 //maybe, needs function to start and stop the lockin 00047 00048 void clearBuffer(); 00049 00050 //can be private 00051 //void catchInterupt(uint32_t value); 00052 00053 //variables 00054 unsigned short buffer[BUFFER_SIZE]; // does not need to be a float - in fact values are from 0 to 4096 (i.e., 00055 //unsigned short int buffer[BUFFER_SIZE]; // this is two bytes (0 to 65535) 00056 unsigned short orderedBuffer[BUFFER_SIZE_MEDIAN]; // for computation of the MEDIAN value 00057 int buffer_pos; 00058 00059 float refFrequency; // frequency of sensing laser and lock-in (in KHz) 00060 //Phase shift of the pwm signals (from 0 to 1): 00061 //it corresponds to a percentage of the half of a period 00062 //(no phase shift ==> 0% / 90deg phase shift ==> 100%) 00063 float phaseShiftLaser; // phase shift of the sensing laser 00064 float phaseShiftLockin; // phase shift of the lock-in reference 00065 00066 int refFreq; //frequency of the lockin 00067 int offsetRef; //offset between the laser signal and the lockin reference signal 00068 int halfRefFreq; 00069 00070 private: 00071 // PWM match register value are saved as private 00072 // to avoid computation when turn on/off for exemple 00073 int _currentMR[6]; 00074 00075 00076 }; 00077 00078 extern Lockin lockin; 00079 00080 #endif
Generated on Tue Jul 12 2022 18:50:27 by
1.7.2
