This tutorial covers the specific details of obtaining data from the line scan camera on the Qorivva TRK-MPC5604B board. This tutorial will help students familiarize themselves with how to interface the camera with the microcontroller, how to configure GPIO pins to create clock signals and also how to utilize the microcontroller's ADC to read the data from the camera. Outside of control algorithms, configuring the camera is one of the more complex tasks necessary to create a Freescale Cup Vehicle.
In this exercise students will access the line scan camera, create a clock signal and create the initialization pulse which tells the camera to begin the exposure period. This tutorial will not describe line recognition or line following algorithms - these concepts are beyond its scope.
Students will:
To successfully complete this exercise, students will need the following board and development environment:
Read the Obtain Data From Line Scan Camera overview article for general information on the camera, ADC, and GPIO microcontroller configuration settings.
Connect the sensors, motor drive board and microcontroller of your car according to the TRK-MPC5604B chassis build instructions
It is crucial for an engineer to have the proper test equipment and tools for the job. In this case, without an oscilloscope, students will not be able to verify whether the proper signals are being sent to the camera, or that the camera is working properly.
If there is more than one project in your project view, make sure the proper project is the focus. The most reliable way to do this is to right click the project and choose Build Project as shown below. You can also go to the Project menu and choose the same command.
If errors are encountered, look in the Problems view and resolve them. For now ignore any warnings.
Download the code to your board, once this process is complete resume the project so that the code runs.
What will happen:
the function ImageCapture() is called in main.c with a pointer to the first element in the array. This function completes the processes necessary to capture images using the camera.
To become more familiar with Pointers and Arrays - navigate to the C Programming Tutorial. Knowledge of Pointers and Arrays is a pre-requisite for understanding the Camera Code.
void CAMERA(void)
{
TransmitData("****Line Sensor Test****\n\r");
SIU.PCR[27].R = 0x0200; /* Program the Sensor read start pin as output*/
SIU.PCR[29].R = 0x0200; /* Program the Sensor Clock pin as output*/
for(j=0;j<2;j++)
//for(;;)
{
SIU.PCR[27].R = 0x0200; /* Program the Sensor read start pin as output*/
SIU.PCR[29].R = 0x0200; /* Program the Sensor Clock pin as output*/
SIU.PGPDO[0].R &= ~0x00000014; /* All port line low */
SIU.PGPDO[0].R |= 0x00000010; /* Sensor read start High */
Delay();
SIU.PGPDO[0].R |= 0x00000004; /* Sensor Clock High */
Delay();
SIU.PGPDO[0].R &= ~0x00000010; /* Sensor read start Low */
Delay();
SIU.PGPDO[0].R &= ~0x00000004; /* Sensor Clock Low */
Delay();
for (i=0;i<128;i++)
{
Delay();
SIU.PGPDO[0].R |= 0x00000004; /* Sensor Clock High */
ADC.MCR.B.NSTART=1; /* Trigger normal conversions for ADC0 */
while (ADC.MCR.B.NSTART == 1) {};
adcdata = ADC.CDR[0].B.CDATA;
Delay();
SIU.PGPDO[0].R &= ~0x00000004; /* Sensor Clock Low */
Result[i] = (uint8_t)(adcdata >> 2);
}
Delaycamera();
//printlistall();
}
printlistall();
}
within the main for loop in main.c, call the camera function using the following code:
for (;;)
{
CAMERA();
}
Creates an 128x1 array for camera data information
volatile uint8_t Result[128]; /* Read converstion result from ADC input ANS0 */
#define THRESHOLD (2.0 /*volts*/ / 0.03125) // 8-bit A/D = 31.25mV/bit
CAMERA(); // read line sensor, 128x1 pixel result returned in Result[128] array
// print result
for (i = 16; i < 112; ++i) // ignore the first and last 16 bits in the camera frame
if (Result[i] < THRESHOLD)
TransmitCharacter('1'); // black (low intensity)
else
TransmitCharacter('0'); // white (high intensity)
Qorivva Sample Code Download Link
Application Note 4244 and Software.
2. Qorivva: Drive DC Motor Tutorial
4. Qorivva: Line Scan Camera Tutorial
https://community.nxp.com/docs/DOC-1019
TRK-MPC5064B Freescale Webpage
TRK-MPC5064B Freescale Reference Manual
TRK-MPC5064B Freescale Schematic
Hi, I can`t understand exactly why threshold is defined like that.
What`s the meaning of the line " (2.0 /*volts*/ / 0.03125) " ?
Where is the variable volts? Is it a just comment?
Please answer me
thank you