simple example program to control one mirror from serial data

Dependencies:   mbed

Committer:
mbedalvaro
Date:
Thu Oct 04 05:16:25 2012 +0000
Revision:
3:3fe7d6b5cf24
simplest control X Y mirrors;

Who changed what in which revision?

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