Electronics Design Lab TUTORIAL PIC Microcontrollers Francesco Tenore 2/10/2006.

Slides:



Advertisements
Similar presentations
Introduction to PIC Microcontrollers
Advertisements

Analog to digital converter
Interrupts How to do 2 things at the same time. Need for interrupts Computers often have to deal with asynchronous events. That is to say events that.
An example Program switch reading, the most basic computer input operation.
Working with time: interrupts, counters and timers Chapter Six Dr. Gheith Abandah1.
MICROCONTROLLERS Why a microcontroller is needed?
Microprocessor Systems Design I Instructor: Dr. Michael Geiger Spring 2014 Lecture 32: PIC example programs: Analog to digital conversion.
Slides created by: Professor Ian G. Harris Inputs and Outputs PIC Vcc RA3 RA4 RA5  Make an LED toggle state when button is pressed  Need to read RA3,
Data acquisition and manipulation
Explain the introduction to ADC, ADC characteristics, Programming ADC using PIC18, Introduction to DAC and DAC interfacing with PIC18.
ECT 357 Ch 10 Analog to Digital COnversion. Today’s Quote: It’s better to die with a good name than to live with a bad one. It’s better to die with a.
Prof. Jorge A. Ramón Introducción a Microcontroladores.
Initial Position Orientation Tracking System (IPOTS) Group Members: Keiichi McGuireHenry Pham Marc TakamoriScott Spiro.
Eng. Husam Alzaq The Islamic Uni. Of Gaza
5-1 Timer/Counters In many microprocessor systems we need to:  count logic pulses  measure the frequency of signals  measure the period of pulses 
HT46 A/D Type MCU Series Data Memory (Byte) Program Memory HT46R22 (OTP) HT46C22 (Mask) 2Kx Kx16 4Kx HT46R23 (OTP) HT46C23 (Mask) HT46R24.
Railway Foundation Electronic, Electrical and Processor Engineering.
Railway Foundation Electronic, Electrical and Processor Engineering.
Engineering 1040: Mechanisms & Electric Circuits Fall 2011 Introduction to Embedded Systems.
Chapter 4 Starting to Program – an Introduction to Assembler The aims of this chapter are to introduce: the essentials of Assembler programming; the Microchip.
Smart-grid Interface with Photovoltaic Installation – Phase 2 PP-01 Team members: Matt Koresh Ivan Mills Matt Martin Advisor: Dr. Aliprantis.
In this PPT, all the materials covered up for the PIC microcontroller set-up would be studied. Preliminary skills: Knowing of basic C grammar and basic.
Microcontroller Programming How to make something almost do something else Raffi Krikorian MAS November 2003.
1 © Unitec New Zealand Embedded Hardware ETEC 6416 Date: - 10 Aug,2011.
Department of Electronic & Electrical Engineering Embedded system Aims: Introduction to: Hardware. Software Ideas for projects ? Robotics/Control/Sensors.
Building Assembler Programs Chapter Five Dr. Gheith Abandah1.
MCU: Interrupts and Timers Ganesh Pitchiah. What’s an MCU ?
Digital to Analogue Converter
Directives, Memory, and Stack. Directives Special commands to the assembler May or may not generate machine code Categories by their function Programming.
Atmel Atmega128 Overview ALU Particulars RISC Architecture 133, Mostly single cycle instructions 2 Address instructions (opcode, Rs, Rd, offset) 32x8 Register.
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.
 Mini-Computer  Microprocessor  The Brains  Arithmetic Logic Unit (ALU)  Control Unit  Program/ Data Storage  Peripherals (Input/Output) Low-Cost.
Architecture and instruction set. Microcontroller Core Features:  Operating speed: DC - 20 MHz clock input DC ns instruction cycle Up to 8K x.
By James Cockrell and Justin Loveless
July 18, UCSD - R.A. de Callafon Short Intro to Micro Processors and I/O functions of our Kinetic Sculpture Control Box Raymond de Callafon.
Department of Electronic & Electrical Engineering Introduction to microcontrollers A microcontroller is a small computer on a single integrated circuit.
Working with Time: Interrupts, Counters and Timers
Microcontrollers session. What is Microcontroller? Microcontroller is composed of microprocessor,ram, flash memory,EEPROM and some modules like timers,
PIC12F629/675. “Wide variety” 8-84 pin RISC core, 12/14/16bit program word USART/AUSART, I 2 C, ADC, ICSP, ICD OTP/UV EPROM/FLASH/ROM Families: PIC12,
D ATA A CQUISITION AND M ANIPULATION. A NALOG V S. D IGITAL Q UANTITIES 2.
Microcontrollers A Practical Approach Ernesto Arroyo
Microcontrollers JULES CALELLA. Microcontrollers vs Microprocessors  Microprocessors – do not contain RAM, ROM, I/O  Microcontrollers – The whole package.
Programming PIC 16F84A in Assembly. PIC16F84 pin-out and required external components.
5-2-1 PIC microcontroller. Learning objectives To aid revision, areas that are examinable are identified by a vertical line in the left margin. Where.
I/O PORTS. General purpose I/O pins can be considered the simplest of peripherals. They allow the PICmicro™ to monitor and control other devices. To add.
CEng3361 CENG 336 INT. TO EMBEDDED SYSTEMS DEVELOPMENT Spring 2011 Recitation 06.
Microprocessor Systems Design I
Microprocessor Systems Design I
Microprocessor Systems Design I
Micro-processor vs. Micro-controller
Microprocessor Systems Design I
C. K. PITHAWALA COLLEGE OF ENGINEERING AND TECHNOLOGY
Microprocessor Systems Design I
Microprocessor Systems Design I
Microprocessor Systems Design I
Microprocessor Systems Design I
EECE.3170 Microprocessor Systems Design I
The Arduino Microcontroller: Atmel AVR Atmega 328
The PIC uCs PIC Microcontroller and Embedded Systems Muhammad Ali Mazidi, Rolin McKinlay and Danny Causey Eng. Husam Alzaq The Islamic Uni. Of Gaza 11-1.
ECE 354 Computer Systems Lab II
PIC18F458 Analog-to-Digital
Introducing the PIC Mid-Range Family and the 16F84A
ADC and DAC Data Converter
EECE.3170 Microprocessor Systems Design I
INSTRUCTION SET.
EECE.3170 Microprocessor Systems Design I
EECE.3170 Microprocessor Systems Design I
EECE.3170 Microprocessor Systems Design I
ADC and DAC Data Converter
PIC Microcontroller ADC interfacing Prof. Ashvini Kulkarni
Presentation transcript:

