Embedded Systems Module. 6EJ505. C Tutorial 3: using the ICD3 rev tjw

Similar documents
Final Design Report 19 April Project Title: Pneumatic Exercise Machine

Embedded systems. Exercise session 3. Microcontroller Programming Lab Preparation

Table of Contents COMPANY PROFILE 1-1 SECTION 1. INTRODUCTION 1-1

PIC16F87X. 28/40-pin 8-Bit CMOS FLASH Microcontrollers. Devices Included in this Data Sheet: Pin Diagram PDIP. Microcontroller Core Features:

Designing Embedded Systems with PIC Microcontrollers

Microcontroller Overview

Laboratory: Introduction to Mechatronics. Instructor TA: Edgar Martinez Soberanes Lab 1.

Hong Kong Institute of Vocational Education Digital Electronics & Microcontroller. 8. Microcontroller

Lecture (03) PIC16F84 (2)

Speed Control of a DC Motor using Digital Control

BME 4900 Page 1 of 2. Meeting 2: Personal Progress Report 12/2/09 Team 12 with Drew Seils. Semester One Week Two

Interrupts on PIC18F252 Part 2

MT2 Introduction Embedded Systems. MT2.1 Mechatronic systems

PIC Microcontroller Introduction

MPLAB SIM. MPLAB IDE Software Simulation Engine Microchip Technology Incorporated MPLAB SIM Software Simulation Engine

