Embedded Systems Lecture 3: Using MPLAB, C and the Computer Hardware Ian McCrumRoom 5B18, Tel: 90 366364 voice mail on 6 th ring

Slides:



Advertisements
Similar presentations
Simple Microcontroller Programming with PIC16F88.
Advertisements

ELECTRONIC SYSTEMS NESI NanoRacks Embedded System Integration Board HARDWARE Functional Design.
Slides created by: Professor Ian G. Harris PIC Development Environment MPLAB IDE integrates all of the tools that we will use 1.Project Manager -Groups.
Robotics Club, Snt Council2 The 3 Schools of Robotics: Mechanical Design – Types of motors – Material selection –
MICRO-CONTROLLER: A microcontroller is the brain of the robot: These are: 1. Integrated Circuits (ICs) 2. Programmable.
Lecture 5: PIC32 development board, Timers ADC and interrupts,
Using PDG with e2studio: Example
EEE305 Microcontroller Systems Lecture 4: The PIC microprocessor and the Microchip C Compilers Teaching resources on on
Railway Foundation Electronic, Electrical and Processor Engineering.
Digital I/O Connecting to the Outside World
EEE305 Microcontroller Systems Lecture 5B: Simple I/O Embedded C using PIC microcontrollers Teaching resources on on
ASPPRATECH.
Microprocessor and Microcontroller Based Systems Instructor: Eng.Moayed N. EL Mobaied The Islamic University of Gaza Faculty of Engineering Electrical.
1-1 SYS Module System Clocks FXTAL BCLK Reset Circuit Reset Conditions Bootstrap Initialization.
Engineering 1040: Mechanisms & Electric Circuits Fall 2011 Introduction to Embedded Systems.
Programming 8-bit PIC Microcontrollers in C Martin Bates Elsevier 2008.
Lecture 6 UARTs and applying PPS
Microprocessor Block Diagram
PIC microcontrollers. PIC microcontrollers come in a wide range of packages from small chips with only 8 pins and 512 words of memory all the way up to.
EEE527 Embedded Systems Lecture 8: Practical Interrupts Ian McCrumRoom 5B18, Tel: voice mail on 6 th ring Web site:
Chapter 1 The First Flight Creating the first project and saying “Hello to the World”
Silicon Labs ToolStick Development Platform
Department of Electronic & Electrical Engineering Embedded system Aims: Introduction to: Hardware. Software Ideas for projects ? Robotics/Control/Sensors.
Renesas Technology America Inc. 1 M16C/Tiny SKP Tutorial 2 Creating A New Project Using HEW4.
Objectives How Microcontroller works
EEE527 Embedded Systems Lecture 3: Chapter 1: Using MPLAB (X) + XC32 Ian McCrumRoom 5B18, Tel: voice mail on 6 th ring
Parallel Ports, Power Supply and the Clock Oscillator Material to be covered  Parallel I/O ports  Interfacing external switches and LEDs  Clock Oscillator.
The 8051 Microcontroller and Embedded Systems
Digital to Analogue Converter
One of the most important feature of the microcontroller is a number of input/output pins used for connection with peripherals. In the case of PIC 167CX,
Arduino. What is it? A open-source software suite and single-board microcontroller. Allows easy and affordable prototyping of microcontroller applications.
Microprocessors A practical approach Subjects Goals for this module Results Subjects of the module Plans Questions.
Renesas Technology America Inc. 1 SKP8CMINI Tutorial 2 Creating A New Project Using HEW.
EEE527 Embedded Systems Lecture 9: Chapter 9: UARTs (version 2 – 25/11/13 changed slides 11-17, added new at end) Ian McCrumRoom 5B18, Tel: voice.
1 LHO 13 The 8051CF020 and the University Daughter Card.
EEE527 Embedded Systems Lecture 10B:Chapter 11 Analogue to Digital Convertors (ADCs) (version 2: 25/11/13, see after slide 20 Ian McCrumRoom 5B18, Tel:
MICROCONTROLLER SYSTEMS Part 1. Figure 1.1Elements of a digital controller CPU Central Processing Unit Input Peripherals Output Peripherals ROM Read Only.
Chapter 2 Introducing the PIC Mid-Range Family and the 16F84A The aims of this chapter are to introduce: The PIC mid-range family, in overview The overall.
Atmel AVR Jared Bevis January 14, The Power of Your Chips The main power of your chips lies in the programming language/compiler available to you.
Chapter 7 Larger Systems and the PIC 16F873A The aims of this chapter are to introduce: The architecture of the 16F873A microcontroller; The 16F873A memory.
IO Subsystem IV Ports and peripherals. IO Subsystem (1) All devices connected to the system buses, other than memory and CPU – Input and output ports.
Getting Started With the Arduino Uno
Renesas Technology America Inc. 1 SKP8CMINI Tutorial 2 Creating A New Project Using HEW.
Chapter 5 - Interrupts.
Lecture 7: Overview Microprocessors / microcontrollers.
Slides created by: Professor Ian G. Harris Embedded Systems  Embedded systems are computer-based systems which are embedded inside another device (car,
Chapter 3 Parallel Ports, Power Supply and the Clock Oscillator The aims of this chapter are to introduce: Why we need parallel input/output; How simple.
Chapter Microcontroller
Submitted by:.  Project overview  Block diagram  Power supply  Microcontroller  MAX232 & DB9 Connector  Relay  Relay driver  Software requirements.
Components of a typical full-featured microcontroller.
Microcontrollers JULES CALELLA. Microcontrollers vs Microprocessors  Microprocessors – do not contain RAM, ROM, I/O  Microcontrollers – The whole package.
Introduction to AVR Name : 1) Abhishek Yadav ) Prakash Giri ) Kheni Niral ) Bhadresh Langadiya Branch.
A Quick Start Guide to PIC16F877 microcontroller And Microchip Development Environment A Quick Start Guide to PIC16F877 microcontroller And Microchip Development.
CEng3361/18 CENG 336 INT. TO EMBEDDED SYSTEMS DEVELOPMENT Spring 2007 Recitation 01.
 Mini-Computer ◦ Microprocessor  The Brains  Arithmetic Logic Unit (ALU)  Control Unit  Program/ Data Storage  Peripherals (Input/Output)  Low-Cost.
