FLEX: Image acquisition firmware for Video Smart Sensor

http://dev.emcelettronica.com/print/51824

Your Electronics Open Source
(http://dev.emcelettronica.com)
Home > My blog > Content

FLEX: Image acquisition firmware for Video Smart Sensor
By Ionela Created 19/06/2008 - 11:52

BLOG Microcontrollers This demo demonstrates a procedure for image acquisition from a camera equipped with serial interface on CMOS levels using FLEX. FLEX [1]is a platform board for embedded modular systems that exploits the potential of Microchip family’s dsPIC DSC microcontroller. It is an ideal board for developing real-time applications because the onboard dsPIC33FJ256MC710 microcontroller supports advanced real-time kernel, such as the Evidence Srl’s Erika Enterprise. The software is divided in two parts: an MPLAB application to be loaded on the FLEX micro-controller (dsPIC33FJ256MC710); and a Win32 application for serial data acquisition and image visualization. For PC Side Application the requirements are: the program uses cygwin1.dll (included in the distribution), that can either be shared through the windows PATH environment variable or be placed in the executable directory. The program must be executed in Microsoft/Cygwin. Requirements for the Flex Side Application: the list of hardware components required to reproduce the demo: FLEX Base Board (Light or Full), home made PCB for serial RS232 voltage conversion, capacitors and connectors, a CAMVGA100 module Using the Project Wizard, create a new MPLAB project in the Flex -side directory and build the executable file. Or alternatively, using the $ makefile to create the project. Then program the microchip device by means of an ICD2 programmer.

[2]

Let's see a piece of the code:
/************** MAIN ***********/ int main ( void ) { unsigned char camok=0; unsigned int i=0; // Fcy/115200/16-1 = 5.78 -> 6 /* Clock setup for 40MIPS */ RCONbits.SWDTEN = 0; CLKDIVbits.DOZEN = 0; CLKDIVbits.PLLPRE = 0; CLKDIVbits.PLLPOST = 0; PLLFBDbits.PLLDIV = 76; while(OSCCONbits.LOCK!=1); //U1BRG=20; //U1BRG=20; // BAUD_RATE = 115200 //U1BRG=41; // BAUD_RATE = 57600 U1BRG=62; // BAUD_RATE = 38400 //U1BRG=125; // BAUD_RATE = 19200

// Disable Watch Dog Timer

// to have Fcy = 39e6Hz... /* Wait for PLL to lock */

1 din 3

23.06.2008 08:41

FLEX: Image acquisition firmware for Video Smart Sensor

http://dev.emcelettronica.com/print/51824

//U1BRG=253; // BAUD_RATE = 9600 UART1_Config(U1BRG); //while(1) //Loop forever //{ //Main routine //Loops forever detecting the baud rate from incoming UART data of 0x55 //and outputing a message each time the baud rate is calculated. //SetupAutoBaud(); //Set up UART1, IC1 and TMR3 for autobaud //while(U1BRG == 0) {} //Wait for autobaud to complete //BRate = ((unsigned )Fcy / 16) / (U1BRG + 1); //See what baud rate is being used //printf("Baud rate: %ld\r", BRate); //Output text with the baud rate //while(finish == 0); //finish=0; //Cam_TIMER89Config(152343); //Cam_Sleep(76170); //0.1sec //IEC0bits.IC1IE = 0; //Clear Capture 1 interrupt enable //IEC0bits.T3IE = 0; //Clear Timer 3 interrupt enable //U1BRG_calcval = (unsigned int)(((SumOfBitTimes + 64) >> 7) - 1); //UART1_Config( U1BRG_calcval ); //Cam_Sleep(152343); //Cam_CloseTimer89(); // ust[0] = (U1BRG>>8) & 0x00FF; // ust[1] = U1BRG & 0x00FF; // Send_by_UART1((unsigned int *)ust,2); // while(BusyUART1()); //Wait for transmission to complete // Send_by_UART1((unsigned int *)ust,2); // while(BusyUART1()); //Wait for transmission to complete //ust[0] = 0xAA; //ust[1] = 0xBB; //ust[2] = 0xCC; //ust[3] = 0xDD; //Send_by_UART1((unsigned int *)ust,4); //while(BusyUART1()); //Wait for transmission to complete //break; //} //UART1_Config(259); //ust[0]=0xAA; //Send_by_UART1((unsigned int *)ust,1); //while(BusyUART1()); //Wait for transmission to complete //UART1_Config(62); //UART1_Config(20); // Initialize the UART module to receive and transmit serial data. //UART1_Config(41); Cam_Init(); // while(1) // { // ust[0]=0xAA; // Send_by_UART1((unsigned int *)ust,1); // for(i=0;i<60000;i++); // } //start1=1; while(1) { if(start1) { start1=0; camok = Cam_Synchronization( (float)Fcy ); if(camok) { ust[0]=0x12; ust[1]=0x34; //Send_by_UART1((unsigned int *)ust,2); } else { ust[0]=0xEE; ust[1]=0xEE; Send_by_UART1((unsigned int *)ust,2); continue; } //if(!camok) continue; camok = Cam_GetStream(); } } //CloseUART1(); //while(1); return 0; } // void SetupAutoBaud(void) -> Read me: Set up the peripherals and interrupts to do baud rate detection void SetupAutoBaud(void) { U1BRG = 0; //U1BRG initially unknown U1MODE = 0x8820; //Enable auto baud detection in UART U1STA = 0x85D0; //Set up rest of UART to default state with transmission enabled ICCount = 0; //Initialize the number of Capture events IC1CON = 0x0000; //Reset Input Capture 1 module IC1CON = 0x0002; //Enable Input Capture 1 module IFS0bits.IC1IF = 0; //Clear Capture 1 interrupt flag IEC0bits.IC1IE = 1; //Enable Capture 1 interrupt T3CON = 0x0000; //Timer 3 off

2 din 3

23.06.2008 08:41

FLEX: Image acquisition firmware for Video Smart Sensor

http://dev.emcelettronica.com/print/51824

IEC0bits.T3IE = 0; T3Count = 0; PR3 = 0xffff; T3CON = 0x8000; }

//Clear Timer 3 interrupt enable //Initialize the number of Timer 3 interrupts //Timer 3 period is maximum //Timer 3 on with 1:1 prescaler and internal clock

For more informations click here [3].

Trademarks

Source URL: http://dev.emcelettronica.com/flex-image-acquisition-firmware-video-smart-sensor Links: [1] http://dev.emcelettronica.com/Flex [2] http://www.evidence.eu.com/images/stories/flex_image_acquisition/conceptual_diagram.jpg [3] http://www.evidence.eu.com/content/view/266/266/

3 din 3

23.06.2008 08:41

Sign up to vote on this title
UsefulNot useful