ETEC 421 - Digital Controls PIC Lab 10 Pulse Width Modulation



Similar documents
Real-Time Clock. * Real-Time Computing, edited by Duncan A. Mellichamp, Van Nostrand Reinhold

Section 14. Compare/Capture/PWM (CCP)

Hi Hsiao-Lung Chan Dept Electrical Engineering Chang Gung University, Taiwan

1. Learn about the 555 timer integrated circuit and applications 2. Apply the 555 timer to build an infrared (IR) transmitter and receiver

CHAPTER 11: Flip Flops

Display Board Pulse Width Modulation (PWM) Power/Speed Controller Module

Accurate Measurement of the Mains Electricity Frequency

Microcontroller Code Example Explanation and Words of Wisdom For Senior Design

A simple RF/Microwave frequency counter

AVR Timer/Counter. Prof Prabhat Ranjan DA-IICT, Gandhinagar

Lab Experiment 1: The LPC 2148 Education Board

Application Note AN-1187

AUTOMATIC NIGHT LAMP WITH MORNING ALARM USING MICROPROCESSOR

Flexible Active Shutter Control Interface using the MC1323x

3-Digit Counter and Display

Experiment 8 : Pulse Width Modulation

Table 1 Comparison of DC, Uni-Polar and Bi-polar Stepper Motors

Arduino Motor Shield (L298) Manual

EXPERIMENT 8. Flip-Flops and Sequential Circuits

Pulse Width Modulation (PWM) LED Dimmer Circuit. Using a 555 Timer Chip

AVR131: Using the AVR s High-speed PWM. Introduction. Features. AVR 8-bit Microcontrollers APPLICATION NOTE

SPI. Overview and Use of the PICmicro Serial Peripheral Interface. Getting Started: SPI

Timer A (0 and 1) and PWM EE3376

Features. Applications

Using Arduino Microcontrollers to Sense DC Motor Speed and Position

Pmod peripheral modules are powered by the host via the interface s power and ground pins.

Small Hardware Development and Prototyping Board for the SX28

0832 Dot Matrix Green Display Information Board User s Guide

AMZ-FX Guitar effects. (2007) Mosfet Body Diodes. Accessed 22/12/09.

Hello and welcome to this training module for the STM32L4 Liquid Crystal Display (LCD) controller. This controller can be used in a wide range of

Data Acquisition Module with I2C interface «I2C-FLEXEL» User s Guide

Low Cost Pure Sine Wave Solar Inverter Circuit

AVR Butterfly Training. Atmel Norway, AVR Applications Group

8-bit Microcontroller. Application Note. AVR415: RC5 IR Remote Control Transmitter. Features. Introduction. Figure 1.

Pulse Width Modulation

HT46R14A Single Phase AC Induction Motor Frequency Converter Application

Microtronics technologies Mobile:

Table 1 below is a complete list of MPTH commands with descriptions. Table 1 : MPTH Commands. Command Name Code Setting Value Description

The Design of DSP controller based DC Servo Motor Control System

Crazy Alarm Clock L A K S H M I M E Y Y A P P A N J A M E S K A Y E W I L L I A M D I E H L C O N G C H E N

Selecting and Implementing H-Bridges in DC Motor Control. Daniel Phan A

Data Sheet. Adaptive Design ltd. Arduino Dual L6470 Stepper Motor Shield V th November L6470 Stepper Motor Shield

A Practical Guide to Free Energy Devices

Microcontroller Based Low Cost Portable PC Mouse and Keyboard Tester

Global Motion Technology Inc Web THCSA200. Capacitive sensor plasma & Oxy-fuel Torch Height Control

8051 MICROCONTROLLER COURSE

Quick Start Guide for High Voltage Solar Inverter DC-AC Board EVM. Version 1.3

Section 9. I/O Ports

PWM IN AVR. Developed by: Krishna Nand Gupta Prashant Agrawal Mayur Agarwal