Popular Microcontrollers and their Selection by Lachit Dutta
PROGRAMMABLE LOGIC CONTROLLERS SINGLE CHIP COMPUTER
Fundamentals of Computer Engineering
Input/Output Ports and Interfacing
ABSTRACT The controller continuously polls the temperature with certain regular time intervals and displays over the 7_segment display The temperature.
For further information
Microcontroller Applications
PC Mouse operated Electrical Load Control Using VB Application
SUBMITTED BY EDGEFX TEAM
Introduction to Circuits
Future Designs, Inc. Your Development Partner
Introducing the PIC Mid-Range Family and the 16F84A
CSCI1600: Embedded and Real Time Software
CSCI1600: Embedded and Real Time Software
PIC Microcontroller ADC interfacing Prof. Ashvini Kulkarni
Presentation transcript:

Embedded Systems Lecture 3: Using MPLAB, C and the Computer Hardware Ian McCrumRoom 5B18, Tel: voice mail on 6 th ring Web site:

Makes microcontrollers, (memories, sensors analog components and power supply chips.) PIC 10F,12F,16F and 18F – supported by the XC8 compilers PIC24F, dsPIC30F & dsPIC 33F - supported by the XC16 compiler PIC32MX and PIC32MZ supported by the XC32 compiler. Gives away MPLAB X IDE and XC family of compilers Has peripheral libraries and Harmony framework to ease use Has support forums and many users

Development boards Microchips’s own starter kits Fubarino modules Digilent boards (including arduino form factor)

Digilent INC DP32 PIC32MX250F128B – 128k Flash/32K SRAM/50MHz 4 LEDs, 2 Pushbuttons, Variable resistor, USB i/f SPI (4 wires) I2C (2 wires) two UARTS (share pins) Analogue input – set up for temperature

