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
mbedalvaro 0:c19dc1d8b225 2 #ifndef hardwareIO_h
mbedalvaro 0:c19dc1d8b225 3 #define hardwareIO_h
mbedalvaro 0:c19dc1d8b225 4
mbedalvaro 0:c19dc1d8b225 5 #include "mbed.h"
mbedalvaro 0:c19dc1d8b225 6 #include "lockin.h"
mbedalvaro 0:c19dc1d8b225 7
mbedalvaro 0:c19dc1d8b225 8
mbedalvaro 0:c19dc1d8b225 9 // 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.
mbedalvaro 0:c19dc1d8b225 10 #define SCK_PIN p7 //SPI Clock
mbedalvaro 0:c19dc1d8b225 11 #define MISO_PIN p6 //SPI input (data comming from DAC, here not connected)
mbedalvaro 0:c19dc1d8b225 12 #define MOSI_PIN p5 //SPI output (data going to DAC)
mbedalvaro 0:c19dc1d8b225 13
mbedalvaro 0:c19dc1d8b225 14 //**** CHIP SELECT pins for MP4922 DAC (mirrors and red laser)
mbedalvaro 0:c19dc1d8b225 15 // VERY IMPORTANT: the chip select for the DACs should be different from the default SPI "SS" pin (Slave Select), which is 53 by default (and will be used by the Ethernet Shield).
mbedalvaro 0:c19dc1d8b225 16 #define CS_DAC_MIRRORS p8 //Chip Select of the first DAC (mirrors)
mbedalvaro 0:c19dc1d8b225 17
mbedalvaro 0:c19dc1d8b225 18 //**** LASERS pins:
mbedalvaro 0:c19dc1d8b225 19 #define LASER_RED_PIN p28
mbedalvaro 0:c19dc1d8b225 20 #define LASER_GREEN_PIN p29
mbedalvaro 0:c19dc1d8b225 21 #define LASER_BLUE_PIN p30
mbedalvaro 0:c19dc1d8b225 22
mbedalvaro 0:c19dc1d8b225 23 //**** MIRRORS:
mbedalvaro 0:c19dc1d8b225 24 //The DAC is 12 bytes capable (Max=4096), but we will limit this a little.
mbedalvaro 0:c19dc1d8b225 25 #define MAX_AD_MIRRORS 4095 // 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.
mbedalvaro 0:c19dc1d8b225 26 #define MIN_AD_MIRRORS 0
mbedalvaro 0:c19dc1d8b225 27 // We assume that the center of the mirror is at MAX_AD_MIRRORS/2 = 2000:
mbedalvaro 0:c19dc1d8b225 28 #define CENTER_AD_MIRROR_X 2047 // This MUST BE the direction of the photodetector.
mbedalvaro 0:c19dc1d8b225 29 #define CENTER_AD_MIRROR_Y 2047 // This MUST BE the direction of the photodetector.
mbedalvaro 0:c19dc1d8b225 30
mbedalvaro 0:c19dc1d8b225 31
mbedalvaro 0:c19dc1d8b225 32 // **** REFERENCE SIGNAL:
mbedalvaro 0:c19dc1d8b225 33 /*
mbedalvaro 0:c19dc1d8b225 34 #define testPin_OC1A 11 // this is, output compare pin OC1A //connected to CK2 = lockIn clock
mbedalvaro 0:c19dc1d8b225 35 #define testPin_OC1B 12 // this is, output compare pin OC1B //connected to CK1 = laser clock
mbedalvaro 0:c19dc1d8b225 36 #define testPin_OC1C 13
mbedalvaro 0:c19dc1d8b225 37 */
mbedalvaro 0:c19dc1d8b225 38
mbedalvaro 0:c19dc1d8b225 39 // ==================================================================================================================================================================
mbedalvaro 0:c19dc1d8b225 40
mbedalvaro 0:c19dc1d8b225 41 class HardwareIO {
mbedalvaro 0:c19dc1d8b225 42 public:
mbedalvaro 0:c19dc1d8b225 43
mbedalvaro 0:c19dc1d8b225 44
mbedalvaro 0:c19dc1d8b225 45 void init(void);
mbedalvaro 0:c19dc1d8b225 46
mbedalvaro 0:c19dc1d8b225 47 float LockInRead_Volts();
mbedalvaro 0:c19dc1d8b225 48 int LockInRead_AD();
mbedalvaro 0:c19dc1d8b225 49 float LockInAD_to_Volts(int);
mbedalvaro 0:c19dc1d8b225 50
mbedalvaro 0:c19dc1d8b225 51 // SPI control for DAC for mirrors and red laser power (low level):
mbedalvaro 0:c19dc1d8b225 52 void writeOutX(int value);
mbedalvaro 0:c19dc1d8b225 53 void writeOutY(int value);
mbedalvaro 0:c19dc1d8b225 54
mbedalvaro 0:c19dc1d8b225 55 // mirror degree-to-AD units conversion factors:
mbedalvaro 0:c19dc1d8b225 56 //float AD_to_Deg_MIRROR_X;//=1.0*(MAX_DEG_MIRROR_X-MIN_DEG_MIRROR_X)/(MAX_AD_MIRRORS-MIN_AD_MIRRORS);
mbedalvaro 0:c19dc1d8b225 57 //float AD_to_Deg_MIRROR_Y;//=1.0*(MAX_DEG_MIRROR_Y-MIN_DEG_MIRROR_Y)/(MAX_AD_MIRRORS-MIN_AD_MIRRORS);
mbedalvaro 0:c19dc1d8b225 58
mbedalvaro 0:c19dc1d8b225 59 /*
mbedalvaro 0:c19dc1d8b225 60 // Mirror position:
mbedalvaro 0:c19dc1d8b225 61 void setMirrorX_Deg(float _Az);
mbedalvaro 0:c19dc1d8b225 62 void setMirrorY_Deg(float _El);
mbedalvaro 0:c19dc1d8b225 63 void setMirrorX_AD(int _AzAD);
mbedalvaro 0:c19dc1d8b225 64 void setMirrorY_AD(int _ElAD);
mbedalvaro 0:c19dc1d8b225 65 void setMirrorsXY_AD(int _xAD, int _yAD);
mbedalvaro 0:c19dc1d8b225 66 void setMirrorsCenter();
mbedalvaro 0:c19dc1d8b225 67 void getAnglesFromAD(float &Az, float &El, int _xAD, int _yAD);
mbedalvaro 0:c19dc1d8b225 68 //void setZoneDelimiters(...) // this could be here, instead on the LivingSpot class
mbedalvaro 0:c19dc1d8b225 69 */
mbedalvaro 0:c19dc1d8b225 70
mbedalvaro 0:c19dc1d8b225 71
mbedalvaro 0:c19dc1d8b225 72 //Laser Power, for the moment laser are TTL but we can use int:
mbedalvaro 0:c19dc1d8b225 73 //if powerValue > 0 ==> 'true'; else 'false'
mbedalvaro 0:c19dc1d8b225 74 // Red laser:
mbedalvaro 0:c19dc1d8b225 75 void setRedPower(int powerRed);
mbedalvaro 0:c19dc1d8b225 76 // Green laser:
mbedalvaro 0:c19dc1d8b225 77 void setGreenPower(int powerGreen);
mbedalvaro 0:c19dc1d8b225 78 // Blue laser:
mbedalvaro 0:c19dc1d8b225 79 void setBluePower(int powerBlue);
mbedalvaro 0:c19dc1d8b225 80
mbedalvaro 0:c19dc1d8b225 81
mbedalvaro 0:c19dc1d8b225 82 //void setupPWM();
mbedalvaro 0:c19dc1d8b225 83 /* IN ADVANCED HARDWARE:
mbedalvaro 0:c19dc1d8b225 84 // init PWM for reference generation:
mbedalvaro 0:c19dc1d8b225 85 void initPWM();
mbedalvaro 0:c19dc1d8b225 86 // reference signal:
mbedalvaro 0:c19dc1d8b225 87 void setRefFreq(int);
mbedalvaro 0:c19dc1d8b225 88 void incRefFreq(int inc=1);
mbedalvaro 0:c19dc1d8b225 89 void decRefFreq(int dec=1);
mbedalvaro 0:c19dc1d8b225 90 */
mbedalvaro 0:c19dc1d8b225 91
mbedalvaro 0:c19dc1d8b225 92 //float refFreq; // could be private
mbedalvaro 0:c19dc1d8b225 93
mbedalvaro 0:c19dc1d8b225 94
mbedalvaro 0:c19dc1d8b225 95 private:
mbedalvaro 0:c19dc1d8b225 96
mbedalvaro 0:c19dc1d8b225 97 };
mbedalvaro 0:c19dc1d8b225 98
mbedalvaro 0:c19dc1d8b225 99
mbedalvaro 0:c19dc1d8b225 100 extern HardwareIO IO; // allows the object IO to be used in other .cpp files (IO is pre-instantiated in hardwareIO.cpp)
mbedalvaro 0:c19dc1d8b225 101 // 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)
mbedalvaro 0:c19dc1d8b225 102 extern Serial pc; // allows pc to be manipulated by other .cpp files, even if pc is defined in the hardwareIO.cpp
mbedalvaro 0:c19dc1d8b225 103
mbedalvaro 0:c19dc1d8b225 104
mbedalvaro 0:c19dc1d8b225 105 #endif