How To Program A Microcontroller Board (Eb064) With A Psp Microcontroller (B064-74) With An Ios 2.5V (Power) And A Ppt (Power Control) (Power Supply) (

AN3252 Application note

A-145 LFO. 1. Introduction. doepfer System A LFO A-145

Servo Motors (SensorDAQ only) Evaluation copy. Vernier Digital Control Unit (DCU) LabQuest or LabPro power supply

Pulse Width Modulation Applications

Theory of Operation. Figure 1 illustrates a fan motor circuit used in an automobile application. The TPIC kω AREF.

Experiment # 9. Clock generator circuits & Counters. Eng. Waleed Y. Mousa

Micro-Step Driving for Stepper Motors: A Case Study

25. AM radio receiver

STEPPER MOTOR SPEED AND POSITION CONTROL

APPLICATION NOTES: Dimming InGaN LED

An Introduction to MPLAB Integrated Development Environment

Servo Info and Centering

A Lesson on Digital Clocks, One Shots and Counters

How To Use A Watt Saver On A Microcontroller (Watt Saver) On A Cell Phone Or Mp3 Player

DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING Question Bank Subject Name: EC Microprocessor & Microcontroller Year/Sem : II/IV

c0003 A Simple PIC Application CHAPTER 3

Hello, and welcome to this presentation of the STM32L4 reset and clock controller.

1/22/16. You Tube Video. Definitions. Duty Cycle: on-time per period (specified in per cent)

MODULE BOUSSOLE ÉLECTRONIQUE CMPS03 Référence :

Constructing a precision SWR meter and antenna analyzer. Mike Brink HNF, Design Technologist.

LINEAR INTEGRATED-CIRCUIT FUNCTION GENERATOR

Lab 4: Pulse Width Modulation and Introduction to Simple Virtual Worlds (PWM) (PWM)

ADS9850 Signal Generator Module

Designing an Induction Cooker Using the S08PT Family

RC Circuits and The Oscilloscope Physics Lab X

Fundamentals of Signature Analysis

Develop a Dallas 1-Wire Master Using the Z8F1680 Series of MCUs

Massachusetts Institute of Technology

Transistor Characteristics and Single Transistor Amplifier Sept. 8, 1997

FEATURES DESCRIPTION. PT6321 Fluorescent Display Tube Controller Driver

HANDLING SUSPEND MODE ON A USB MOUSE

AN111: Using 8-Bit MCUs in 5 Volt Systems

A Lesson on Digital Clocks, One Shots and Counters

HT1632C 32 8 &24 16 LED Driver

Controller for AD9850 DDS Modules Andy Talbot G4JNT

Interfacing Of PIC 18F252 Microcontroller with Real Time Clock via I2C Protocol

Work with Arduino Hardware

AN108 IMPLEMENTING A REALTIME CLOCK. Relevant Devices. Introduction. Key Points. Overview

Interfacing To Alphanumeric Displays

How To Make A Pure Sine Wave Inverter

Information Board User s Guide

Programming PIC Microcontrollers in PicBasic Pro Lesson 1 Cornerstone Electronics Technology and Robotics II

NJU6061. Full Color LED Controller Driver with PWM Control GENERAL DESCRIPTION PACKAGE OUTLINE FEATURES

A Digital Timer Implementation using 7 Segment Displays

Section 19. Voltage Reference

Four/Five Axis TB6560 CNC Driver Users Manual

ARM Thumb Microcontrollers. Application Note. Software ISO 7816 I/O Line Implementation. Features. Introduction

Lab 11 Digital Dice. Figure Digital Dice Circuit on NI ELVIS II Workstation

Transcription:

ETEC 421 - Digital Controls PIC Lab 10 Pulse Width Modulation Program Definition: Write a program to control the speed of a dc motor using pulse width modulation. Discussion: The speed of a dc motor is proportional to the applied voltage, the current, and the torque requirements of the load. Torque is directly proportional to speed. The trick with speed control is to achieve a reasonable torque as the motor speed is varied. This can be done by supplying full voltage pulses to the motor while varying the duty cycle. Pulse width modulation is accomplished by establishing a constant period for a square wave and allowing the pulse width during that period to vary in length as a percentage of the period. The diagram below shows pulse width modulation for three different percentages of the period. We will construct a program for the PIC and an h-bridge driver circuit to demonstrate pulse width modulation techniques using a small dc motor. Two different methods of generating the pulse will be used. Procedure: Figure 1 Pulse Width Modulation Assemble the H-Bridge motor driver circuit as shown in Fig. 2 on a protoboard.

Figure 2 H-Bridge Schematic Now we will write two programs for the PIC to generate the pulses and direction signal to drive the dc motor utilizing the above circuit. In both programs, you will use the RC2 output for the pulse signal to the h-bridge, and an output pin of your choice for the direction. Program 1: Using the PIC Timer Interrupts with CCP1 in Compare Mode We will generate a pulse train that can be changed by pushing one of 3 buttons on the LabX1 board. The program starts out with the pulse width set at 50%. Select a row of buttons on the LabX1 board to act as signals to change the pulse width. Use the left-most button to decrease the speed by one count, the next button to reset the speed to 50%, the next button to increase the speed by one count, and the right-most button to change directions. The process of generating the pulse train is as follows: CCP1 is set to compare mode so that it will generate a software interrupt (sets CCP1IF to 1) when the value stored in its data registers (CCPR1H and CCPR1L) match the count of a free-running timer Timer1. Timer 1 is allowed to count until it rolls-over (65536) at which time it generates an interrupt (sets TMR1IF to 1). An interrupt routine traps each interrupt as it happens. When TMR1IF is trapped, set RC2 to 1 and clear the flag. When CCP1IF is trapped, Set RC2 to 0 and clear the flag. The length of the period (1 / frequency) is determined by setting bits 5 and 4 in the T1CON register. The pulse width is varied by changing the values in CCPR1H and CCPR1L. Note that 50% duty cycle is accomplished by setting CCPR1H to 128 with CCPR1L = 0.

This program will use the interrupts generated by Timer1 and CCP1 to set or clear pin 17 of the PIC (RC2) to give the output pulse train. See Table 8-4 below. Here are some tips to get you going: 1. Be sure to enable all of the appropriate interrupts (GIE, the peripherals, the port B interrupt on change feature, port B0 interrupt, timer 1, and the capture and compare module CCP1). 2. Enable the pull-up resistors for port B, set RC2 as an output, and set the TRISA and TRISB registers to utilize the pushbuttons on the LabX1 board. This is the same as in a previous lab. 3. Set up the LCD to display the value stored in CCPR1H so that we can see how long the pulse is high. 4. Re-use some of the code from a previous lab to utilize the interrupt routine to detect when one of the buttons is pushed and take the appropriate action based upon which one is pushed. 5. In the main program, establish a while() loop that runs forever and displays the value of CCPR1H. 6. The interrupt routine does three things: a) Test for TMR1IF, b) Tests for CCP1IF, and c) Tests for RBIF. 7. Refer to the diagram below to get an idea of how the waveform looks and when the interrupts are generated:

Program 2: Using the PIC PWM Feature The PIC has a built-in Pulse Width Modulation feature that uses Timer2 with CCP1 set in PWM mode which makes it very easy and efficient to generate the pulse train. You will set up the new program as above (re-use most of its code) to generate a variable width pulse on the same pin (RC2). However, you will need to use the registers and timer as shown in the table below. The process of generating a PWM signal is outlined in the PIC Data Sheet (Section 8.3) but listed below are some salient points from the set-up procedure Section 8.8.3: 1. Set the PWM period by writing to the PR2 register (a good initial value is 255 its max value) 2. Set the PWM duty cycle by writing to the CCPR1L register (a good initial value is 128 which will set it to a 50% duty cycle) Also you may want to set CCP1CON bits 5 and 4 to 1 s since these are the two least significant bits of the duty cycle. (Note that the duty cycle is a 10 bit number) 3. Make CCP1 and output by clearing the TRISC register bit 2. 4. Set the TMR2 prescale value and enable Timer2 by writing to T2CON. 5. Configure the CCP1 module for PWM operation. 6. Be sure to enable Timer2, set its prescale value to 1:1, and make it listen to the internal oscillator. 7. This time, the interrupt routine is used only to trap the button pushes since we do not need to be involved with the timer or compare module interrupts. 8. Display the value of CCPR1L on the LCD.