RB0/PGD RB1/PGC RB2 RB3 RB4 RB7 RB15(AN9) RB13(AN11) LED 3 LED 2 LED 1 LED 0 LEDs all via 4k7 to base of transistors ‘1’ lights LED BTN2 BTN3 10k series Resistors and 10k pullups, Switches to ground VR1 10k Variable resistor 3v3 to 0v, feed to slider via 1k IC3 Supplies temperature as Voltage, MCP9701A Sensor, 3 pin TO92 PGCPGD MCLR 3V3 0V ICSP to PICKIT3 Programmer Pin 1 RB5/USBID (for USB OTG) VBUS D-/RB11 D+/RB10 VCAP VUSB VDD AVDDVSS AVSS RA2/OSC1 RA3/OSC2 To 8MHz XTAL Via 680R and With 30pF caps JP3 JP2 JP1 MINI – USB For power & bootloa ding PIC32MX250F128B 28 PIN DIL PACKAGE 3V3 REG (SDA1)RB9 (SCL1)RB8 (SCK1)RB14 (SD0)RA4 (SDI)RA1 (CS)RA0 10k 2k2 JP5 JP6 JP7 DC IN J6 NB, link only One of these MCLR I2C – or use PPS to set them to UART2 SPI – or use PPS to set them to UART1 Diagram of DP32 board, see full schematic for details!

Before running code we must configure the CPU. This requires careful study of the datasheet and is tedious. However, it maybe that the default values will work, or at least the code below is worth noting Good Practice – author * version number You must include, stdio.h and stdlib.h declare a prototypes for main and EXIT_SUCCESS A function prototype for my waitabit function

Complete Process to get code to run Plug in PICKIT3 – do this before running MPLAB. Check in “devices and printers” section of the control panel that the device is recognised and a driver installed. If using a ttl USB UART plug in now as well (see week 4) Start MPLAB X and run the new project wizard.

Screendumps of the 7 steps…

Lastly the project name and folder locations. – start names with letters, avoid funny characters! NB watch out that this is ticked on your second or subsequent projects

Look at the project navigator and project properties windows Rightclick on “Source Files and select new main – give the file a sensible name Make sure CPU is correct Make sure you can see the PICKIT3 here. You may need to reboot if not! Rightclick here to change project properties

If powering the board from the PICKIT3 Rightclick on the project name and select properties

A more complete C Source file Will have all these Rather than Hoping the last person to program the configuration fuses set them Correctly You should have some understanding of what each of these bits does Study them using the datasheet…

The Hardware The PIC32MX1xx/2xx family The PIC32MX256F128B chip There is a datasheet on the PIC32MX1xx/2xx and a reference manual on the PIC32MX (downloadable as individual chapters) I also like the book “Beginner’s guide to Programming the PIC32” by Thomas Kibalo)

PIC32MX family Based on MIPs core with microchip legacy peripherals E.g the PIC32MX256F128B has 256k words of flash and 128kBytes (32kWords) of RAM Uses 3.3V logic (some of the pins can be destroyed by applying 5 Volts!) 21 i/o lines, 9 channels of ADC (10 bit,1.1Msps) Two UARTs, two SPI, two I2C ports, 5 timers ‘B’ version is a 28 pin PDIP package Has pin mapping system to allow selected peripherals to be mapped to certain pins – we will use this for the UARTs This is called “Peripheral Pin Select” or PPS.

Simple I/O using the PIC32MX User programmable pins; digital input, digital output, analog input or connected to a peripheral’s input or output. Some peripherals can be selected using PPS. Special Function Registers provided to select and control functions; these are the SFRs. SFRs allow outputting a 16 bit word, or setting, clearing or toggling individual bits in an atomic fashion (guaranteed one clock cycle)

Clues to functions of pins Page 4 of the Datasheet (above) and pages part of which is shown below

Here we see pin 2 can be an analog pin (AN0) or a simple digital pin as RA0 (input or output) or a re-mappable peripheral pin RPA0

A pin’s output can come from either a peripheral or a digital data path. The peripheral has to be enabled (on) to drive a pin. Pins have a TRIS SFR to set the digital direction, ‘0’=output, ‘1’=input Pins have a 16 bit PORT SFR allows reading or writing a pin. Only RA0, 1, 3 and 4 are used, though all 16 are available for PORTB. Pins have a LAT SFR, allows latching input (or output). Writing to LAT has same affect as writing to PORT. (see diagram for details) Pins have SFRs to select weak pull-up, pull-down resistors or open drain; CNPUx,CNPDx or ODCx As well as PORTx SFRs there are PORTSETx, PORTCLRx and PORTxINV. (x=A or B) The SFRs are available as 16 bit WORDs or a struct of bits. There is input change registers that allow the i/o ports to generate interrupts whenever a change occurs on a digital input pin. You enable this though the CNENx and CNCONx registers and can check whether a change has happened since the last time you read the PORTx bit using the CNSTATx register. You can either poll (manually look at) the interrupt flag registers or configure the PIC for interrupts.