* File: 8x8_matrix_vinyl.c. * Author: Phil Glazzard. * Created on 16 August 2016, 17:59. /* This design drives five 8x8 common cathode LED matrices

1 Introduction to Computers and Computer Terminology Programs Memory Processor Data Sheet Example Application...

#pragma config Usage. #pragma config Settings. #pragma config <setting>=<named value>

Remote Controlled KitchenAid Mixer for the Clients at ADEC. Appendices. Arnaud Bacye Karina Dubé Justin Erman Matthew Martin

Timer0..Timer3. Interrupt Description Input Conditions Enable Flag

University of Jordan Faculty of Engineering and Technology Department of Computer Engineering Embedded Systems Laboratory

University of Hawaii EE 361L MPLab Quick Tutorial and Project 2.1 Last updated September 1, 2011

Team 8: Robert Blake Craig Goliber Alanna Ocampo

Development Hardware. Target Board and In-circuit Debugger

Introduction to Microcontroller Apps for Amateur Radio Projects Using the HamStack Platform.

1 Introduction to Computers and Computer Terminology Programs Memory Processor Data Sheet... 4

Embedded Systems Lab Lab 1 Introduction to Microcontrollers Eng. Dalia A. Awad

DEV-1 HamStack Development Board

Capture Mode of Pic18F252

Section 29. Device Configuration Bits

Programmable Pet Feeder

SKP16C26 Tutorial 1 Software Development Process using HEW. Renesas Technology America Inc.

Timer2 Interrupts. NDSU Timer2 Interrupts September 20, Background:

M16C/62P QSK QSK62P Plus Tutorial 1. Software Development Process using HEW4

C and Embedded Systems. So Why Learn Assembly Language? C Compilation. PICC Lite C Compiler. PICC Lite C Optimization Results (Lab #13)

MICROPROCESSORS A (17.383) Fall Lecture Outline

MICROPROCESSORS A (17.383) Fall Lecture Outline

Chapter 13. PIC Family Microcontroller

Getting acquainted with the development tools June 27, 2006 ELE492 Embedded System Design Exercise 1

Lecture (04) PIC 16F84A programming I

Introduction. Embedded system functionality aspects. Processing. Storage. Communication. Transformation of data Implemented using processors

Dept. of Computer Engineering Final Exam, First Semester: 2016/2017

Timer1 Capture Mode:

Laboratory: Introduction to Mechatronics

Basic Embedded Software C Review Using MPLAB SIM. Loops. Embedded Systems Interfacing. 25 August 2011

ELCT708 MicroLab Session #1 Introduction to Embedded Systems and Microcontrollers. Eng. Salma Hesham

Z8 Encore! XP F1680 Series 8-Bit Flash Solution with Extended Peripherals

C Programming in Atmel Studio 7 Step by Step Tutorial

Linux Kernel Hacking Free Course, 3rd edition. HWMPS: Hardware Monitor & Protection System

ToolStick-EK TOOLSTICK USER S GUIDE. 1. Kit Contents. 2. ToolStick Overview. Green and Red LEDs. C8051F321 provides USB debug interface.

Bolt 18F2550 System Hardware Manual

TB033. Using the PIC16F877 To Develop Code For PIC16CXXX Devices INTRODUCTION. Stan D Souza, Rodger Richey Microchip Technology Inc.

C:\Users\cunningh\StaysOnPC\ME430 Downloads & Projects\exam2_problem1\problem1Cunningham.c

Embedded Systems. PIC16F84A Internal Architecture. Eng. Anis Nazer First Semester

An FTDI connection: The ATtiny microcontrollers don t have a hardware UART External Crystal header pins for an optional crystal

An Introduction to Designing Ham Radio Projects with PIC Microcontrollers. George Zafiropoulos KJ6VU

Section 33. Device Configuration (Part II)

PIC32MX150F128 Breakout Board

USB Debug Adapter. Power USB DEBUG ADAPTER. Silicon Laboratories. Stop. Run. Figure 1. Hardware Setup using a USB Debug Adapter

Embedded System Design

Interrupts on PIC18F252 Part 2. Interrupts Programming in C Language

Section 32. High-Level Device Integration

SH69P48A EVB. Application Notes for SH69P48A EVB SH69V48A JP2 J4(ICE_J4) S1 IDD TEST JP1 74HC273 JP4 JP3 74HC273 JP6 STKOVE JP7 SW1 J5(ICE_J5)

Lecture (09) PIC16F84A LCD interface LCD. Dr. Ahmed M. ElShafee

CHAPTER 6 CONCLUSION AND SCOPE FOR FUTURE WORK

Chapter 11: Interrupt On Change

Outlines. PIC Programming in C and Assembly. Krerk Piromsopa, Ph.D. Department of Computer Engineering Chulalongkorn University

UNIVERSITY OF BOLTON SCHOOL OF ENGINEERING B.ENG (HONS) ELECTRICAL AND ELECTRONIC ENGINEERING EXAMINATION SEMESTER /2016

EB-51 Low-Cost Emulator

Goal: We want to build an autonomous vehicle (robot)

Robosoft Systems in association with JNCE presents. Swarm Robotics

Microprocessors B Lab 1 Spring The PIC24HJ32GP202

UNIVERSITY OF BOLTON SCHOOL OF ENGINEERING. BEng(Hons) Electrical and Electronics Engineering SEMESTER 1 EXAMINATION 2016/2017

More Fun with Timer Interrupts

Introduction to 8051 microcontrollers

Inverted Pendulum Microprocessor and FPGA Manual Sheldon Logan July 3, 2006

MPLAB -ICD USER S GUIDE

Microchip 18F4550 Interface, Signal conditioning, USB, USB- RS-232, 16x2 LCD Interface

EE6008-Microcontroller Based System Design Department Of EEE/ DCE

PIC-MAXI-WEB development board Users Manual

Creating a robot project

AER201 Engineering Design. PIC DevBugger Manual

UNIVERSITY OF BOLTON SCHOOL OF ENGINEERING MSC SYSTEMS ENGINEERING AND ENGINEERING MANAGEMENT SEMESTER 2 EXAMINATION 2016/2017

_ V Intel 8085 Family In-Circuit Emulation. Contents. Technical Notes

CHAPTER 1 - World of microcontrollers

Typical applications where a CPLD may be the best design approach:

Model Answer Microcontrollers. MCQ Problems Total Q1 Q2

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

Introduction to the MC9S12 Hardware Subsystems

/*Algorithm: This code display a centrifuge with five variable speed RPM by increaseing */

11.0 Microchip PIC Development Tools

Manual of Board ET-PIC STAMP 18F8722-K22 ET-PIC STAMP 18F8722-K22

PIC-LCD-3310 development board Users Manual

Command-Line Compilers for C

2. Tutorial ESC Programming myavr MK2 USB UFO Doctor, June 5 rd, 2010

Figure 1. Proper Method of Holding the ToolStick. Figure 2. Improper Method of Holding the ToolStick

