Qorivva: Line Scan Camera Tutorial

Document created by GUO XIAOLI Employee on Jul 12, 2012Last modified by GUO XIAOLI Employee on Sep 20, 2012
Version 9Show Document
  • View in full screen mode

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.

 

 

1. Overview

 

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:

  • Open the example file using Codewarrior
  • Build a project
  • Download the code to the board
  • connect the microcontroller to the camera via the motor control board
  • Run the program
  • view the camera data, clock and Si pulse on an oscilloscope

 

To successfully complete this exercise, students will need the following board and development environment:

  • TRK-MPC5604B
  • Motor Drive Board Version A
  • Freescale Cup TRK-MPC5604B compatible Car Kit
  • CodeWarrior for Microcontrollers v 2.8
  • P&E Micro Toolkit
  • Freescale Line Scan Camera
  • USB Cord
  • Knowledge of how Pointers and arrays are utilized in C

2. Hardware

 

  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

3. Set up the Hardware: Line Scan Camera/Microcontroller Hardware Setup

 

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.

 

4. Build the Code

 

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.

5. Download/Debug/Run

 

Download the code to your board, once this process is complete resume the project so that the code runs.

6. Learning Step

 

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.

Functions

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();
}

 

Calling the Function

 

within the main for loop in main.c, call the camera function using the following code:

for (;;) 
  {
  CAMERA();
  }

 

Variables

Creates an 128x1 array for camera data information

volatile uint8_t Result[128]; /* Read converstion result from ADC input ANS0 */  

Setting threshold. (This can give you a simple view of what your camera sees without connecting it to a scope)

#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)

Sample Code Download Link

 

Qorivva Sample Code Download Link

Alternative Examples

Application Note 4244 and Software.

 

Other Qorivva Tutorials:

 

1. Qorivva: Blink LED

2. Qorivva: Drive DC Motor Tutorial

3. Qorivva: Turning A Servo

4. Qorivva: Line Scan Camera Tutorial

Links

 

Qorivva Overview

Assembling the TRK-MPC5604B Chassis Components

External

 

TRK-MPC5064B Freescale Webpage
TRK-MPC5064B Freescale Reference Manual
TRK-MPC5064B Freescale Schematic

Attachments

    Outcomes