ECE 4510/5530 Microcontroller Applications Week 12

Similar documents
CAN Protocol Implementation

ECE 4510/5530 Microcontroller Applications Week 11

ECE 4510 Introduction to Microprocessors. Chapter 13

CAN Node using HCS12

CIS-331 Exam 2 Fall 2015 Total of 105 Points Version 1

MSCAN Block Guide V03.01

Course Introduction. Purpose. Objectives. Content. Learning Time

University of Florida EEL 4744 Fall 1998 Dr. Eric M. Schwartz

CIS-331 Fall 2013 Exam 1 Name: Total of 120 Points Version 1

CIS-331 Exam 2 Fall 2014 Total of 105 Points. Version 1

VMBDMI. Velbus dimmer for resistive or inductive load. VMBDMI PROTOCOL edition 2

CIS-331 Spring 2016 Exam 1 Name: Total of 109 Points Version 1

History and Basic Processor Architecture

UNH-IOL MIPI Alliance Test Program

Controller Area Network CAN. overview

VORAGO VA108x0 I 2 C programming application note

ECE 4510/5530 Microcontroller Applications Week 7

CIS-331 Fall 2014 Exam 1 Name: Total of 109 Points Version 1

CIS-331 Final Exam Spring 2018 Total of 120 Points. Version 1

CIS-331 Exam 2 Spring 2016 Total of 110 Points Version 1

HOURS SYLLABUS

Chapter 1 Freescale s Scalable Controller Area Network (S12MSCANV2)

Block number: 00 Interface version: 4A Date: Checksum: 7500 Deployment Non-Deployment

Interfacing Z8 Encore! XP MCUs with an I 2 C-Based Character LCD

EMS CPC XTI. CAN-PC Interface. User Manual THOMAS WÜNSCHE. Documentation for CAN-Interface CPC-XTI.

Robotic Systems ECE 401RB Fall 2006

Gateway Ascii Command Protocol

Application Note I-Port event/error list

ECE 4510/5530 Microcontroller Applications Week 10

The House Intelligent Switch Control Network based On CAN bus

Example Programs for 6502 Microprocessor Kit

The cache is 4-way set associative, with 4-byte blocks, and 16 total lines

CAN In A Day 2L01I. Renesas Electronics America Inc Renesas Electronics America Inc. All rights reserved.

C1098 JPEG Module User Manual

Embedded Systems and Software

Modules For Six Months Industrial Training On WIRELESS EMBEDDED SYSTEM DESIGN

1. TIMS-0201 STEPPER CONTROLLER MODULE HARDWARE GENERAL SOFTWARE DESCRIPTION TIMS-0201 LABVIEW INSTRUMENT DRIVERS...

4. Specifications and Additional Information

INNOVATIVE TECHNOLOGY LTD CC2. Communications Protocol Manual GA863. Issue version Page 1 of 108

CIS-331 Final Exam Spring 2015 Total of 115 Points. Version 1

Lab 8 (ETH): Control Area Network

MTRX3700 Mechatronics

Introduction to Controller Area Network (CAN)

The University of the West Indies, St. Augustine INFO 2603 Platform Technologies /2018 Semester 1 Lab 1 - Wednesday 13th September 2017

Interrupts, timers and counters

CprE 288 Introduction to Embedded Systems (Timers/Input Capture) Instructors: Dr. Phillip Jones

Real Time Operating Systems Application Board Details

Data Sheet MEM 22. Absolute Encoder Multiturn

University of Florida EEL 4744 Spring 2011 Dr. Eric M. Schwartz Department of Electrical & Computer Engineering 31 March Apr-11 1:29 PM

EMS CPC 104I. CAN-PC Interface. User Manual THOMAS WÜNSCHE. Documentation for plug-in board CPC-104I.

Embedded Systems and Software. Serial Communication

Build a 5A H-bridge Motor driver! New version

Solumetrix Toroidal Conductivity Sensors

CMSC 313 Lecture 03 Multiple-byte data big-endian vs little-endian sign extension Multiplication and division Floating point formats Character Codes

SA818 Programming Manual

Arduino Prof. Dr. Magdy M. Abdelhameed

