Alvaro Cassinelli
/
laserScannerControl_FRDMK64F
Example controlling galvanomirrors (X and Y) using the spi DAC MCP4922 and the new platform FRDM_K64F
laserProjectorHardware/laserProjectorHardware.h
- Committer:
- mbedalvaro
- Date:
- 2014-12-10
- Revision:
- 5:cea6da0fe2f0
- Parent:
- 4:1428775752f7
File content as of revision 5:cea6da0fe2f0:
#ifndef hardwareIO_h #define hardwareIO_h #include "mbed.h" //SPI library (for DAC MCP4922 chip) 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: #define SCK_PIN D13 //SPI Clock #define MISO_PIN D12 //SPI input (data comming from DAC, here not connected) #define MOSI_PIN D11 //SPI output (data going to DAC) //**** CHIP SELECT pins for MP4922 DAC (mirrors and red laser) // 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). #define CS_DAC_MIRRORS D7 //Chip Select of the first DAC (mirrors) //**** LASERS pins: // NOTE: for some reason PWM output D8 does not goes to 0!! #define LASER_LOCKIN_PIN D5 // this can be analog, or TTL controlled (PWM modulation or real analog output, in this case it needs to be pin DAC0_OUT #define LOCKIN_FREQUENCY 100 // in Hertz #define LASER_RED_PIN D4 // NOT YET USED (TTL control) #define LASER_GREEN_PIN D8 // NOT YET USED (TTL control) #define LASER_BLUE_PIN D6 // NOT YET USED (TTL control) //**** MIRRORS: //The DAC is 12 bytes capable (Max=4096), but we will limit this a little. #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. #define MIN_AD_MIRRORS 0 // note: 0 is 0 volts for the SPI voltage. // We assume that the center of the mirror is at MAX_AD_MIRRORS/2 = 2000: #define CENTER_AD_MIRROR_X 2047 // This MUST BE the direction of the photodetector. #define CENTER_AD_MIRROR_Y 2047 // This MUST BE the direction of the photodetector. extern DigitalOut Laser_Red, Laser_Green, Laser_Blue; // ================================================================================================================================================================== class HardwareIO { public: void init(void); // SPI control for DAC for mirrors and red laser power (low level): void writeOutX(unsigned short value); void writeOutY(unsigned short value); void writeOutXY(unsigned short valueX, unsigned short valueY) {writeOutX(valueX); writeOutY(valueY);}; // Lockin Laser: void setLockinFreq(int freqHz); void setLockinPower(int powerLockin); // actually 0 or >0, for 0 and 50% duty cycle of the pwm output //Displaying lasers: // Again: for the moment laser are TTL but these could be analog. Now, it is just: powerValue > 0 ==> 'true'; else 'false' // Red laser: void setRedPower(int powerRed); // Green laser: void setGreenPower(int powerGreen); // Blue laser: void setBluePower(int powerBlue); // Setting all colors at once: void setRGBPower(unsigned char color); // we will use the 3 LSB bits to set each color // More complex functions: void showLimitsMirrors( int seconds ); void drawCircle(int X, int Y, int R, int numPoints); void drawCircle(int X, int Y, int R, int numPoints, int seconds); private: }; extern HardwareIO IO; // allows the object IO to be used in other .cpp files (IO is pre-instantiated in hardwareIO.cpp) // 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) extern Serial pc; // allows pc to be manipulated by other .cpp files, even if pc is defined in the hardwareIO.cpp #endif