Alvaro Cassinelli
/
laserScannerControl_FRDMK64F
Example controlling galvanomirrors (X and Y) using the spi DAC MCP4922 and the new platform FRDM_K64F
laserProjectorHardware/laserProjectorHardware.h@4:1428775752f7, 2014-12-10 (annotated)
- Committer:
- mbedalvaro
- Date:
- Wed Dec 10 07:22:41 2014 +0000
- Revision:
- 4:1428775752f7
- Parent:
- 3:89f592efbe84
added circle with timer
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mbedalvaro | 0:26b228dde70c | 1 | |
mbedalvaro | 0:26b228dde70c | 2 | #ifndef hardwareIO_h |
mbedalvaro | 0:26b228dde70c | 3 | #define hardwareIO_h |
mbedalvaro | 0:26b228dde70c | 4 | |
mbedalvaro | 0:26b228dde70c | 5 | #include "mbed.h" |
mbedalvaro | 0:26b228dde70c | 6 | |
mbedalvaro | 0:26b228dde70c | 7 | |
mbedalvaro | 4:1428775752f7 | 8 | //SPI library (for DAC MCP4922 chip) uses the following pins, but we don't have to set them and inputs or outputs |
mbedalvaro | 0:26b228dde70c | 9 | // (this is done when the library is initialized, which is done by pre-instantiation: |
mbedalvaro | 0:26b228dde70c | 10 | #define SCK_PIN D13 //SPI Clock |
mbedalvaro | 0:26b228dde70c | 11 | #define MISO_PIN D12 //SPI input (data comming from DAC, here not connected) |
mbedalvaro | 0:26b228dde70c | 12 | #define MOSI_PIN D11 //SPI output (data going to DAC) |
mbedalvaro | 0:26b228dde70c | 13 | |
mbedalvaro | 0:26b228dde70c | 14 | //**** CHIP SELECT pins for MP4922 DAC (mirrors and red laser) |
mbedalvaro | 0:26b228dde70c | 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:26b228dde70c | 16 | #define CS_DAC_MIRRORS D7 //Chip Select of the first DAC (mirrors) |
mbedalvaro | 0:26b228dde70c | 17 | |
mbedalvaro | 0:26b228dde70c | 18 | //**** LASERS pins: |
mbedalvaro | 3:89f592efbe84 | 19 | // NOTE: for some reason PWM output D8 does not goes to 0!! |
mbedalvaro | 3:89f592efbe84 | 20 | #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 |
mbedalvaro | 3:89f592efbe84 | 21 | #define LOCKIN_FREQUENCY 100 // in Hertz |
mbedalvaro | 3:89f592efbe84 | 22 | |
mbedalvaro | 3:89f592efbe84 | 23 | #define LASER_RED_PIN D4 // NOT YET USED (TTL control) |
mbedalvaro | 3:89f592efbe84 | 24 | #define LASER_GREEN_PIN D8 // NOT YET USED (TTL control) |
mbedalvaro | 3:89f592efbe84 | 25 | #define LASER_BLUE_PIN D6 // NOT YET USED (TTL control) |
mbedalvaro | 0:26b228dde70c | 26 | |
mbedalvaro | 0:26b228dde70c | 27 | //**** MIRRORS: |
mbedalvaro | 0:26b228dde70c | 28 | //The DAC is 12 bytes capable (Max=4096), but we will limit this a little. |
mbedalvaro | 0:26b228dde70c | 29 | #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 | 0:26b228dde70c | 30 | #define MIN_AD_MIRRORS 0 // note: 0 is 0 volts for the SPI voltage. |
mbedalvaro | 0:26b228dde70c | 31 | // We assume that the center of the mirror is at MAX_AD_MIRRORS/2 = 2000: |
mbedalvaro | 0:26b228dde70c | 32 | #define CENTER_AD_MIRROR_X 2047 // This MUST BE the direction of the photodetector. |
mbedalvaro | 0:26b228dde70c | 33 | #define CENTER_AD_MIRROR_Y 2047 // This MUST BE the direction of the photodetector. |
mbedalvaro | 0:26b228dde70c | 34 | |
mbedalvaro | 0:26b228dde70c | 35 | |
mbedalvaro | 0:26b228dde70c | 36 | extern DigitalOut Laser_Red, Laser_Green, Laser_Blue; |
mbedalvaro | 0:26b228dde70c | 37 | |
mbedalvaro | 0:26b228dde70c | 38 | // ================================================================================================================================================================== |
mbedalvaro | 0:26b228dde70c | 39 | |
mbedalvaro | 0:26b228dde70c | 40 | class HardwareIO { |
mbedalvaro | 0:26b228dde70c | 41 | public: |
mbedalvaro | 0:26b228dde70c | 42 | |
mbedalvaro | 0:26b228dde70c | 43 | |
mbedalvaro | 0:26b228dde70c | 44 | void init(void); |
mbedalvaro | 0:26b228dde70c | 45 | |
mbedalvaro | 0:26b228dde70c | 46 | // SPI control for DAC for mirrors and red laser power (low level): |
mbedalvaro | 0:26b228dde70c | 47 | void writeOutX(unsigned short value); |
mbedalvaro | 0:26b228dde70c | 48 | void writeOutY(unsigned short value); |
mbedalvaro | 0:26b228dde70c | 49 | void writeOutXY(unsigned short valueX, unsigned short valueY) {writeOutX(valueX); writeOutY(valueY);}; |
mbedalvaro | 0:26b228dde70c | 50 | |
mbedalvaro | 0:26b228dde70c | 51 | |
mbedalvaro | 3:89f592efbe84 | 52 | // Lockin Laser: |
mbedalvaro | 3:89f592efbe84 | 53 | void setLockinFreq(int freqHz); |
mbedalvaro | 3:89f592efbe84 | 54 | void setLockinPower(int powerLockin); // actually 0 or >0, for 0 and 50% duty cycle of the pwm output |
mbedalvaro | 3:89f592efbe84 | 55 | |
mbedalvaro | 3:89f592efbe84 | 56 | |
mbedalvaro | 0:26b228dde70c | 57 | //Displaying lasers: |
mbedalvaro | 0:26b228dde70c | 58 | // Again: for the moment laser are TTL but these could be analog. Now, it is just: powerValue > 0 ==> 'true'; else 'false' |
mbedalvaro | 0:26b228dde70c | 59 | // Red laser: |
mbedalvaro | 0:26b228dde70c | 60 | void setRedPower(int powerRed); |
mbedalvaro | 0:26b228dde70c | 61 | // Green laser: |
mbedalvaro | 0:26b228dde70c | 62 | void setGreenPower(int powerGreen); |
mbedalvaro | 0:26b228dde70c | 63 | // Blue laser: |
mbedalvaro | 0:26b228dde70c | 64 | void setBluePower(int powerBlue); |
mbedalvaro | 0:26b228dde70c | 65 | // Setting all colors at once: |
mbedalvaro | 0:26b228dde70c | 66 | void setRGBPower(unsigned char color); // we will use the 3 LSB bits to set each color |
mbedalvaro | 0:26b228dde70c | 67 | |
mbedalvaro | 2:383b2acec6e4 | 68 | // More complex functions: |
mbedalvaro | 4:1428775752f7 | 69 | void showLimitsMirrors( int seconds ); |
mbedalvaro | 2:383b2acec6e4 | 70 | void drawCircle(int X, int Y, int R, int numPoints); |
mbedalvaro | 4:1428775752f7 | 71 | void drawCircle(int X, int Y, int R, int numPoints, int seconds); |
mbedalvaro | 0:26b228dde70c | 72 | |
mbedalvaro | 0:26b228dde70c | 73 | private: |
mbedalvaro | 0:26b228dde70c | 74 | |
mbedalvaro | 0:26b228dde70c | 75 | }; |
mbedalvaro | 0:26b228dde70c | 76 | |
mbedalvaro | 0:26b228dde70c | 77 | |
mbedalvaro | 0:26b228dde70c | 78 | extern HardwareIO IO; // allows the object IO to be used in other .cpp files (IO is pre-instantiated in hardwareIO.cpp) |
mbedalvaro | 0:26b228dde70c | 79 | // 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:26b228dde70c | 80 | extern Serial pc; // allows pc to be manipulated by other .cpp files, even if pc is defined in the hardwareIO.cpp |
mbedalvaro | 0:26b228dde70c | 81 | |
mbedalvaro | 0:26b228dde70c | 82 | |
mbedalvaro | 0:26b228dde70c | 83 | #endif |