DOC PREVIEW
PSU EE 200 - Lab_20_EE200_s14

This preview shows page 1-2-3-4-5-6-45-46-47-48-49-50-51-91-92-93-94-95-96 out of 96 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 96 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 96 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 96 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 96 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 96 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 96 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 96 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 96 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 96 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 96 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 96 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 96 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 96 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 96 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 96 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 96 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 96 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 96 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 96 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 96 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

ColorGrayscaleEE 200 Spring 2014Lab 20.EE 200Design ToolsLaboratory 20Professor Jeffrey SchianoDepartment of Electrical Engineering1EE 200 Spring 2014Lab 20.Laboratory 20 Topics• Rotary Incremental Quadrature Encoders– Terminology, Operation, Applications– Reading using the dsPIC33 and C Programming Language– Realization of an LED dimmer using the dsPIC33– Reading using the myDAQ and the LabVIEW Programming Environment• PICkit-3 debugger functions2EE 200 Spring 2014Lab 20.Rotary Encoders• Advantages– Mechanically reliable– Rotate without end stop• Applications– Volume Control– Linear and Angular Displacement Sensors3EE 200 Spring 2014Lab 20.Rotary Encoder Classifications• Absolute Encoders– Indicates current position of the shaft– Maintains position information when power is removed from the system• Incremental Encoders– Provides cyclical outputs only when the shaft rotates– Reveals incremental changes in position, not absolute position4EE 200 Spring 2014Lab 20.Incremental Encoder Anatomy5BACENCODERA BA Signal B SignalCVsA SignalB SignalCWCCWDOFFON• Known as quadrature encoding because the A and B signals differ in phase by 90EE 200 Spring 2014Lab 20.Resolution and Maximum Count• BOURNS ENCODER PEC11-4215F-N0024 – 24 Counts per Revolution (CPR) • Resolution• dsPIC33 x4 mode– Each count commanded by the encoder produces 4 counts in the dsPIC33 counter• Maximum Count per Revolution (MCPR)• Set dsPIC33 to count in modulo 96: 0,1, 2,… ,95, 0,..6MCPR CPR 4-1 24 4 1 95360 360Resolution 15CPR 24EE 200 Spring 2014Lab 20.Quadrature Encoder Interface (QEI)7EE 200 Spring 2014Lab 20.dsPIC33EP64MC502 pin out8• How do we access QEA and QEB?– Use Peripheral Pin SelectAN0/OA2OUT/RA0AN1/C2IN1+/RA1MCLRPGED3/VREF-/AN2/C2IN1-/SS1/ /CTED2RPI32/RB0PGEC3/VREF+/AN3/OA1OUT/ /CTED1RPI33/RB1PGEC1/AN4/C1IN RPI31+/ 4/RB2PGED1/AN5/C1I RP35N1-/ /RB3VSSOSC1/CLKI/RA2OSC2/CLKO/RA3RP3FLT32/ 6/RB4RP2CVREF20/ /T1CK0/RA4VDDPGED2/ASDA2 RP37//RB5AVDDAVSS/PWM1L/T5CK/RPI47 RB15/PWM1H/T3CK/RPI46 RB14/PWM2L/CTPLS/RPI45 RB13/PWM2H/RPI44 RB12TDI/ /PWM3L/RP43 RB11TDO/ /PWM3H/RP42 RB10VCAPVSSTMS/ASDA1/SD RP4I1/ 1/RB9TCK/CVREF10/ASCL1/SDO1/ /T4CKRP40/RB8SCK1/ /INT0RP39/RB7PGEC2/ASCL2 RP38//RB612345678910111213142827262524232221201918171615dsPIC33EP64MC502-I/SP Pins are up to 5V tolerantEE 200 Spring 2014Lab 20.Selectable Input Sources9EE 200 Spring 2014Lab 20.Register RPINR1410EE 200 Spring 2014Lab 20.Input Pin Selection11QEBQEARPINR14 = 0x2021EE 200 Spring 2014Lab 20.QEI Registers• C Code must include the header file#include <qei32.h>• QEI1CON: QEI Control Register• QEILEC: Less Than or Equal Compare Register• QEIGEC: Greater Than or Equal Compare Register• PSO1CNT: Position Counter Register12EE 200 Spring 2014Lab 20.QEI1CON13• Page 252 of dsPIC33 data sheet• The enable and mode bits are is of interest• Enable bit– QEI1CONbits.QEIEN• Mode bites– QEI1CONbits.PIMODEE 200 Spring 2014Lab 20.Modulo Count Mode (PIMOD = 6)14• Details appear on page 28 of Sec_15_QEI.pdf• Abbreviations– QEI1GEC: Greater Than or Equal Compare Register– QEI1LEC: Less Than or Equal Compare Register– POS1CNT: 32-bit Counter Register• POS1CNT resets to QEI1LEC if POS1CNT > QEI1GEC• POS1CNT resets to QEI1GEC if POS1CNT < QEI1LEC• Count in modulo 96: …, 95, 0, 1, 2,… , 95, 0,.. by setting– QEI1LEC = 0– QEI1GEC = 95EE 200 Spring 2014Lab 20.QEI1LEC: Less Than or Equal Compare Register15• Page 261 of dsPIC33 data sheet• QEI1LEC is a 32-bit number represented by two 16-bit registers• To count in modulo 96 using PIMOD 6, set– QEI1LECL = 0– QEI1LECH = 0EE 200 Spring 2014Lab 20.QEI1GEC: Greater Than or Equal Compare Register16• Page 262 of dsPIC33 data sheet• QEI1GEC is a 32-bit number represented by two 16-bit registers• To count in modulo 96 using PIMOD 6, set– QEI1GECL = 95– QEI1GECH = 0EE 200 Spring 2014Lab 20.POS1CNT: Position Counter Register17• Page 258 of dsPIC33 data sheet• POS1CNT holds the value of the QEI counter• POS1CNT is a 32-bit number represented by two 16-bit registersEE 200 Spring 2014Lab 20.Exercise 1: Overview• Implement a LED dimmer using a mechanical encoder and the dsPIC33 microcontroller• Vary the intensity of the LED using PWM• Set the PWM frequency to 1 kHz• Allow the user to set the duty cycle of the PWM waveform using the rotary incremental encoder• Update the duty cycle every 100 ms• Reset the dsPIC33 watchdog timer so that the LED dimmer program does not automatically restart every few minutes18EE 200 Spring 2014Lab 20.Encoder to PWM Mapping• Program the dsPIC33 QEI so that one revolution of the mechanical encoder varies the counter from 0 to 95• With a clock frequency of 7.37 MHz and PWM frequency of 1 kHz, there are 7370 clock ticks per PWM period• Map an encoder counts of 0 and 95 to 0% and 100% duty cycle, respectively• The PWM register PDC1 must be an integer• Why must we type cast POS1CNTL to a double?• To access the C function floor(), include the header file#include <math.h>19PDC1 = floor( 7370 * (double) POS1CNTL / 95 )EE 200 Spring 2014Lab 20.Watchdog Timer Concept• Details appear in Sec_9_WDT_PSM.pdf• A watchdog timer (WDT) allows an embedded controller to detect and recover from malfunctions• During normal operation, the computer regularly restarts the watchdog timer to prevent it from timing out• If, due to a hardware fault or program error, the computer fails to restart the watchdog, the timer will elapse and generate a timeout signal that resets the computer20EE 200 Spring 2014Lab 20.Watchdog Timer Concept• Restarting a watchdog timer is known as "kicking the dog"21ComputerWatchdog TimerReset Restart TimeoutEE 200 Spring 2014Lab 20.dsPIC33 Watchdog Timer (WDT)• For the default dsPIC33 settings, the WDT times out about every 2 minutes• The WDT restarts if– The dsPIC33 is reset, for example, when it is powered on– The C function ClrWdt () is called• When the WDT times out, the dsPIC33 resets and the code restarts execution– When the LED dimmer programmer restarts, the LED turns off because the default value of POS1CNTL is zero22EE 200 Spring 2014Lab 20.Approaches for Avoiding WDT Timeouts• Preferred Method– Call the C function ClrWdt () to restart the WDT timer• Undesirable Method– Disable the WDT with the following configuration bit settings23EE 200 Spring 2014Lab 20.Exercise 1: LED Dimmer


View Full Document

PSU EE 200 - Lab_20_EE200_s14

Download Lab_20_EE200_s14
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Lab_20_EE200_s14 and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Lab_20_EE200_s14 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?