Reference firmware for PixArt's PAA5101 sensor and evaluation board. "Hello World" and "Library" contain the exact same files. Please import just one of the two into your mBed compiler as a new program and not as a library.
Welcome to the code repository for PixArt's PAA5101 sensor and evaluation board.
For general information about this product, please visit this product's components page here:
https://os.mbed.com/components/PAA5101-Floor-Tracking-Sensor-with-Wide-/
For guides and tips on how to setup and evaluate the PAA5101 sensor with the Nordic nRF52-DK microcontroller using this reference code, please visit this guide:
https://os.mbed.com/teams/PixArt/code/5101_referenceCode/wiki/Guide-for-nRF52-DK-Platform
For guides and tips on how to setup and evaluate the PAA5101 sensor with any microcontroller using this reference code, please visit this guide:
https://os.mbed.com/teams/PixArt/code/5101_referenceCode/wiki/Guide-for-Any-Platform
main.cpp@4:234a8616c0a6, 2018-06-13 (annotated)
- Committer:
- PixArtVY
- Date:
- Wed Jun 13 20:30:06 2018 +0000
- Revision:
- 4:234a8616c0a6
- Parent:
- 3:1d5c2956f415
- Child:
- 5:e6cc13f2fc8b
Comments
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
PixArtVY | 0:2c144b6813d1 | 1 | // PAA5101 Optical Tracking Minuature Chip reference code. |
PixArtVY | 0:2c144b6813d1 | 2 | // Version: 1.0 |
PixArtVY | 0:2c144b6813d1 | 3 | // Latest Revision Date: 29 Jan. 2018 |
PixArtVY | 0:2c144b6813d1 | 4 | // By PixArt Imaging Inc. |
PixArtVY | 0:2c144b6813d1 | 5 | // Primary Engineer: Vincent Yeh (PixArt USA) |
PixArtVY | 0:2c144b6813d1 | 6 | |
PixArtVY | 0:2c144b6813d1 | 7 | /* |
PixArtVY | 0:2c144b6813d1 | 8 | //======================= |
PixArtVY | 0:2c144b6813d1 | 9 | //Revision History |
PixArtVY | 0:2c144b6813d1 | 10 | //======================= |
PixArtVY | 4:234a8616c0a6 | 11 | Version 1.1 -- Fixed SPI frequency from 10MHz to 2MHz. |
PixArtVY | 4:234a8616c0a6 | 12 | Version 1.0 -- First release. |
PixArtVY | 0:2c144b6813d1 | 13 | */ |
PixArtVY | 0:2c144b6813d1 | 14 | |
PixArtVY | 0:2c144b6813d1 | 15 | #include "mbed.h" |
PixArtVY | 0:2c144b6813d1 | 16 | #include "registerArrays.h" |
PixArtVY | 0:2c144b6813d1 | 17 | #include "SPIcommFunctions.h" |
PixArtVY | 0:2c144b6813d1 | 18 | |
PixArtVY | 0:2c144b6813d1 | 19 | int main() |
PixArtVY | 0:2c144b6813d1 | 20 | { |
PixArtVY | 0:2c144b6813d1 | 21 | pc.baud(115200); // Set baud rate to 115200. Remember to sync serial terminal baud rate to the same value. |
PixArtVY | 0:2c144b6813d1 | 22 | |
PixArtVY | 0:2c144b6813d1 | 23 | spi.format(8,3); // Set SPI to 8 bits with inverted polarity and phase-shifted to second edge. |
PixArtVY | 3:1d5c2956f415 | 24 | spi.frequency(2000000); // Set frequency for SPI communication. |
PixArtVY | 0:2c144b6813d1 | 25 | cs = 1; // Initialize chip-select pin to be HIGH (inactive). |
PixArtVY | 0:2c144b6813d1 | 26 | |
PixArtVY | 0:2c144b6813d1 | 27 | pc.printf("Program START\n\r"); |
PixArtVY | 0:2c144b6813d1 | 28 | |
PixArtVY | 0:2c144b6813d1 | 29 | writeRegister(0x7F, 0x00); //Reset to bank 0 before initializing again |
PixArtVY | 0:2c144b6813d1 | 30 | |
PixArtVY | 0:2c144b6813d1 | 31 | pc.printf("ID Check: %2X\n\r", readRegister(0x00)); //Checks product ID to make sure communication protocol is working properly. |
PixArtVY | 0:2c144b6813d1 | 32 | if(readRegister(0x00) != 0x31) |
PixArtVY | 0:2c144b6813d1 | 33 | { |
PixArtVY | 0:2c144b6813d1 | 34 | pc.printf("Communication protocol error! Terminating program.\n\r"); |
PixArtVY | 0:2c144b6813d1 | 35 | return 0; |
PixArtVY | 0:2c144b6813d1 | 36 | } |
PixArtVY | 0:2c144b6813d1 | 37 | |
PixArtVY | 0:2c144b6813d1 | 38 | writeRegister(0x06, 0x80); //Resets the chip now that we have verified that the communication works. |
PixArtVY | 0:2c144b6813d1 | 39 | wait_ms(1); //Wait at least 1 millisecond after resetting for timing. |
PixArtVY | 0:2c144b6813d1 | 40 | |
PixArtVY | 0:2c144b6813d1 | 41 | pc.printf("ID Check #2: %2X\n\r", readRegister(0x00)); //Checks product ID to make sure communication protocol is working properly after the reset. |
PixArtVY | 0:2c144b6813d1 | 42 | if(readRegister(0x00) != 0x31) |
PixArtVY | 0:2c144b6813d1 | 43 | { |
PixArtVY | 0:2c144b6813d1 | 44 | pc.printf("Communication protocol error! Terminating program.\n\r"); |
PixArtVY | 0:2c144b6813d1 | 45 | return 0; |
PixArtVY | 0:2c144b6813d1 | 46 | } |
PixArtVY | 0:2c144b6813d1 | 47 | |
PixArtVY | 0:2c144b6813d1 | 48 | writeRegister(0x09, 0x5A); //Disables write-protect |
PixArtVY | 0:2c144b6813d1 | 49 | writeRegister(0x51, 0x06); //Sets laser diode power. Value should be <= 6 |
PixArtVY | 0:2c144b6813d1 | 50 | |
PixArtVY | 0:2c144b6813d1 | 51 | load(initialize, initialize_size); //Loads initial register settings |
PixArtVY | 0:2c144b6813d1 | 52 | |
PixArtVY | 0:2c144b6813d1 | 53 | writeRegister(0x5D, 0x3E); //Unlisted register. Internal recommendation... |
PixArtVY | 0:2c144b6813d1 | 54 | wait_ms(10); |
PixArtVY | 0:2c144b6813d1 | 55 | writeRegister(0x5D, 0x3F); //Unlisted register. Internal recommendation... |
PixArtVY | 0:2c144b6813d1 | 56 | |
PixArtVY | 0:2c144b6813d1 | 57 | load(modeLaser, modeLaser_size); //Goes into laser mode which is the default mode (not LED) |
PixArtVY | 0:2c144b6813d1 | 58 | mode = 0; //This variable tracks if we are in laser mode or LED mode. 0 = laser, 1 = LED |
PixArtVY | 0:2c144b6813d1 | 59 | LDP = 0; //Change GPIO pin to the laser diode to be LOW to activate the laser. |
PixArtVY | 0:2c144b6813d1 | 60 | |
PixArtVY | 0:2c144b6813d1 | 61 | writeRegister(0x09, 0x00); //Enables write-protect |
PixArtVY | 0:2c144b6813d1 | 62 | |
PixArtVY | 0:2c144b6813d1 | 63 | |
PixArtVY | 0:2c144b6813d1 | 64 | |
PixArtVY | 0:2c144b6813d1 | 65 | while(1) //After all setup/initialization is done, we can loop for interrupts and mode detection. |
PixArtVY | 0:2c144b6813d1 | 66 | { |
PixArtVY | 0:2c144b6813d1 | 67 | checkMode(); //Checks image quality and switches to laser or LED mode accordingly. |
PixArtVY | 0:2c144b6813d1 | 68 | |
PixArtVY | 2:045cc9f995ae | 69 | if(readRegister(0x02) & 0x80) //If motion bit (bit 7 of register 0x02) is 1, movement has been detected. |
PixArtVY | 0:2c144b6813d1 | 70 | { |
PixArtVY | 0:2c144b6813d1 | 71 | grabData(); //Grabs data into variables deltaX and deltaY. |
PixArtVY | 0:2c144b6813d1 | 72 | printData(); //Prints deltaX and deltaY, but only if they have changed from their previous values. |
PixArtVY | 0:2c144b6813d1 | 73 | } |
PixArtVY | 0:2c144b6813d1 | 74 | } |
PixArtVY | 0:2c144b6813d1 | 75 | } |