Summary (see section 12 of ref man) ANSELA=0000 ; // pins are NOT to be analog TRISB=0x0000 (or TRISAbits.RA0=0x1F;) ODCB=1;// make RB0 open drain PORTB=0x00FF ; // output 8 ‘1’s LATB=0x0055 ; // output CNPUA=1; // set pullup on RA0 CNPDA=8;// set pulldown on RA3 PORTBINV=0x0001;// invert RB0, rest unchanged We will cover change notification later – after we cover interrupts. Note that most of the time you just need ANSELA if using PORTA, TRISA and TRISB to set digital direction and then you write or read from PORTA or PORTB accordingly - or use PORTAbits.Rax or PORTBbits.RBx (x in this case is numeric)

Peripheral Pin Select (PPS) The number of available pins is dependent on the particular device and its pin count. Pins that support the PPS feature include the designation “RPn” in their full pin designation, where “RP” designates a remappable peripheral and “n” is the remappable port number Not every peripheral pin can map to every RP pin, you must consult a table (two tables actually, one for inputs and one for outputs. Analog and I2C peripherals never remap pins

E.G to map UART1 RX to a PIN

So U1RX can only map to bits RA2,4 or RB2, or 13 in the PIC32MX256F128B On the DP32, RA2 is used by OSC1, RA4 is normally SDO1, RB2 is an LED and RB13 is free – but wired to a pad that can have a temperature sensor added.

For U1TX So U1TX can only be output from RA0, RB3,4,7 or 15

Similarly for UART2

RB0/PGD RB1/PGC RB2 RB3 RB4 RB7 RB15(AN9) RB13(AN11) LED 3 LED 2 LED 1 LED 0 LEDs all via 4k7 to base of transistors ‘1’ lights LED BTN2 BTN3 10k series Resistors and 10k pullups, Switches to ground VR1 10k Variable resistor 3v3 to 0v, feed to slider via 1k IC3 Supplies temperature as Voltage, MCP9701A Sensor, 3 pin TO92 PGCPGD MCLR 3V3 0V ICSP to PICKIT3 Programmer Pin 1 RB5/USBID (for USB OTG) VBUS D-/RB11 D+/RB10 VCAP VUSB VDD AVDDVSS AVSS RA2/OSC1 RA3/OSC2 To 8MHz XTAL Via 680R and With 30pF caps JP3 JP2 JP1 MINI – USB For power & bootloa ding PIC32MX250F128B 28 PIN DIL PACKAGE 3V3 REG (SDA1)RB9 (SCL1)RB8 (SCK1)RB14 (SD0)RA4 (SDI)RA1 (CS)RA0 10k 2k2 JP5 JP6 JP7 DC IN J6 NB, link only One of these MCLR I2C – or use PPS to set them to UART2 SPI – or use PPS to set them to UART1 Diagram of DP32 board, see full schematic for details! Further restraints – the DP32 schematic Note, using PPS you can wire U1RX to RA4,RB13 or RB2. U1TX to RA0,RB3,RB4,RB7,U2RX to RB5,RB8,RA1,RB1 and U2TX to RB9 or RB14

You should now understand the code on the left… ANSELB… TRISB…. PORTB…. Etc.,

Microchip also supply a peripheral library – mPORTBSetPinsDigitalOut(BIT_0|BIT_1|BIT_2); mPORTBSetPinsDigitalOut(7); mPORTBSetPinsDigitalIn(BIT_6|BIT_7|BIT_13); mPORTBSetPins(0x20C0); mPORTBClearBits(BIT_0); mPORTBClearBits(1); mPORTBToggleBits(BIT_7); mPORTBToggleBits(0x80); mPORTBReadBits(BIT_2); mPORTBReadBits(4); mPORTBWrite(0x00FF); Value=mPORTBRead(); Frankly this is a lot of typing, a lot of reading needed to get the correct function. Microchip say it makes for portable code, I doubt that. It might make for more readable code to a programmer using Plib every day of the year but for occasional coding I prefer to access the registers “manually” – you need only read the datasheet and do not also need to read the plib documentation

Exercises Plugin PICKIT3 or 2 Start MPLABX – new project Try out code from website – simple_blinker_timer1.c (load into wordpad then copy and paste into MPLAB Modify … chevrons …