17
r etis.sssup.it The dsPic33 and FLEX board Paolo Pagano RETIS Laboratory, Scuola Superiore Sant'Anna, Pisa, Italy [email protected] Corso di Sistemi in Tempo Reale Laurea in Ingegneria dell‘Automazione a.a. 2008- 2009

The dsPic33 and FLEX board

  • Upload
    roscoe

  • View
    28

  • Download
    2

Embed Size (px)

DESCRIPTION

Corso di Sistemi in Tempo Reale Laurea in Ingegneria dell‘Automazione a.a. 2008-2009. The dsPic33 and FLEX board. Paolo Pagano RETIS Laboratory, Scuola Superiore Sant'Anna, Pisa, Italy [email protected]. Course Outline (1/2). Second day (24 th ) - PowerPoint PPT Presentation

Citation preview

Page 1: The dsPic33 and FLEX board

retis.sssup.it

The dsPic33 and FLEX board

Paolo PaganoRETIS Laboratory,

Scuola Superiore Sant'Anna, Pisa, [email protected]

Corso di Sistemi in Tempo RealeLaurea in Ingegneria

dell‘Automazione a.a. 2008-2009

Page 2: The dsPic33 and FLEX board

retis.sssup.it

Course Outline (1/2)

• Second day (24th)• FSM implementation in C (slides by prof. Di Natale)• A case study• Real Hardware demonstration

Page 3: The dsPic33 and FLEX board

retis.sssup.it

Outline

• Introduction to the FLEX board• A FSM instantiation on the FLEX

• Visit the web site:

http://feanor.sssup.it/~pagano/personalWEB/courses.htm

Page 4: The dsPic33 and FLEX board

retis.sssup.it

FLEX

idea:cheap, small, easy-to-use evaluation boards

Typical applications:• industrial sensing and control• small robots• wireless sensor networks• demo boards for university labs

embedded boards

Page 5: The dsPic33 and FLEX board

retis.sssup.it

Flex

Page 6: The dsPic33 and FLEX board

retis.sssup.it

board layout

Main processing board

add-on boards

Page 7: The dsPic33 and FLEX board

retis.sssup.it

add-on boards

1 - 2.54mm pattern2 - 2.54mm alternate

pattern (RJ45 / RS232 connectors)

3 - 1.27mm pattern (SMD components)

4 - 5.08mm pattern (clamps)

breadboard

Page 8: The dsPic33 and FLEX board

retis.sssup.it

add-on boards

1 - Serial port 2(RS232 / RS422 /RS485 / TP-UART)

2 - Serial port 1(RS232 / RS422 /RS485)

3 - CAN port 1

4 - CAN port 2

5 - I2C port

6 - SPI port

7 - 10Mbit Ethernet

8 - RJ45 Ethernet

multibus

Page 9: The dsPic33 and FLEX board

retis.sssup.it

Our test device

• It is an extended basic flex board;• We connected the dsPic33 core to:

• Set of buttons (input);• Set of leds (output);• LCD display (status display).

• We have in mind to simulate an elevator controller:• its implementation starts from FSM modeling;• the model is validated by OTS tools (Uppaal);• the code generation is done by hand.

Page 10: The dsPic33 and FLEX board

retis.sssup.it

How to program our device

• Our FLEX board should run a specific program (firmware);

• We need a compiler to translate from C to machine code;

• We need a linker command file that allows the test code to be targeted to the dsPIC33;

• We need a tool to transfer the firmware from the PC to the MCU flash memory.

MPLAB_C30

gld script

Microchip ICD2

Page 11: The dsPic33 and FLEX board

retis.sssup.it

COFF file structurehttp://delorie.com/djgpp/doc/coff/

Page 12: The dsPic33 and FLEX board

retis.sssup.it

Peripheral Mapping

• Expansion Board PIN I/O:• Leds -> PortD (output)• But’s -> PortG (input)• LCD -> PortA (output)

Page 13: The dsPic33 and FLEX board

retis.sssup.it

MCU I/O

• A port is a set of analog/digital enabled pins.• A port can be configured to catch analog or digital

inputs. Digital signals can have a duration (like those generated by pushing buttons) or can be “levels” (latch mode).• of course finite signals must be caught while high.

Page 14: The dsPic33 and FLEX board

retis.sssup.it

How to configure ports

• dsPic has 7 ports defined in the included header:

• #include "p33FJ256MC710.h"• Configuring a port for OUTPUT

void initLeds (void){

TRISDbits.TRISD0 = 0;TRISDbits.TRISD1 = 0;TRISDbits.TRISD2 = 0;TRISDbits.TRISD3 = 0;TRISDbits.TRISD4 = 0;TRISDbits.TRISD5 = 0;TRISDbits.TRISD6 = 0;TRISDbits.TRISD7 = 0;TRISDbits.TRISD8 = 0;TRISDbits.TRISD9 = 0;TRISDbits.TRISD10 = 0;TRISDbits.TRISD11 = 0;TRISDbits.TRISD12 = 0;TRISDbits.TRISD13 = 0;TRISDbits.TRISD14 = 0;TRISDbits.TRISD15 = 0;

}:

• Configuring a port for INPUT:

void initButtons (void){

TRISGbits.TRISG6 = 1; TRISGbits.TRISG7 = 1; TRISGbits.TRISG8 = 1; TRISGbits.TRISG9 = 1;

}

4 Buttons

16 pels of the LCD

Page 15: The dsPic33 and FLEX board

retis.sssup.it

How to read/write ports

• Writing OUTPUT:

void setLed ( int led, int on_off ){

switch (led){case 0:LATDbits.LATD0 = on_off;break;case 1:LATDbits.LATD1 = on_off;break;case 2:LATDbits.LATD2 = on_off;break;case 3:LATDbits.LATD3 = on_off;break;}

}

• Reading INPUT:

int getButton ( int j ){switch (j){case 0: return !PORTGbits.RG6;case 1: return !PORTGbits.RG7;case 2: return !PORTGbits.RG8;case 3: return !PORTGbits.RG9;}

}

Page 16: The dsPic33 and FLEX board

retis.sssup.it

the end

Questions ?

Page 17: The dsPic33 and FLEX board

retis.sssup.it

HOWTO initialize and transit

static enum State {IDLE, S0, S1, S2, S3

};static enum Signal {

ABSENT, GO_TO_S0, GO_TO_S1, GO_TO_S2, GO_TO_S3

};

void FSMInit(FSM *me){me->state_ = IDLE;

}void FSMTran_(FSM *me, unsigned int

dest){

me->state_ = dest;}

enum Signal FSMGetSignals(FSM *me){if (b0)

return GO_TO_S0;else if (b1)

return GO_TO_S1;else if (b2)

return GO_TO_S2;else if (b3)

return GO_TO_S3;

return ABSENT;}

init

transition

signal generation