Everything s possible. Modbus Communication. Reference Manual. DigiFlex Performance Servo Drives. MNCMMBRF-02

Communications guide. Line Distance Protection System * F1* GE Digital Energy. Title page

Unlocking the Potential of Your Microcontroller

ECE 4510/5530 Microcontroller Applications Week 9

Administrivia. ECE/CS 5780/6780: Embedded System Design. FIFO with Infinite Memory. Introduction to FIFOs

Processor Register Set of M16C

Modbus Register Map: InRow ACRD60x / ACRC60x

CHETTINAD COLLEGE OF ENGINEERING AND TECHNOLOGY COMMUNICATION ENGINEERING REG 2008 TWO MARKS QUESTION AND ANSWERS

Project Final Report Internet Ready Refrigerator Inventory Control System

Dallas Semiconductor DS1307 Real Time Clock. The DS 1307 is a real-time clock with 56 bytes of NV (nonvolatile)

USBCAN-OBD. USB to CAN adapter. User Manual. Document version 3.01 (2015/04/22)

Intecom. March

Integrated Device Technology, Inc Stender Way, Santa Clara, CA Phone #: (408) Fax #: (408) Errata Notification

Developer Notes INSTEON Thermostat v012. Developer Notes. INSTEON Thermostat. Revision History

CANCore-I/II. User Manual. Industrial grade CAN module. Ver.:V3.02 (2016/10/22)

Embedded Systems, Android & Robotics INTERNSHIP CONTENT

Combining Today s Best Technologies. For Tomorrow s Break Through Discoveries. Feedback Versions Analog Sin/Cos. Control Modes.

10. RS-232C communication

Digital Input and Output

Controller Area Network

Topics. Interfacing chips

ASCII Code - The extended ASCII table

Absolute Encoder Multiturn

17. I 2 C communication channel

EMBEDDED SYSTEMS COURSE CURRICULUM

CAN Module Documentation

1) A/D MODULE (REV D) G23V ONLY 2) LATCH-UP G23V AND G49V ONLY 3) MSCAN MODULE (REV A) G23V AND G49V ONLY 4) MSCAN MODULE (REV A) G23V AND G49V ONLY

SBPC-21-CN. Customer Instruction Manual. FifeNet To ControlNet Gateway

CMSC 313 COMPUTER ORGANIZATION & ASSEMBLY LANGUAGE PROGRAMMING LECTURE 02, FALL 2012

ECE251: Thursday November 8

1.0. Presents. techathon 3.0

CDR File Information. Comments Direct PCM

The Link Layer and LANs: Ethernet and Swiches

DeviceNet Communication Manual

Lab 9: On-Board Time Generation and Interrupts

6.1 Combinational Circuits. George Boole ( ) Claude Shannon ( )

EE 308 Spring A software delay. To enter a software delay, put in a nested loop, just like in assembly.

WIRELESS EMBEDDED SYSTEM DESIGN

Workshop on In Vehicle Network using CAN By

Experiment 4.A. Speed and Position Control. ECEN 2270 Electronics Design Laboratory 1

Debounced 8 8 Key-Scan Controller

EC 6504 MICROPROCESSOR AND MICROCONTROLLER

Locus Engineering Inc

PAK-XI PS/2 Coprocessor Data Sheet by AWC

Transcription:

Microcontroller Applications Week 12 Dr. Bradley J. Bazuin Associate Professor Department of Electrical and Computer Engineering College of Engineering and Applied Sciences

Continuing Information PING Controller Area Network (CAN) Project 3 PLAN 2510 2

PING Ultrasonic range sensing Dist C air Tof 2 C air 0.606 T / sec 331.3 m c 3

Controller Area Network 4

CAN Physical Layer Data Frames are transmitted on a two-wire common bus as CAN high (CAN_H) and CAN low (CAN_L) signals. 4510 5

Typical CAN Signaling Frame A data frame consists of seven fields: start-of-frame, arbitration, control, data, CRC, ACK, and end-of-frame. Interframe space Data Frame Interframe space or overload frame Start of frame Arbitration field Control field Data field CRC field ACK field End of frame Figure 13.2 CAN Data frame Data: 0 to 8 Bytes

Multiple CAN Frames 7

