Hardware control: mirrors

Committer:
mbedalvaro
Date:
Fri Sep 07 06:41:01 2012 +0000
Revision:
2:b8673fcb3800
Parent:
hardwareIO.h@1:b1f5ed22087a
this is a simple library to control a simple laser projector: control three lasers (TTL) and two galvano mirrors, through a pair of DAC

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbedalvaro 0:3fe2fe307968 1
mbedalvaro 0:3fe2fe307968 2 #ifndef hardwareIO_h
mbedalvaro 0:3fe2fe307968 3 #define hardwareIO_h
mbedalvaro 0:3fe2fe307968 4
mbedalvaro 0:3fe2fe307968 5 #include "mbed.h"
mbedalvaro 0:3fe2fe307968 6
mbedalvaro 0:3fe2fe307968 7
mbedalvaro 1:b1f5ed22087a 8 //SPI library (for ADC chip) uses the following pins, but we don't have to set them and inputs or outputs
mbedalvaro 1:b1f5ed22087a 9 // (this is done when the library is initialized, which is done by pre-instantiation:
mbedalvaro 0:3fe2fe307968 10 #define SCK_PIN p7 //SPI Clock
mbedalvaro 0:3fe2fe307968 11 #define MISO_PIN p6 //SPI input (data comming from DAC, here not connected)
mbedalvaro 0:3fe2fe307968 12 #define MOSI_PIN p5 //SPI output (data going to DAC)
mbedalvaro 0:3fe2fe307968 13
mbedalvaro 0:3fe2fe307968 14 //**** CHIP SELECT pins for MP4922 DAC (mirrors and red laser)
mbedalvaro 0:3fe2fe307968 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:3fe2fe307968 16 #define CS_DAC_MIRRORS p8 //Chip Select of the first DAC (mirrors)
mbedalvaro 0:3fe2fe307968 17
mbedalvaro 0:3fe2fe307968 18 //**** LASERS pins:
mbedalvaro 1:b1f5ed22087a 19 #define LASER_RED_PIN p28 // NOT YET USED (TTL control). NOTE: this is NOT the locking sensing laser!
mbedalvaro 0:3fe2fe307968 20 #define LASER_GREEN_PIN p29 // USED (TTL control)
mbedalvaro 0:3fe2fe307968 21 #define LASER_BLUE_PIN p30 // USED (TTL control)
mbedalvaro 0:3fe2fe307968 22
mbedalvaro 0:3fe2fe307968 23 //**** MIRRORS:
mbedalvaro 0:3fe2fe307968 24 //The DAC is 12 bytes capable (Max=4096), but we will limit this a little.
mbedalvaro 0:3fe2fe307968 25 #define MAX_AD_MIRRORS 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.
mbedalvaro 0:3fe2fe307968 26 #define MIN_AD_MIRRORS 250 // note: 0 is 0 volts for the SPI voltage.
mbedalvaro 0:3fe2fe307968 27 // We assume that the center of the mirror is at MAX_AD_MIRRORS/2 = 2000:
mbedalvaro 0:3fe2fe307968 28 #define CENTER_AD_MIRROR_X 2047 // This MUST BE the direction of the photodetector.
mbedalvaro 0:3fe2fe307968 29 #define CENTER_AD_MIRROR_Y 2047 // This MUST BE the direction of the photodetector.
mbedalvaro 0:3fe2fe307968 30
mbedalvaro 0:3fe2fe307968 31
mbedalvaro 0:3fe2fe307968 32 extern DigitalOut Laser_Red, Laser_Green, Laser_Blue;
mbedalvaro 0:3fe2fe307968 33
mbedalvaro 0:3fe2fe307968 34 // ==================================================================================================================================================================
mbedalvaro 0:3fe2fe307968 35
mbedalvaro 0:3fe2fe307968 36 class HardwareIO {
mbedalvaro 0:3fe2fe307968 37 public:
mbedalvaro 0:3fe2fe307968 38
mbedalvaro 0:3fe2fe307968 39
mbedalvaro 0:3fe2fe307968 40 void init(void);
mbedalvaro 0:3fe2fe307968 41
mbedalvaro 0:3fe2fe307968 42 void showLimitsMirrors( int times );
mbedalvaro 0:3fe2fe307968 43
mbedalvaro 0:3fe2fe307968 44 // SPI control for DAC for mirrors and red laser power (low level):
mbedalvaro 0:3fe2fe307968 45 void writeOutX(unsigned short value);
mbedalvaro 0:3fe2fe307968 46 void writeOutY(unsigned short value);
mbedalvaro 1:b1f5ed22087a 47 void writeOutXY(unsigned short valueX, unsigned short valueY) {writeOutX(valueX); writeOutY(valueY);};
mbedalvaro 1:b1f5ed22087a 48
mbedalvaro 1:b1f5ed22087a 49
mbedalvaro 1:b1f5ed22087a 50 //Displaying lasers:
mbedalvaro 1:b1f5ed22087a 51 // Again: for the moment laser are TTL but these could be analog. Now, it is just: powerValue > 0 ==> 'true'; else 'false'
mbedalvaro 0:3fe2fe307968 52 // Red laser:
mbedalvaro 0:3fe2fe307968 53 void setRedPower(int powerRed);
mbedalvaro 0:3fe2fe307968 54 // Green laser:
mbedalvaro 0:3fe2fe307968 55 void setGreenPower(int powerGreen);
mbedalvaro 0:3fe2fe307968 56 // Blue laser:
mbedalvaro 0:3fe2fe307968 57 void setBluePower(int powerBlue);
mbedalvaro 1:b1f5ed22087a 58 // Setting all colors at once:
mbedalvaro 0:3fe2fe307968 59 void setRGBPower(unsigned char color); // we will use the 3 LSB bits to set each color
mbedalvaro 0:3fe2fe307968 60
mbedalvaro 0:3fe2fe307968 61
mbedalvaro 0:3fe2fe307968 62
mbedalvaro 0:3fe2fe307968 63 private:
mbedalvaro 0:3fe2fe307968 64
mbedalvaro 0:3fe2fe307968 65 };
mbedalvaro 0:3fe2fe307968 66
mbedalvaro 0:3fe2fe307968 67
mbedalvaro 0:3fe2fe307968 68 extern HardwareIO IO; // allows the object IO to be used in other .cpp files (IO is pre-instantiated in hardwareIO.cpp)
mbedalvaro 0:3fe2fe307968 69 // 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:3fe2fe307968 70 extern Serial pc; // allows pc to be manipulated by other .cpp files, even if pc is defined in the hardwareIO.cpp
mbedalvaro 0:3fe2fe307968 71
mbedalvaro 0:3fe2fe307968 72
mbedalvaro 0:3fe2fe307968 73 #endif