Laser Sensing Display for UI interfaces in the real world

Dependencies:   mbed

Fork of skinGames_forktest by Alvaro Cassinelli

Committer:
mbedalvaro
Date:
Thu Apr 17 08:04:14 2014 +0000
Revision:
47:199042980678
Parent:
41:74e24a0e6e50
publishing for sharing with Ken Iwasaki

Who changed what in which revision?

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