Alvaro Cassinelli
/
skinGames_II
save loops
Embed:
(wiki syntax)
Show/hide line numbers
hardwareIO.h
00001 00002 #ifndef hardwareIO_h 00003 #define hardwareIO_h 00004 00005 #include "mbed.h" 00006 #include "lockin.h" 00007 #include "CRotaryEncoder.h" 00008 00009 00010 // potentiometer to change sensitivity by hand, or other things... ACTUALLY THIS IS NOT WORKING because I cannot switch back and forth from 00011 // burst mode of analog conversion and "normal" one. Better use a rotary encoder!! 00012 #define POT_ANALOG_INPUT p15 // note: analog inputs in the mbed are from 15 to 20 00013 00014 // Momentary switches triggering INTERRUPT functions: 00015 // (Any of the numbered mbed pins can be used as an InterruptIn, except p19 and p20) 00016 // NOTE: do not use pins from p21 to p26 because they are all set as pwm output (see lockin.h) 00017 #define LED_SWITCH_ONE p9 // digital output pin 00018 #define SWITCH_ONE p10 // interrupt pin 00019 #define SWITCH_TWO p11 // interrupt pin 00020 00021 // Two state switch: 00022 #define TWO_STATE_SWITCH p12 00023 00024 // NOTE: the SPI library uses the following pins, but we don't have to set them and inputs or outputs (this is done when the library is initialized, which is done by pre-instantiation. 00025 #define SCK_PIN p7 //SPI Clock 00026 #define MISO_PIN p6 //SPI input (data comming from DAC, here not connected) 00027 #define MOSI_PIN p5 //SPI output (data going to DAC) 00028 00029 //**** CHIP SELECT pins for MP4922 DAC (mirrors and red laser) 00030 #define CS_DAC_MIRRORS p8 00031 00032 //**** LASERS pins: 00033 #define LASER_RED_PIN p28 // NOT YET USED!! (NOTE: this is NOT the locking sensing laser (also called red, but could be infrared...) 00034 #define LASER_GREEN_PIN p29 // USED (TTL control) 00035 #define LASER_BLUE_PIN p30 // USED (TTL control) 00036 00037 //**** MIRRORS: 00038 //The DAC is 12 bytes capable (Max=4096), but we will limit this a little. 00039 #define MAX_AD_MIRRORS 4000//3845 // note: 4095 is the absolute maximum for the SPI voltage (5V). This is for checking hardware compliance, but max and min angles can be defined for X and Y in each LivingSpot instance. 00040 #define MIN_AD_MIRRORS 155//250 // note: 0 is 0 volts for the SPI voltage. 00041 // We assume that the center of the mirror is at MAX_AD_MIRRORS/2 = 2000: 00042 #define CENTER_AD_MIRROR_X 2047 // This MUST BE the direction of the photodetector. 00043 #define CENTER_AD_MIRROR_Y 2047 // This MUST BE the direction of the photodetector. 00044 00045 00046 //**** Look-Up Table: 00047 #define uint16 unsigned short 00048 #define LUT_RESOLUTION 33 // resolution of the Look-Up Table (power of 2 +1) 00049 #define LUT_BITS_SHIFT 7 // bits shift from mirror DAC (12 bits) to LUT ( root_square(LUT_RESOLUTION - 1) ) 00050 #define LUT_BITS_MASK 127 // bits mask to obtain the position remainder ( 2^LUT_BITS_SHIFT - 1 ) 00051 // possible configurations: 00052 // LUT_RESOLUTION LUT_BITS_SHIFT LUT_BITS_MASK 00053 // 9 9 511 00054 // 17 8 255 00055 // 33 7 127 00056 // 65 6 63 00057 // ... 00058 #define NB_SCANS 8 // number of scans performed to generate the LUT table (actually, each site CUMULATES NB_SCANS values) 00059 // IMPORTANT: NB_SCANS*4095 should not exceed the capacity of uint16, this is 2^16-1=65535. 00060 // In other terms, NB_SCANS should be < 65535/4095=16 00061 00062 #define LUT_FILENAME "/local/LUT.txt" 00063 00064 // For checking (define if human readable file is required - note: it is not used by the program, just as output for human reading) 00065 #define LUT_H_FILENAME "/local/LUT_pos.txt" 00066 00067 // Current Look-up table approximation (only one at a time!): 00068 //#define LUT_BILINEAR 00069 //#define LUT_DIRECT 00070 //#define LUT_LINEAR 00071 #define NO_LUT 00072 00073 //Current method for lockin data acquisition and correction 00074 #define lockin_read() lockin.getMedianValue() // lockin.getSmoothValue(); //return the average of the value stored on the buffer 00075 // lockin.getLastValue(); //return the last conversion of the ADC 00076 // lockin.getMedianValue(); //return the median value of the buffer 00077 00078 00079 00080 // **** REFERENCE SIGNAL: 00081 /* 00082 #define testPin_OC1A 11 // this is, output compare pin OC1A //connected to CK2 = lockIn clock 00083 #define testPin_OC1B 12 // this is, output compare pin OC1B //connected to CK1 = laser clock 00084 #define testPin_OC1C 13 00085 */ 00086 00087 // ================================================================================================================================================================== 00088 00089 class HardwareIO { 00090 public: 00091 00092 00093 void init(void); 00094 00095 //Lock-in acquisition methods: 00096 // float LockInRead_Volts(); 00097 // int LockInRead_AD(); 00098 // float LockInAD_to_Volts(int); 00099 00100 //Look-Up Table: 00101 unsigned short lut[LUT_RESOLUTION][LUT_RESOLUTION]; //Look-Up Table (uint16 is "unsigned short") 00102 void scanLUT(); //create and save the Look-Up Table 00103 void setLUT(); //set the Look-Up Table: either from scanning, or from the file LUT.TXT (if it is present) 00104 float lockInCorrectedValue(unsigned short x, unsigned short y); //return the lockin value corrected with the Look-UpTable (this is, a RATIO of reflectivities, and <1) 00105 00106 void scan_serial(unsigned short pointsPerLine = 400); 00107 00108 void showLimitsMirrors( int times ); 00109 00110 // SPI control for DAC for mirrors and red laser power (low level): 00111 void writeOutX(unsigned short value); 00112 void writeOutY(unsigned short value); 00113 00114 // mirror degree-to-AD units conversion factors: 00115 //float AD_to_Deg_MIRROR_X;//=1.0*(MAX_DEG_MIRROR_X-MIN_DEG_MIRROR_X)/(MAX_AD_MIRRORS-MIN_AD_MIRRORS); 00116 //float AD_to_Deg_MIRROR_Y;//=1.0*(MAX_DEG_MIRROR_Y-MIN_DEG_MIRROR_Y)/(MAX_AD_MIRRORS-MIN_AD_MIRRORS); 00117 00118 /* 00119 // Mirror position: 00120 void setMirrorX_Deg(float _Az); 00121 void setMirrorY_Deg(float _El); 00122 void setMirrorX_AD(int _AzAD); 00123 void setMirrorY_AD(int _ElAD); 00124 void setMirrorsXY_AD(int _xAD, int _yAD); 00125 void setMirrorsCenter(); 00126 void getAnglesFromAD(float &Az, float &El, int _xAD, int _yAD); 00127 //void setZoneDelimiters(...) // this could be here, instead on the LivingSpot class 00128 */ 00129 00130 00131 //Laser Power, for the moment laser are TTL but we can use int: 00132 //if powerValue > 0 ==> 'true'; else 'false' 00133 void setLaserLockinPower(int powerLockingLaser); 00134 // Red laser (not used) 00135 void setRedPower(int powerRed); 00136 // Green laser: 00137 void setGreenPower(int powerGreen); 00138 // Blue laser: 00139 void setBluePower(int powerBlue); 00140 00141 void setRGBPower(unsigned char color); // we will use the 3 LSB bits to set each color, note that here the "red" is the LOCKIN LASER 00142 00143 //void setupPWM(); 00144 /* IN ADVANCED HARDWARE: 00145 // init PWM for reference generation: 00146 void initPWM(); 00147 // reference signal: 00148 void setRefFreq(int); 00149 void incRefFreq(int inc=1); 00150 void decRefFreq(int dec=1); 00151 */ 00152 00153 //float refFreq; // could be private 00154 00155 // Interrupt "momentary" switches: 00156 bool switchOneState, switchTwoState; 00157 bool switchOneChange, switchTwoChange; 00158 void switchOneInterrupt(); 00159 void switchTwoInterrupt(); 00160 bool switchOneCheck(bool& state); 00161 bool switchTwoCheck(bool& state); 00162 void setSwitchOneState(bool newstate); 00163 00164 // two state switch: 00165 bool twoStateSwitchState; 00166 bool twoStateSwitchChange; 00167 bool twoStateSwitchCheck(bool& stateswitch); 00168 00169 // Potentiometer (does not work!!) 00170 unsigned char updatePotValue(); // the value will be ajusted in the range 0-255 00171 unsigned char potValue; 00172 00173 private: 00174 //DigitalOut Laser_Red, Laser_Green, Laser_Blue; 00175 00176 }; 00177 00178 00179 extern HardwareIO IO; // allows the object IO to be used in other .cpp files (IO is pre-instantiated in hardwareIO.cpp) 00180 // NOTE: IO encapsulates many IO functions, but perhaps it is better not to have an IO object - just use each IO function separatedly (as with pc object for instance) 00181 extern Serial pc; // allows pc to be manipulated by other .cpp files, even if pc is defined in the hardwareIO.cpp 00182 00183 00184 #endif
Generated on Tue Jul 12 2022 21:23:04 by 1.7.2