CAN Controllers The controllers handle many if not all interface issues. Software is needed to: Initialize the controller Configure the controller Select the CAN addresses to pay attention to Read the messages when received Determine message type, address, amount of data, and data Prepare a transmit message if and when required Determine message type, provide address, fill data buffers and define amount of data Handle error conditions Reset, reinitialize or just turn off.

Procedure for Message Transmission Step 1 Identifying an available transmit buffer by checking the TXEx flag associated with the transmit buffer. (CANxTFLG) Step 2 Setting a pointer to the empty transmit buffer by writing the CANxTFLG register to the CANxTBSEL register. This makes the transmit buffer accessible to the user. (Moves it to the foreground.) Step 3 Storing the identifier, the control bits, and the data contents into one of the foreground transmit buffers. Step 4 Flagging the buffer as ready by clearing the associated TXE flag.

Using multiple transmit buffers (1) void can_transmit( void ) { static unsigned int buf_addr[3] = {0xFFFF, 0xFFFF, 0xFFFF; // Check if the incoming address has already been configured in a mailbox if( can.address == buf_addr[0] ){ // Mailbox 0 setup matches our new message // Write to TX Buffer 0, start at data registers, and initiate transmission while(!(can0tflg & TXE0)){asm("nop"); CAN0TBSEL = TX0; else if( can.address == buf_addr[1] ){ // Mailbox 1 setup matches our new message // Write to TX Buffer 1, start at data registers, and initiate transmission while(!(can0tflg & TXE1)){asm("nop"); CAN0TBSEL = TX1; else if( can.address == buf_addr[2] ){ // Mailbox 2 setup matches our new message // Write to TX Buffer 2, start at data registers, and initiate transmission while(!(can0tflg & TXE2)){asm("nop"); CAN0TBSEL = TX2; else Check for existing address 10

Using multiple transmit buffers (2) else{ // Check if we've got any un-setup mailboxes free and use them // Otherwise, find a non-busy mailbox and set it up with our new address if( buf_addr[0] == 0xFFFF ){ // Mailbox 0 is free // Write to TX Buffer 0, start at address registers, and initiate transmission CAN0TBSEL = TX0; buf_addr[0] = can.address; Check for free address else if( buf_addr[1] == 0xFFFF ){ // Mailbox 1 is free // Write to TX Buffer 1, start at address registers, and initiate transmission CAN0TBSEL = TX1; buf_addr[1] = can.address; else if( buf_addr[2] == 0xFFFF ){ // Mailbox 2 is free // Write to TX Buffer 2, start at address registers, and initiate transmission while(!(can0tflg & TXE2)){asm("nop"); CAN0TBSEL = TX2; buf_addr[2] = can.address; else 11

Using multiple transmit buffers (3) else { // No mailboxes free, wait until at least one is not busy while(( CAN0TFLG & 0x07 ) == 0x00){ asm("nop"); // Is it mailbox 0? if(( CAN0TFLG & TXE0 ) == TXE0) { // Setup mailbox 0 and send the message CAN0TBSEL = TX0; buf_addr[0] = can.address; // Is it mailbox 1? else if(( CAN0TFLG & TXE1 ) == TXE1) { // Setup mailbox 1 and send the message CAN0TBSEL = TX1; buf_addr[1] = can.address; // Is it mailbox 2? else if(( CAN0TFLG & TXE2 ) == TXE2) { // Setup mailbox 2 and send the message CAN0TBSEL = TX2; buf_addr[2] = can.address; Wait until a mailbox is not busy 12

Using multiple transmit buffers (4) // No matches in existing mailboxes // No mailboxes already configured, so we'll need to load an address - set it up CAN0TXIDR0 = (unsigned char)(can.address >> 3); CAN0TXIDR1 = (unsigned char)(can.address << 5); CAN0TXIDR3 = 0x00; // EID8 CAN0TXIDR4 = 0x00; // EID0 CAN0TXDLR = 0x08; // DLC = 8 bytes // Fill data into buffer, it's used by any address // Allow room at the start of the buffer for the address info if needed CAN0TXDSR0 = can.data.data_u8[0]; CAN0TXDSR1 = can.data.data_u8[1]; CAN0TXDSR2 = can.data.data_u8[2]; CAN0TXDSR3 = can.data.data_u8[3]; CAN0TXDSR4 = can.data.data_u8[4]; CAN0TXDSR5 = can.data.data_u8[5]; CAN0TXDSR6 = can.data.data_u8[6]; CAN0TXDSR7 = can.data.data_u8[7]; Load the data and send CAN0TFLG = CAN0TBSEL; // clear TXE flag to send 13

Receive Procedure When a valid message is received at the background receive buffer, it will be transferred to the foreground receive buffer and the RXF flag will be set to 1. (CANxRFLG & RXF) The user s program has to read the received message from the RxFG and then clear the RXF flag to acknowledge the interrupt and to release the foreground receive buffer. When all receive buffers in the FIFO are filled with received messages, an overrun condition may occur. (CANxRFLG & OVRIF)

Using receive buffers (1) void can_receive( void ) { unsigned char flags; // Read out the interrupt flags register flags = CAN0RFLG; // Check for errors if(( flags & CSCIF )!= 0x00 ){ // Clear error flags CAN0RFLG &= ~(CSCIF); Check if CSCIF error conditions to high 15

Using receive buffers (2) // No error, check for received messages else if(( flags & RXF )!= 0x00 ) { // Read in the info, address & message data can.address = CAN0IDAR0; can.address = can.address << 3; temp = CAN0IDAR1 >> 5; can.address = can.address temp; // Fill out return structure // check for Remote Frame requests and indicate the status correctly if(( CAN0IDAR1 & RTR ) == 0x00 ){ // We've received a standard data packet can.status = CAN_OK; // Fill in the data can.data.data_u8[0] = CAN0RXDSR0; can.data.data_u8[1] = CAN0RXDSR1; can.data.data_u8[2] = CAN0RXDSR2; can.data.data_u8[3] = CAN0RXDSR3; can.data.data_u8[4] = CAN0RXDSR4; can.data.data_u8[5] = CAN0RXDSR5; can.data.data_u8[6] = CAN0RXDSR6; can.data.data_u8[7] = CAN0RXDSR7; can.length = CAN0RXDLR; else{ // We've received a remote frame request // Data is irrelevant with an RTR can.status = CAN_RTR; // Clear the IRQ flag CAN0RFLG &= ~(RXF); Check RXF (RTR or message) 16

Using receive buffers (3) else{ can.status = CAN_ERROR; can.address = 0x0001; can.data.data_u8[0] = flags; // CAN0RFLG values returned Not CSCIF or RXF. Another error, possibly an overrun error (all receive buffers full). 17

Project #3 Plan Old (1) Historical Project Objectives: The theme of the project is to move an object that has been placed on a conveyor belt from a start position to a specific end position. Emulation: If it was built, a physical model of the plant would include the peripherals as follows: a Start Switch, a LED indicator, a Buzzer (a small speaker), an IR (Infra Red) Emitter and Receiver Module, a H- Bridge Motor Driver Module, and a Motor Encoder Module. In the absence of a fully assembled physical model, the IR Module will be substituted by a IR LED indicator (i.e., a common LED) and a bounce-free switch (STOP#), the output signal of the Encoder Module will be provided by a Function Generator (initial frequency is 5.5KHz), and the PWM signal to drive the H-Bridge will be verified using a Logic Analyzer (initial duty cycle is 50%). All signals should comply with TTL levels. 18

Project #3 Plan Old (2) Historical Project Description: The system should implement the operations as follows: upon receiving the asserted START# signal (active-low), the Buzzer should sound (the frequency of the output signal f = 5.5KHz), and the LED indicator should blink six times (at the rate of 1 blink/s). The Buzzer should also be turned off when the blinking is over. Then the IR Emitter LED should be turned on. The PWM signal driving the motor should also be turned on at this point (f = approx. 30KHz, initial duty cycle = 50% to match the input frequency of 5.5 KHz). Until an active-low signal from the IR Receiver (i.e., from the STOP# switch) is detected indicating that the object on the belt has tripped the IR beam, the system should sample the frequency of the signal received from the Encoder, and respond to it by adjusting the duty cycle of the PWM signal as given in the Table below. Input frequency (KHz) 4.7 4.9 5.1 5.3 5.5 5.7 5.9 6.1 6.3 Duty cycle of PWM signal (%) 90 80 70 60 50 40 30 20 10 When the desired end position for the object is reached, the PWM signal should be turned off (duty cycle = 0%), the Buzzer should sound (at 3.5KHz), and the LED indicator should blink 10 times (at the rate of 2 blinks/s). The Buzzer and the IR LED indicator should be turned off when the blinking is over. The process should restart when the START# signal is asserted again. You are to design, simulate, build, and demonstrate the operation of the system specified above using the Adapt9S12DP512 Board in the Lab and circuits constructed on your Breadboard. 19

Project #3 Plan New Goals Objectives: The theme of the project is to move an object that has been placed on a conveyor belt from a start position to multiple positions as specified. Operate as in an industrial environment with warnings and indicators. Use distance sensing to provide feedback control to the conveyor. Long operations and time information for post-operation checking. 20

Project #3 Plan New Goals Test Hardware A 2 in. wide by 9-11 in. long conveyor. A bidirectional, geared DC motor driven by an H-bridge. Maximum RPM 60, high torque gearing with possible position overshoot. PING with ADC/Temp. for position determination. H-bridge controls (PWM and direction). Information logging capability based on Real-Time Clock/Calendar and SCI0 port Indicators and warnings based on LEDs and audio output. Operational step counter based on 5x7 display. (5530 students only) Manual conveyor operation with keypad. (5530 students only) Step learning sequence based on keypad. 21

Project #3 Plan Dependence Progress in getting the hardware acquired and built. 22

Data Logging Collection of sensor information Inclusion of a time and data stamp with data Non-volatile storage Once data is collected, it should never be lost until intentionally deleted. 23

Useful Textual Formats A common file format is CSV comma separated values. From http://en.wikipedia.org/wiki/comma-separated_values In practice the term "CSV" refers to any file that: 1. is plain text using a character set such as ASCII, Unicode, EBCDIC, or Shift JIS, 2. consists of records (typically one record per line), 3. with the records divided into fields separated by delimiters (typically a single reserved character such as comma, semicolon, or tab; sometimes the delimiter may include optional spaces), 4. where every record has the same sequence of fields. Within these general constraints, many variations are in use. Therefore "CSV" files are not entirely portable. Nevertheless, the variations are fairly small, and many implementations allow users to glance at the file (which is feasible because it is plain text), and then specify the delimiter character(s), quoting rules, etc. If a particular CSV file's variations fall outside what a particular receiving program supports, it is often feasible to examine and edit the file by hand or via simple programming to fix the problem. Thus CSV files are, in practice, quite portable. 24

CSV File Access MATLAB M = csvread(filename); csvwrite(filename,m); Excel Will both read and write spread sheet information as CSV files 25

Text Files as Data Logs LT1 00 00000C3A LT1 01 00000C3E LT1 02 00000C39 LT1 03 00000C3E LT1 04 00000C3D LT1 05 00000C38 LT1 06 00000C3D LT1 07 00000C3B LT1 08 00000C38 LT1 09 00000C3A LT1 10 00000C39 LT1 11 00000C3B LT1 12 00000C3D LT1 13 00000C3E LT1 14 00000C3C LT1 15 00000C3C LT1 16 00000C3D LT1 17 00000C34 LT1 18 00000C39 LT2 19 00000C33 LT2 20 00000C38 LT2 21 00000C3C LT2 22 00000C3B LT2 23 00000C3A LT2 24 00000C39 LT2 25 00000C39 LT2 26 00000C38 LT2 27 00000C36 LT2 28 00000C3A LT2 29 00000C36 LT2 30 00000C36 LT2 31 00000C3B LT2 32 00000C3B LT2 33 00000C3A LT2 34 00000C31 LT2 35 00000C39 LT2 36 00000C3C LT2 37 00000C3A AD1 00 004EC098 AD1 01 004F4ABA AD1 02 005045FE AD1 03 004F9DFE AD1 04 004F1EC2 AD1 05 004F109A AD1 06 004EC6D4 AD1 07 00FDBA6C AD1 08 004EC2E2 AD1 09 004FCF1A AD1 10 004FB10A AD1 11 004F0E5C AD1 12 004EC294 AD1 13 004EF91A AD1 14 004EC762 AD1 15 00FD6922 AD1 16 004FE31E AD1 17 00502552 AD1 18 004E850A AD1 19 004F0B24 AD1 20 004F6118 AD1 21 004FB552 AD1 22 004E5D68 AD1 23 00FD36AE AD1 24 0000F424 AD1 25 00000000 AD1 26 00000028 AD1 27 00000000 AD1 28 00FD7FEC AD1 29 00000022 AD1 30 007D1E60 AD1 31 0075F434 AD2 32 0052E846 AD2 33 0053654E AD2 34 0052E1BA AD2 35 00523968 AD2 36 00528F3A AD2 37 0052CD8C AD2 38 00531E3A AD2 39 00FD3FAE AD2 40 00530494 AD2 41 00526354 AD2 42 00526E30 AD2 43 00525F96 AD2 44 005258B8 AD2 45 0052E750 AD2 46 005279F0 AD2 47 00FD2050 AD2 48 00528AF0 AD2 49 00521696 AD2 50 0051EEC0 AD2 51 00521C04 AD2 52 00528F18 AD2 53 00504A70 AD2 54 00C1C11A AD2 55 00FD4A7E AD2 56 000AE68C AD2 57 00000000 AD2 58 0000001E AD2 59 00000000 AD2 60 00FD6AC8 AD2 61 00000000 AD2 62 007D4B1C AD2 63 007D4A2A ISH 00 FFF8D764 ERR 00 06E00000 ERR 01 04F00000 ERR 02 04800000 ERR 03 04F00000 ERR 04 04800000 ERR 05 06F00000 ERR 06 00000000 ERR 07 00000000 ERR 08 00000000 ERR 09 00000000 ERR 10 00000000 ERR 11 007D49E6 ERR 12 00000000 ERR 13 00000000 ERR 14 00000000 ERR 15 00000000 ERR 16 00000000 ERR 17 00000000 ERR 18 00000000 ERR 19 00000000 ERR 05 06F00000 26

Example Translation LT1 0 00000AFA 2810 3.447000 LT1 1 00000AFC 2812 3.450000 LT1 2 00000AFA 2810 3.447000 LT1 3 00000AFC 2812 3.450000 LT1 4 00000AFB 2811 3.448500 LT1 5 00000AFA 2810 3.447000 LT1 6 00000AFB 2811 3.448500 LT1 7 00000AFB 2811 3.448500 LT1 8 00000AFA 2810 3.447000 LT1 9 00000AFA 2810 3.447000 LT1 10 00000AF9 2809 3.445500 LT1 11 00000AFC 2812 3.450000 LT1 12 00000AFB 2811 3.448500 LT1 13 00000AFD 2813 3.451500 LT1 14 00000AFA 2810 3.447000 LT1 15 00000AFC 2812 3.450000 LT1 16 00000AFB 2811 3.448500 min 3.4425 LT1 17 00000AF7 2807 3.442500 max 3.4515 LT1 18 00000AF9 2809 3.445500 diff 0.0090 27

Example Translation LT1 0 00000AFA 2810 3.447000 LT1 1 00000AFC 2812 3.450000 LT1 2 00000AFA 2810 3.447000 LT1 3 00000AFC 2812 3.450000 LT1 4 00000AFB 2811 3.448500 LT1 5 00000AFA 2810 3.447000 LT1 6 00000AFB 2811 3.448500 LT1 7 00000AFB 2811 3.448500 LT1 8 00000AFA 2810 3.447000 LT1 9 00000AFA 2810 3.447000 LT1 10 00000AF9 2809 3.445500 LT1 11 00000AFC 2812 3.450000 LT1 12 00000AFB 2811 3.448500 LT1 13 00000AFD 2813 3.451500 LT1 14 00000AFA 2810 3.447000 LT1 15 00000AFC 2812 3.450000 LT1 16 00000AFB 2811 3.448500 min 3.4425 LT1 17 00000AF7 2807 3.442500 max 3.4515 LT1 18 00000AF9 2809 3.445500 diff 0.0090 28