Term 8 Electrical and Computer Engineering Project Course January 2002 Mark Simms Steven Taylor PIC Development, The Easy Way.

Slides:



Advertisements
Similar presentations
EMS1EP Lecture 4 Intro to Programming Dr. Robert Ross.
Advertisements

JED Microprocessors Pty Ltd Presenting the JED T430 low-cost Projector Controllers Nov 22nd, 2009.
Lab7: Introduction to Arduino
What is Arduino?  Arduino is a ATMEL 168 micro-controller kit designed specially for small projects  User friendly IDE(Integrated Development Environment)
Initial Position Orientation Tracking System (IPOTS) Group Members: Keiichi McGuireHenry Pham Marc TakamoriScott Spiro.
Design and Implementation of a Virtual Reality Glove Device Final presentation – winter 2001/2 By:Amos Mosseri, Shy Shalom, Instructors:Michael.
1-1 Embedded Software Development Tools and Processes Hardware & Software Hardware – Host development system Software – Compilers, simulators etc. Target.
Railway Foundation Electronic, Electrical and Processor Engineering.
Timers and Interrupts Shivendu Bhushan Summer Camp ‘13.
Railway Foundation Electronic, Electrical and Processor Engineering.
Embedded Programming and Robotics Lesson 2 C Programming Refresher C Programming1.
Introduction to Arduino Prepared by R. Lamond.  “Arduino is an open-source electronics prototyping platform based on flexible, easy- to-use hardware.
BLDC MOTOR SPEED CONTROL USING EMBEDDED PROCESSOR
Engineering 1040: Mechanisms & Electric Circuits Fall 2011 Introduction to Embedded Systems.
Microcontroller Programming How to make something almost do something else Raffi Krikorian MAS November 2003.
Working with Arduino: Lesson #1: Getting Acquainted with the Kit EGN1007.
Shell and Flashing Images Commands and upgrades. RS-232 Driver chip – ST3232C Driver chip is ST3232C Provides electrical interface between UART port and.
Colorado Space Grant Consortium Gateway To Space ASEN 1400 / ASTR 2500 Class #12 Gateway To Space ASEN 1400 / ASTR 2500 Class #12 T-58.
Serial Communication ETEC 6416.
Part 1 Using the ARM board And start working with C Tutorial 5 and 6
The 6713 DSP Starter Kit (DSK) is a low-cost platform which lets customers evaluate and develop applications for the Texas Instruments C67X DSP family.
EE 1106: Introduction to EE Freshman Practicum
NetBurner MOD 5282 Network Development Kit MCF 5282 Integrated ColdFire 32 bit Microcontoller 2 DB-9 connectors for serial I/O supports: RS-232, RS-485,
Objectives How Microcontroller works
© 2008, Renesas Technology America, Inc., All Rights Reserved 1 Purpose  This training course describes how to configure the the C/C++ compiler options.
September, 2007ENGR Low-Level Robot Control Mechatronics: Motors, sensors & embedded controls.
Introduction to Python
MICROPROCESSOR INPUT/OUTPUT
Introduction to PIC-C. Required Software PIC-C Compiler Firmware Downloader Driver for the USB->Serial Adapter.
MCU: Interrupts and Timers Ganesh Pitchiah. What’s an MCU ?
Arduino. What is it? A open-source software suite and single-board microcontroller. Allows easy and affordable prototyping of microcontroller applications.
Page 1 D&C EBV Seminar June 2003 Motor Demo C868 Chevillot/Jansen June 2003 N e v e r s t o p t h i n k i n g. Infineon C868 Hands On Training CAPCOM6.
RS232 #use rs232(baud=9600,xmit=PIN_C6,rcv=PIN_C7
MICROCONTROLLER SYSTEMS Part 1. Figure 1.1Elements of a digital controller CPU Central Processing Unit Input Peripherals Output Peripherals ROM Read Only.
Introduction to PIC-C. Installing PIC-C Goto Username/pass = guest/cpecmu Download and install:  IDEUTIL  PCWHD.
Slide 1 Project 1 Task 2 T&N3311 PJ1 Information & Communications Technology HD in Telecommunications and Networking Task 2 Briefing The Design of a Computer.
Code The Arduino Environment.
By James Cockrell and Justin Loveless
Introduction to Python Dr. José M. Reyes Álamo. 2 Three Rules of Programming Rule 1: Think before you program Rule 2: A program is a human-readable set.
JDS5 Training Guide. On Start Up you will see this screen click the OK button Click OK.
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.
Teaching Digital Logic courses with Altera Technology
Analog to Digital Conversion - ADC Mark Neil - Microprocessor Course 1 Device Drivers – Measuring Voltages.
Lab 1 Summary.
بسم الله الرحمن الرحيم MEMORY AND I/O.
Serial Communication RS-232. In order to make two devices communicate, whether they are desktop computers, microcontrollers, or any other form of integrated.
Components of a typical full-featured microcontroller.
Microcontroller basics Embedded systems for mortals.
NAM S.B MDLAB. Electronic Engineering, Kangwon National University 1.
ME 120: Arduino Programming Arduino Programming Part II ME 120 Mechanical and Materials Engineering Portland State University
Introduction to Computer Programming Concepts M. Uyguroğlu R. Uyguroğlu.
Programming and Debugging with the Dragon and JTAG Many thanks to Dr. James Hawthorne for evaluating the Dragon system and providing the core content for.
DEPARTMENT OF ELECTRONICS ENGINEERING V-SEMESTER MICROPROCESSOR & MICROCONTROLLER 1 CHAPTER NO microcontroller & programming.
1. PIC ADC  PIC18F877 has 8 analog input channels i.e. port A pins(RA0 to RA5) and port E pins(RE1 and RE2). These pins are used as Analog input pins.
Arduino.
Programming and Debugging with the Dragon and JTAG
Microcontroller basics
SCADA for Remote Industrial Plant
Microcontroller Applications
Overview Basic PIC Circuits Development in C using CCS
Arduino Part 1 Topics: Microcontrollers Programming Basics
Programming Boe-Bots (Part 1)
Roller Coaster Design Project
Lesson 2: Introduction to Control programming using Labview
Working with Arduino: Lesson #1: Getting Acquainted with the Kit
CSCI1600: Embedded and Real Time Software
CSCI1600: Embedded and Real Time Software
Robotics System Lecture 11_12: DC Motor
Introduction to Arduino
Presentation transcript:

Term 8 Electrical and Computer Engineering Project Course January 2002 Mark Simms Steven Taylor PIC Development, The Easy Way

Overview Basic PIC Circuits Development in C using CCS Typical Tasks (A/D, PWM, timing) How to Layout a Program Debugging Tips The Pumpkin protoboard

Basic PIC Circuits All designs are based around the PIC16F877, a mid- range microcontroller that supports: 8kB of flash program memory Interrupts In-circuit programming Hardware timers Capture/Compare/PWM modules 10-bit A/D conversion (up to 8 channels) Built-in USART for serial communication Lots of Digital I/O

Basic PIC Circuits The most basic circuit consists of: The microcontroller Power and GND (+5V) Oscillator with Caps Typical development circuit adds: RS232 interface (typically with a MAX2.. Chip) LED’s / switches / etc Schematics available on INCA web site (resources at end)

Programming in C Programming the PIC in C offers several advantages: Higher level language – developer is insulated from details of the chip Library support for common tasks (string manipulation, serial communication) We use the CCS compiler ( which don’t suck. All examples will use CCS codehttp://

PIC – Common Tasks with CCS Program Template. Starting point for just about everything #define // Define the type of chip you’re using. // Makes it easier to switch chips #use delay(clock= )// 20Mhz oscillator void main() { /* Initialization Code goes here */ while (TRUE) { /* Program Code goes here */ }

PIC – Common Tasks with CCS Digital I/O Standard I/O vs. Fast I/O Using (standard I/O): // Output a high on PIN_D1, low on PIN_D2 // Wait 50 us and invert output_high(PIN_D1); output_low(PIN_D2); delay_us(50); output_low(PIN_D1); output_high(PIN_D2);

PIC – Common Tasks with CCS Analog Input Initialization: setup_adc_ports(ALL_ANALOG); setup_adc(ADC_CLOCK_DIV_2); Picking a channel: set_adc_channel(0);// Note: must wait between changing // input channels (~ 10us) Inputting Data: unsigned int16 data;// Declare a 16-bit integer data = read_adc();// Read a 10-bit value from the // selected channel

PIC – Common Tasks with CCS Using PWM Initialization: setup_timer_2(T2_DIV_BY_1,249,1);// Setup the PWM period setup_ccp1(CCP_PWM);// Set CCP1 for PWM Setting the Duty Cycle: set_pwm1_duty(500);// See the CCS examples for the formula // for setting the PWM period and duty // cycle

PIC – Tips for Software Design Design the program as a state machine A main() loop, with: A switch() statement that jumps to a function() which represents the actions that occur in that state Each state function() has an output section and a transition section (which can change the current state variable) Interrupts are very useful (for example: interrupt when data received on serial port), but can cause problems. I.e. if you change state during an interrupt (such as an E-stop), return from the interrupt service routine, then change the state variable again (during the transition section) the interrupt change is lost. Design with tuning and debugging in mind Programmer time is more important than machine time – the PIC16F877 is plenty fast

PIC – Tips for Debugging Use a protoboard with RS232 support and lots of print statements. Example: program waits for a switch press reads an analog voltage changes the PWM cycle accordingly

PIC – Tips for Debugging Some_function() { int1 pushed = FALSE, last_pushed = FALSE; int16 analog_value; float volts; pushed = input(PIN_D3); if (pushed && !last_pushed) { puts(“Button Pushed!”); analog_value = read_adc();/* 10-bit analog input value is * between V range */ volts = 5.0 * (analog_value / ); printf(“Button pushed! Analog value is %f volts, PWM to %i\n, volts, analog_value); set_pwm1_duty(analog_value); /* We’ve pre-configured PWM channel 1 – the set_pwm1_duty cycle function accepts a 10-bit number and adjusts the cycle accordingly */ }

PIC – Tips for Debugging Can also use conditionals to print out different types of debugging messages. Say we have a type of message, INFO that we only want to be displayed when testing certain things. We could define a MACRO: #ifdef SHOW_INFO #define INFO(A) puts(A); #else #define INFO(A) /* A */ #endif Then, at an appropriate point in the code: INFO(“Button Pushed”);

PIC – In-Circuit Programming The PIC16F877 has on-board FLASH memory No burner needed to reprogram the PIC No need to remove PIC from circuit Using a bootloader on the PIC, and a bootload utility on the PC the PIC can be reprogrammed in seconds over a serial link. Burn the bootloader code onto the PIC When writing your program in C tell the compiler not to use the top 255 bytes of flash memory Connect the PIC circuit to the PC via a serial link. Run the bootloader code from the PC and download your code to the circuit in seconds This technique is VITAL to preserving sanity

PIC – In-Circuit Programming The PIC16F877 has on-board FLASH memory No burner needed to reprogram the PIC No need to remove PIC from circuit Using a bootloader on the PIC, and a bootload utility on the PC the PIC can be reprogrammed in seconds over a serial link. Burn the bootloader code onto the PIC When writing your program in C tell the compiler not to use the top 255 bytes of flash memory Connect the PIC circuit to the PC via a serial link. Run the bootloader code from the PC and download your code to the circuit in seconds This technique is VITAL to preserving sanity

PIC – Mad2/Pumpkin PIC16F877-based Prototyping Board PIC16F877 microcontroller with PWR/GND connected, 20Mhz oscillator 8 digital I/O points 8 LED’s (switchable to DI/O) 8 Analog Input ports (also usable as DI/O) 2 PWM channels RS232 interface

Sample Application – Analog Sampling PC Application will do the following: Present a graphical front end to the user Have a “sample” button that will send a character to the PIC over the serial port Will read back a number in hex format, reformat into decimal and display on the screen PIC Application will do the following: Poll the serial port If a character is received, sample analog channel 0 (A0), and print the value to the serial port as a hex number, followed by a newline/return (\r\n) Use the value read from the analog input channel as the PWM duty cycle on channel 1

Mplab – Setting up for CCS Project->New (call it main.prj) Development Mode: Editor/16F877 Language Tool Suite: CCS Click on main.hex, Node Properties Click on PCM File->New File->Save As, main.c Add Node, main.c Ready to start building the application

Step 1: Basic Template Basic Template Code is: Include the header file for the appropriate PIC Note: I typically use a custom 16F877.H header file with 10-bit data acquisition turned on Set the clock speed Set the fuses Set up serial communication Reserve memory for the bootloader Main function and debug/status message

Step 2: Initialize the PIC functions Need to initialize (if using): Analog to Digital Conversion Counters and Timers PWM output / capture Interrupts Serial Timer Global Etc I’ve included an LED test to show the card has reset

Step 2: Initialize the PIC functions Need to initialize (if using): Analog to Digital Conversion Counters and Timers PWM output / capture Interrupts Serial Timer Global Etc I’ve included an LED test to show the card has reset

Step 3: State Machine and Interrupts Set up the state machine Define the allowable states with enum’s Define the state variables ALWAYS INITIALIZE EVERY VARIABLE Enter the infinite loop and check for state Set up the interrupt handler Serial #INT_RDA Timer #INT_TIMER1

Step 3: State Machine and Interrupts Three States IDLE – do nothing RECV_DATA Enter: when serial interrupt received Exit: when serial data handled READ_ANALOG Enter: when timer1 overflows (every 100 ms) Exit: when analog data is read and PWM updated

Step 3: State Machine and Interrupts The first state machine is composed with this master “on/off” state machine. STOP: user sends a “stop” command START: user sends a “start” command

Step 4: Handle ANALOG_DATA state Declare variables to store analog input and PWM output In the state handler: Read in the analog voltage (remember it’s a 10-bit number, so we’ll need a 16-bit integer) Convert to PWM rate (divide by 2, ceil to 500) Convert to actual voltage (0-5V) Print on the serial port Return to IDLE state

Step 5: Handle Serial Input Declare variables to store string data from the user Copy in the get_string() function from input.c In the state handler: Disable interrupts Read in a string Check to see if it matches “start” or “stop” Change state if necessary Re-enable interrupts Change state to IDLE

References and Links Presentation, Notes and Code Archive CCS PIC C Compiler CCS PIC C Compiler Manual WorkingTex Web Site (lots of examples!) Bootloader Code (that resides on the PIC) Bootloader Program (that resides on the PC)