Hardware IO control: mirrors, lock in

Committer:
mbedalvaro
Date:
Mon Oct 17 13:23:06 2011 +0000
Revision:
0:c19dc1d8b225
I wonder if perhaps it would be better to avoid a hardwareIO object, and instead have a set of global hardware functions... I think I will do this in the next revisions of this library

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbedalvaro 0:c19dc1d8b225 1 #ifndef MBED_LOCKIN_H
mbedalvaro 0:c19dc1d8b225 2 #define MBED_LOCKIN_H
mbedalvaro 0:c19dc1d8b225 3
mbedalvaro 0:c19dc1d8b225 4 #include "mbed.h"
mbedalvaro 0:c19dc1d8b225 5 #include "adc.h"
mbedalvaro 0:c19dc1d8b225 6
mbedalvaro 0:c19dc1d8b225 7 #define MBEDFREQUENCY 96000 //frequency of the mBed in KHz
mbedalvaro 0:c19dc1d8b225 8
mbedalvaro 0:c19dc1d8b225 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:c19dc1d8b225 10
mbedalvaro 0:c19dc1d8b225 11 #define LOCKIN_ADC_PIN p18 //ADC pin : connect to lockin output
mbedalvaro 0:c19dc1d8b225 12 #define LOCKIN_LASER_PIN p22 //PWM pin : connect to laser input
mbedalvaro 0:c19dc1d8b225 13 #define LOCKIN_REF_PIN p25 //PWM pin : connect to lockin input
mbedalvaro 0:c19dc1d8b225 14 // p21 to p25 are used by the PWM timers even if only 2 pin are connected to the circuit
mbedalvaro 0:c19dc1d8b225 15
mbedalvaro 0:c19dc1d8b225 16 #define BUFFER_SIZE 3
mbedalvaro 0:c19dc1d8b225 17
mbedalvaro 0:c19dc1d8b225 18
mbedalvaro 0:c19dc1d8b225 19 class Lockin {
mbedalvaro 0:c19dc1d8b225 20 public:
mbedalvaro 0:c19dc1d8b225 21 // default constructor (untouched!)
mbedalvaro 0:c19dc1d8b225 22 // Lockin();
mbedalvaro 0:c19dc1d8b225 23
mbedalvaro 0:c19dc1d8b225 24 // initialization of object modes (could have parameters):
mbedalvaro 0:c19dc1d8b225 25 void init();
mbedalvaro 0:c19dc1d8b225 26
mbedalvaro 0:c19dc1d8b225 27 void initPWM(); //setup the laser and reference signal used by the lockin
mbedalvaro 0:c19dc1d8b225 28 void setPWMFrequency(float freq); //change the shared period of the pwm signals
mbedalvaro 0:c19dc1d8b225 29 void setLaserPhaseShift(float phaseShift); //change the phase shift of the laser (from 0 to 1)
mbedalvaro 0:c19dc1d8b225 30 void setLockinPhaseShift(float phaseShift); //change the phase shift of the lock-in (from 0 to 1)
mbedalvaro 0:c19dc1d8b225 31 //future works:
mbedalvaro 0:c19dc1d8b225 32 //add function to change frequency or offset with a potentiometer for exemple
mbedalvaro 0:c19dc1d8b225 33 //or scan the best frequency...
mbedalvaro 0:c19dc1d8b225 34
mbedalvaro 0:c19dc1d8b225 35 void setLaserPower(bool power); //change PWM settings to turn on/off the laser
mbedalvaro 0:c19dc1d8b225 36
mbedalvaro 0:c19dc1d8b225 37
mbedalvaro 0:c19dc1d8b225 38 float getSmoothValue(); //return the average of the value stored on the buffer
mbedalvaro 0:c19dc1d8b225 39 float getLastValue(); //return the last conversion of the ADC
mbedalvaro 0:c19dc1d8b225 40 //it is just a begining; we can add more complex method for denoising for exemple
mbedalvaro 0:c19dc1d8b225 41 //maybe, needs function to start and stop the lockin
mbedalvaro 0:c19dc1d8b225 42
mbedalvaro 0:c19dc1d8b225 43 void clearBuffer();
mbedalvaro 0:c19dc1d8b225 44
mbedalvaro 0:c19dc1d8b225 45 //can be private
mbedalvaro 0:c19dc1d8b225 46 //void catchInterupt(uint32_t value);
mbedalvaro 0:c19dc1d8b225 47
mbedalvaro 0:c19dc1d8b225 48 //variables
mbedalvaro 0:c19dc1d8b225 49 float buffer[BUFFER_SIZE];
mbedalvaro 0:c19dc1d8b225 50 int buffer_pos;
mbedalvaro 0:c19dc1d8b225 51
mbedalvaro 0:c19dc1d8b225 52 float refFrequency; // frequency of sensing laser and lock-in (in KHz)
mbedalvaro 0:c19dc1d8b225 53 //Phase shift of the pwm signals (from 0 to 1):
mbedalvaro 0:c19dc1d8b225 54 //it corresponds to a percentage of the half of a period
mbedalvaro 0:c19dc1d8b225 55 //(no phase shift ==> 0% / 90deg phase shift ==> 100%)
mbedalvaro 0:c19dc1d8b225 56 float phaseShiftLaser; // phase shift of the sensing laser
mbedalvaro 0:c19dc1d8b225 57 float phaseShiftLockin; // phase shift of the lock-in reference
mbedalvaro 0:c19dc1d8b225 58
mbedalvaro 0:c19dc1d8b225 59 int refFreq; //frequency of the lockin
mbedalvaro 0:c19dc1d8b225 60 int offsetRef; //offset between the laser signal and the lockin reference signal
mbedalvaro 0:c19dc1d8b225 61 int halfRefFreq;
mbedalvaro 0:c19dc1d8b225 62
mbedalvaro 0:c19dc1d8b225 63 private:
mbedalvaro 0:c19dc1d8b225 64 // PWM match register value are saved as private
mbedalvaro 0:c19dc1d8b225 65 // to avoid computation when turn on/off for exemple
mbedalvaro 0:c19dc1d8b225 66 int _currentMR[6];
mbedalvaro 0:c19dc1d8b225 67
mbedalvaro 0:c19dc1d8b225 68
mbedalvaro 0:c19dc1d8b225 69 };
mbedalvaro 0:c19dc1d8b225 70
mbedalvaro 0:c19dc1d8b225 71 extern Lockin lockin;
mbedalvaro 0:c19dc1d8b225 72
mbedalvaro 0:c19dc1d8b225 73 #endif