[Solved] Experiment 10: D.C. Motor Speed Control and Digital Tachometer

$25

File Name: Experiment_10:_D.C._Motor_Speed_Control_and_Digital_Tachometer.zip
File Size: 584.04 KB

SKU: [Solved] Experiment 10: D.C. Motor Speed Control and Digital Tachometer Category: Tag:
5/5 - (1 vote)

ECE 362 Experiment 10 Rev 3/14Bigger Bytes Lab Manual -1- 2014 by D. G. MeyerExperiment 10: D.C. Motor Speed Control and Digital TachometerInstructional Objectives: To illustrate a real-time embedded control application and the use of interrupts To provide experience using various 9S12C32 integrated peripherals, including the pulse width modulation (PWM) unit, the analog-to-digital (ATD) unit, the serial communications interface (SCI), the pulse accumulator (PA) unit, and the serial peripheral interface (SPI)Parts Required: 4N28 optical isolator (included with DK-3 parts kit) TIP 120 or TIP 122 NPN transistor (included with DK-3 parts kit) 2 x 16 LCD and 16-pin single-row header (previous experiment) GAL22V10 programmed as an 8-bitshift register (previous experiment) Breadboard and wirePreparation: Read this document in its entirety Review material on the ATD, PWM, TIM/PA, SCI, and SPI Create your solution in C using Code Warrior1. IntroductionIn lecture you have been introduced to a number of peripheral subsystems included on the 9S12C32 microcontroller. The best way to understand how these independent functional units operate, as well as to gain an appreciation for how they might be utilized in real-world applications, is to illustrate their use in a real-time control experiment. In this lab you will investigate the use of several key HC(S)12 peripherals: the pulse width modulation (PWM) unit,the analog-to-digital converter (ATD), the serial communications interface (SCI), the pulse accumulator (PA) unit (itself part of an extensive timer subsystem), and the serial peripheral interface (SPI). In this real-time application, you will control the speed of a small D.C. motor using a pulse-width modulated signal derived from an analog input control voltage.Your solution should utilize the two pushbuttons (PAD7 and PAD6) on the docking module: the left pushbutton (PAD7) should stop the motor (if it is running), while the right pushbutton (PAD6) should start the motor (if it is stopped). The left LED (connected to port pin PTT1) should be on when the motor is stopped; the right LED (connected to port pin PTT0) should be turned on when the motor is running.The 3-digit (geared down) drive shaft speed (in RPM) as well a percent-of-maximum bar graph will be displayed on an LCD (as shown below). An external shift register is used to interface the LCD to the microcontroller via the SPI module (MOSI, port pin PM4; and SCK, port pin PM5), as in Experiment 8.NOTE: The C code formain and the ISRs mustbe written and debuggedduring your scheduled labperiod (LCD device drivershould be written andtested as part of your prelabpreparation.)ECE 362 Experiment 10 Rev 3/14Bigger Bytes Lab Manual -2- 2014 by D. G. Meyer2. Software OverviewThe objective of this experiment is to control the speed of a small D.C. motor using pulse widthmodulation. The PWM duty cycle will be a function of an input analog D.C. voltage (in therange of 0 to 5 volts). The motor speed will be determined by the number of pulses detected bythe pulse accumulator; its instantaneous value will be estimated based on the number of pulsesaccumulated from the motors 64-slot chopper over a one-second integration period. Anupdated calculation of the (geared-down) drive shaft RPM (in BCD format) will be displayed onthe terminal screen once every second. The motor, to which the chopper is attached, drives agear-head, which then drives the external shaft; the gear ratio is approximately 28:1. Therefore,the three-digit value displayed for the drive shaft speed should be the motor speed divided by 28.The timer module (TIM) will be used to establish the ATD sampling rate as well as thetachometer integration period and display update rate. The real time interrupt (RTI) will be usedto establish the pushbutton sampling rate.The SCI will be used to print the RPM of the motor to the terminal in a buffered, interrupt-drivenfashion. To print characters you should call bco which writes them into the buffer TBUF. Alsoin bco, the transmit interrupt should be enabled so that the buffer can be emptied. The SCItransmit ISR will send out characters when the buffer is not empty. When the transmit ISRencounters an empty buffer, it should turn off the SCI transmit interrupt so that no unintendedcharacters are sent. This methodology allows the processor can do other things in-betweencharacter transmissions.The RTI will be used to sample the pushbuttons on the docking board every 2.048 milliseconds.Data for the LCD display will be shifted out to an external shift register (GAL22V10) and willbe interfaced to the SPI module through Port M (PTM).You should reuse the LCD driver you created for Lab 8 in this experiment for all interfacing. Onthe first line of the LCD, you should display the RPM, updated every second. On the second lineof the LCD, one box character (ASCII $FF) should be displayed for each 10%. Additionally, thepercentage-of-max should be right aligned. Noting the fact that each line of the LCD is 16characters will be useful in doing this.NOTE: Before generating the bar graph, the maximum RPM must be determined.ECE 362 Experiment 10 Rev 3/14Bigger Bytes Lab Manual -3- 2014 by D. G. MeyerLeft LEDRight LEDPT0PT1PAD7PAD65 VLeft PBRight PBPAD0 10K5 V1 62544N28PT21N4001TIP122220 10005 V12 VMOTOR5 VPT7CHOPPER3. Hardware OverviewThe basic interface circuit you will need to construct is illustrated in Figure 1. PWM outputChannel 3 (routed to port pin PTT3 based on MODRR register setting) is used to drive an(optically isolated) NPN switching transistor. The PWM sampling frequency should beapproximately 100 Hz. Attached to the motor shaft is a 64-slot chopper disk that passesthrough an optical detector. Signal conditioning circuitry included with the motor assemblyproduces a pulse each time a hole in the disk passes through the aperture of the optical detector.The signal produced by the optical detector is fed to the pulse accumulator input PTT7. Finally,a potentiometer is used to provide a reference D.C. voltage (in the range of 0 to 5 volts) for ATDinput Channel 0 (PAD0). This value, when digitized, is used to control the PWM duty cycle.Figure 1. Wiring diagram for potentiometer and motor interface.Microcontroller docking boardMotor assemblyPT5NOTE: Motor assemblies will only be available for checkout during times that a coursestaff member is on duty. Debug your software using an oscilloscope (to view PWM outputgenerated on PT3) and a function generator (connected to PT7) to simulate the chopper.PT3ECE 362 Experiment 10 Rev 3/14Bigger Bytes Lab Manual -4- 2014 by D. G. MeyerYou will interface to the LCD in the same way that you did in Experiment 8 (except for the PortT connections) The description of the LCD interface is reproduced below for your convenience.An external 8-bit shift register (GAL22V10) will be used to interface LCD to the microcontrollervia the SPI module (MOSI, port pin PTM4; and SCK, port pin PTM5). The LCD will beinterfaced as described to the microcontroller module as described in the table below:LCDPin # LCD Pin Description Connected toMicrocontroller1 Vss (ground) Vss (ground)2 Vcc (+5V) Vcc (+5V)3 VEE (contrast adjust) Vss (ground)4 R/S (register select) PTT45 R/W (LCD read/write) PTT56 LCD Clock PTT67 DB[0] (LSb) Q[0]8 DB[1] Q[1]9 DB[2] Q[2]10 DB[3] Q[3]11 DB[4] Q[4]12 DB[5] Q[5]13 DB[6] Q[6]14 DB[7] (MSb) Q[7]15 Not connected16 Not connectedSome of the LCD pins require a bit more explanation:Mnemonic Name DescriptionRS RegisterselectThis pin is logic 0 when sending an instructioncommand over the data bus and logic 1 whensending a character.R/W Read/write This pin is logic 0 when writing to the LCD,logic 1 when reading from it. For this lab, wewill only write to the LCD.LCDCLK LCD clock This pin latches in the data on the data[7:0]bus on the falling edge. Therefore, this lineshould idle as logic 1.Step 1. InterfacingInterface the LCD and LEDs to your microcontroller kit as described in the Hardware Overviewsection (note that different Port T pins are used than in previous experiments see table).This will require programming your GAL22V10 to function as an 8-bit shift register, asdescribed in problem 5 of the Module 2 homework. Complete all the interface wiring on yourbreadboard as part of your pre-lab preparation.NOTE: Port T connections are different than those usedin previous experiments.ECE 362 Experiment 10 Rev 3/14Bigger Bytes Lab Manual -5- 2014 by D. G. MeyerStep 2. SoftwarePrior to your scheduled lab period, copy the LCD device driver routines you wrote for Lab 8 andtest them with the interface circuitry completed for Step 1. Complete the remainder of the Cskeleton file provided on the course website during your scheduled lab period. Note that thefinished product should work in a turn key fashion, i.e., your application code should bestored in flash memory and begin running upon power-on or reset. Demonstrate the completedmotor speed control system to your lab T.A.Step 3. SubmissionSubmit your .C solution file on-line after demonstrating it to your lab T.A. (but before leavinglab). Be sure identifying information (i.e., name, class number, and lab division) is included inthe files you submit credit will not be awarded if identifying information is omitted.Bonus CreditAdd a musical (frequency modulation) mode to the motor speed control function. Here, use theleft pushbutton to toggle motor run/stop, and the right button to toggle between potentiometer(voltage) speed control (stock solution) and a frequency control mode. Indicate the mode ofoperation in column 16 of the first line of the LCD display: V for voltage, F for frequency.For the frequency control mode, use the function generator at your lab station as a musicaltone: connect the SYNC output of the function generator (CMOS compatible square wave) toPTT2 (timer channel 2), configured for input capture mode. Write a function that converts inputcapture timestamps to frequency, and convert the frequency to a proportional (8-bit) PWM dutycycle: the lower the frequency, the slower the motor should run, and the higher the frequency,the faster the motor will run. So, for example, if you wish to allow a frequency control range of1000 Hz, you will want to divide the frequency detected by four to produce a PWM duty rangeof 250 (assuming a PWM period of 255).While beyond the scope of this experiment (but well within the realm of an exciting potentialMini-Project), a microphone/preamp could be added along with some input conditioningcircuitry to create a hummer a device that converts musical tones to different motor speeds.The speed of a color wheel (or disco ball?) could be modulated by music.As they tend to screech on most infomercials, Amazing!ECE 362 Experiment 10 Rev 3/14Bigger Bytes Lab Manual -6- 2014 by D. G. MeyerThought QuestionsAnswer the following thought questions in the space provided below:(a) Why is an optical isolator used to interface the 9S12C32 PWM output pin with the NPNswitching transistor that controls the motor? Could an NPN switching transistor like a TIP120 be interfaced to a 9S12C32 port pin without using an optical isolator?(b) What are the advantages of using PWM to control the speed of a D.C. motor? (ComparePWM to any alternatives you think might be feasible.)(c) Why not just connect the motor directly to the potentiometer to control its speed? Whatwould happen? (DO NOT TRY THIS!)(d) What would happen if a higher PWM sampling frequency were utilized? Is there a practicallimit to the sampling frequency that can/should be utilized? (This one you CAN safely try!!)(e) Given a 64-slot chopper and a 1.0 second integration period, what is the RESOLUTION ofthe tachometer (i.e., the difference in RPM estimate caused by pulse count difference of oneover the integration period)?

Reviews

There are no reviews yet.

Only logged in customers who have purchased this product may leave a review.

Shopping Cart
[Solved] Experiment 10: D.C. Motor Speed Control and Digital Tachometer
$25