Electronics Design Lab TUTORIAL PIC Microcontrollers Francesco Tenore 2/10/2006

The Microchip ® PIC ucontrollers Characteristics –types; speeds; I/O pins; Analog to Digital Converters; Capture/Compare modules Programming (MPLab) Instruction set Implementations and Examples

Characteristics RISC CPUs –8-bit –16-bit Number of I/O pins: 4-70 Memory types and sizes: –Flash; OTP; ROM –0.5k – 256k

Speeds All PICs require oscillators to execute instructions: –Internal * (low speeds, up to 8 MHz) –External (high speeds, up to 40 MHz) Instructions are executed at least at ¼ oscillator speed (4 clocks/instruction) ( * Note: not all PICs have internal oscillators)

A/D converters and C/C modules All PICs have between 0 and 16 A/D converters with 8/10-bit resolution 8-16 bit Timers/Counters Comparator Modules (0-2)

Example: PIC16F877A 5/6 Programming pins 8 A/D channels 2 Oscillator Inputs 2 RS-232 inputs 33 I/O ports

Programming – MPLab and Assembly

MPLab Assembly compiler for programming PICs Based on specific PIC instruction set To upload the program: 1.Compile: Project Build All (Ctrl+F10) 2.Erase the device: Programmer Erase Flash Device 3.Program: Programmer Program

Instruction Set 35 single word instructions –Byte oriented file register operations –Bit oriented file register operations –Literal and control operations

Example 1 Using the PIC12F683 as a 2-state switch

Giving memory to a pushbutton

In this example we: –Store the state of the LED and Turn off if on and Turn on if off

Example 2 Using the PICs A/D converters for Pulse Width Modulation

Pulse Width Modulation (PWM) 1-2 ms pulse used to control servomotors In this example, we: – ACQUIRE an analog 0-5V signal –CONVERT it into a 1-2 ms pulse that depends on the analog voltage and output the result on an output pin –REPEAT

Steps for Analog-to-Digital Conversion 1. Configure the A/D module: Configure analog pins/voltage reference and digital I/O (ADCON1) Select A/D input channel (ADCON0) Select A/D conversion clock (ADCON0) Turn on A/D module (ADCON0) 2. Configure A/D interrupt (if desired): Clear ADIF bit Set ADIE bit Set PEIE bit Set GIE bit 3. Wait the required acquisition time. 4. Start conversion: Set GO/DONE bit (ADCON0) 5. Wait for A/D conversion to complete, by either: Polling for the GO/DONE bit to be cleared (with interrupts enabled); OR Waiting for the A/D interrupt 6. Read A/D result register pair (ADRESH:ADRESL), clear bit ADIF if required. 7. For the next conversion, go to step 1 or step 2, as required. The A/D conversion time per bit is defined as TAD. A minimum wait of 2TAD is required before the next acquisition starts.

ADC on PIC 16F877 Configuration: –ADCON0, ADCON1 Result –ADRESH, ADRESL (See handout)

Samples The microchip website: offers samples of PICs (maximum 5) that are sent to you for free. Please me at if you have any

; EDL_test1.asm: blinks an LED when pushbutton is pressed. #INCLUDE "P12F683.INC" ORG 0x bsf STATUS,RP0 ;Bank 1 movlw b' ' ; 0x00 movwf OSCCON ; 0x01 goto START ; 0x02 ORG 0x START: COUNTER EQU 0x21 TEMP EQU 0x22 BCF STATUS,RP0 ;Bank 0 CLRF GPIO ;Init GPIO MOVLW 07h ;Set GP to MOVWF CMCON0 ;digital I/O BSF STATUS,RP0 ;Bank 1 CLRF ANSEL ;digital I/O MOVLW 28h ;Set GP and GP as inputs MOVWF TRISIO ;and set GP as outputs BCF STATUS,RP0 ;Bank 0 BSF GPIO,0 LOOP: BTFSS GPIO,5 ; skip if button NOT pressed GOTO CLEAR_ROUTINE ; otherwise GOTO LOOP CLEAR_ROUTINE: INCF COUNTER,1 ; increment the counter MOVLW 0x01 ; w=1 ANDWF COUNTER,0 ; counter AND w => ; w = 0x01 MOVWF TEMP ; TEMP = 0x01 BTFSC TEMP,0 ; skip if TEMP is 0 BCF GPIO,0 ; otherwise, clear GPIO BTFSS TEMP,0 BSF GPIO,0 ; if it's 1, then set it. LOOP2: BTFSC GPIO,5 GOTO LOOP GOTO LOOP2 END