Department of Electronics and Instrumentation Engineering Question Bank

Hardware Interfacing. EE25M Introduction to microprocessors. Part V. 15 Interfacing methods. original author: Feisal Mohammed

HC12 Built-In Hardware

Figure 1. Proper Method of Holding the ToolStick. Figure 2. Improper Method of Holding the ToolStick

Transcription:

Embedded Systems Module. 6EJ505 C Tutorial 3: using the ICD3 rev. 27.9.16 tjw Images are reproduced from Reference 1. Microchip permits the use of its images for educational purposes. Main Learning Points C Programming 18F2420 peripheral initialization through SFRs Simple use of Pulse Width Modulation Using MPLABX and dev. tools Use of the ICD3 0. Preliminaries This introduction assumes you have MPLABX running on a PC, an ICD 3, and a Derbot board populated to Build Stage 1 (i.e. a House Derbot ). If you are running from your own laptop, you may need to install the USB device driver for the ICD3. 1. Introducing the Microchip in-circuit debugger (ICD 3) The features of the Microchip ICD 3 system are illustrated in Figures 1 and 2; the host computer is linked to the target system via the ICD 3 pod. The ICD is controlled from the host computer, which must be running MPLAB X. The ICD pod links to the host computer via a USB cable. It then connects to the target system via another cable, having five interconnections. These are shown in Figure 2. Figure 1 The ICD 3 can be used as a debugger, in which case it can program the microcontroller, at the same time downloading its own debug executive, which is loaded into the high end of program memory. Running from MPLAB X it can then execute all the functions of the MPLAB X simulator, except that now the program is actually running in the hardware. Running in this mode, the target has to remain connected to the ICD and the host computer. The ICD 3 can also be used simply as a programmer, downloading the program into the microcontroller. In this mode, once programmed the target must be disconnected from the ICD 3, and then runs independently.

Figure 2: The required ICD3 connections, as provided on the Derbot board The led functions on the ICD 3 are shown in Table 1. Table 1: LED Functions on the ICD 3 Figure 3: A House Derbot Connected to the ICD 3

2. Applying the ICD 3 as debugger Use the Blind Navigation Program Example below. Create this as a project, selecting ICD 3 under Select Tool, and build in the normal way. Connect the ICD 3 between computer and Derbot board, as shown in Figure 3; the board should be powered up and switched on. Set the ICD to operate initially in debug mode, by clicking Debug > Debug Project. This forces a new project build, and then automatically proceeds to download to the microcontroller. This takes a bit of time, and progress is reported as usual in the Output window. If the target system is powered and working, the ICD 3 should be able to identify the microcontroller, reporting its version number. The drop-down menu under Debug then becomes active, as does the toolbar, as seen in Tutorial Sheet 1. You can now test the operation of the downloaded program, exactly as you did with the simulator in Tutorial Sheet 2. The big difference is that now you are actually controlling the program as it runs in the hardware. This is powerful indeed! Instead of simulating inputs however you can of course press the microswitches, and observe the response of the leds. If you single-step in the main loop, try pressing the microswitches in turn, and see the response of the Port values in the Watch window as you step. Unlike when using the simulator, it is actual values from the hardware that are being transmitted back to the display you are seeing. As with the simulator, breakpoints can be set in the program by clicking on any line. 3. Applying the ICD 3 as programmer To program a product, the ICD 3 should be used in simple programmer mode. Exit the Debug session, and click Run > Run Project. Again MPLAB X will force a project Build, and will automatically connect to the ICD 3 and download. Now if you disconnect from the ICD 3, you should find your program runs you have a stand-alone system! Follow this with the Blind Navigation Program, appendix to this tutorial, and download and trial on one of the House Derbots. 4. Making changes to the Program Try varying: The length of the delays, The number of times the leds flash in the Diagnostic function, The response to microswitch pushes, e.g. make an led light as long as a switch is pressed, instead of just holding a steady state. Download the revised program each time to the Derbot board. 5. Line Following Note the physical location of the reflective opto-sensors on the Derbot, and from the circuit diagram check their connection to the microcontroller. When a reflective object is paced in front of them, the sensors output a logic 0 to the microcontroller, when there is no object they output a logic 1. Program a House Derbot to follow a white line on the trial track. You should be able to do this, with care, by adapting the Blind Navigation program.

Figure 4: Derbot Build Stage 2 6. Troubleshooting Refer to Reference 1. This also tells you, in Part 4 of its reference section, how you can use the little Test Interface Board (as seen in Figure 1) to conduct a self-test of the ICD 3. References 1. MPLAB ICD-3 In-Circuit Debugger User s Guide, for MPLAB X IDE. Microchip. Doc. DS50002081B.

/**************************************************************** Dbt_blind_Nav. Program Example 15.3 (rev.) Derbot moves by blind navigation. Moves forward, and reverses and turns on bump. Fixed rate PWM applied to set reasonable speeds. rev. 26.9.16 (for MPLABX) ***************************************************************** Clock is 4MHz */ #include <xc.h> //configuration settings. These take action at the moment of power-up, and can't change #pragma config OSC = HS //HS oscillator (for crystal use) #pragma config PWRT = ON, BOREN = OFF //power-up timer on, brown-out detect off #pragma config WDT = OFF //watchdog timer off #pragma config LVP = OFF //low voltage programming off #pragma config PBADEN = OFF //Port B A to D Enable is off #define _XTAL_FREQ 4000000 //function prototypes void initialise (void); void diagnostic (void); void leftmot_fwd(void); void rtmot_fwd(void); void rev_left(void); void rev_rt(void); void delay_100ms(char); //4 MHz clock frequency defined //main function int main(void) { initialise (); diagnostic (); //move microswitch states to diag leds while(1) { leftmot_fwd(); rtmot_fwd(); if (PORTBbits.RB4 == 0) rev_left(); if (PORTBbits.RB5 == 0) rev_rt(); delay_ms(100); //end of main() void initialise (void){ //set port bits as ip (1) or op (0). TRISA = 0; //set all Port A to output, pins 2 and 5 are motor enables TRISB = 0b00110000; //bits 5 and 4 of Port B are inputs, microswitches TRISC = 0; //Port C all output, includes PWM and diag leds ADCON1 = 0b00001111; //Port A is set to digital i.o. //switch all outputs off, for safety PORTA = PORTB = PORTC = 0; //set up conditions required for PWM T2CON = 0b00000100; //Timer 2 feeds PWM generator PR2 = 0xFF; //PR2 determines PWM period, this is max value CCP1CON = 0b0001100; //select PWM action in "Capture/Compare/PWM" (CCP) CCP2CON = 0b0001100; //end of function

void diagnostic (void){ //flashes leds at start of program, to demonstrate prog launch PORTCbits.RC6 = 1; //switch on led PORTCbits.RC5 = 0; //switch off led PORTCbits.RC6 = 0; //switch off led PORTCbits.RC5 = 1; //switch on led PORTCbits.RC6 = 1; //switch on led PORTCbits.RC5 = 0; //switch off led PORTCbits.RC6 = 0; //switch off led PORTCbits.RC5 = 1; //switch on led PORTCbits.RC5 = 0; //switch off led //end of function void leftmot_fwd (void){ CCPR2L = 196; //this number sets the PWM ratio, to fast forward PORTAbits.RA5 = 1; void rtmot_fwd (void){ CCPR1L = 196; //this number sets the PWM ratio, to fast forward PORTAbits.RA2 = 1; void leftmot_rev (void){ CCPR2L = 60; //this number sets the PWM ratio, to medium backward PORTAbits.RA5 = 1; void rtmot_rev (void){ CCPR1L = 60; //this number sets the PWM ratio, to medium backward PORTAbits.RA2 = 1; void rev_rt (void){ PORTCbits.RC6 = 1; //switch on led PORTAbits.RA5 = 0; //switch off motor enable leftmot_rev(); //run backwards rtmot_rev(); leftmot_fwd(); //left forwards, so machine spins PORTCbits.RC6 = 0; //switch off led void rev_left (void){ PORTCbits.RC5 = 1; //switch on led PORTAbits.RA2 = 0; //switch off motor enable leftmot_rev(); rtmot_rev(); rtmot_fwd(); PORTCbits.RC5 = 0; void delay_100ms(char n) { while (n!=0){ delay_ms(100); n = n-1;