140 likes | 326 Views
Lab 4 – Servo Motor. Start Date: Week #6 Due date: Week #8. Overview of the timer system. See black book p. 66 TCNT Free running counter Prescaler sets relationship to ECLK (TMSK2) Main part of the timer subsystem Can be stopped while in wait or background debug mode (TSCR).
E N D
Lab 4 – Servo Motor Start Date: Week #6 Due date: Week #8
Overview of the timer system • See black book p. 66 • TCNT • Free running counter • Prescaler sets relationship to ECLK (TMSK2) • Main part of the timer subsystem • Can be stopped while in wait or background debug mode (TSCR)
Input capture/output compare • TIC / TOC • Set using TIOS register • Input capture • When an event is detected on pin x, the value of TCNT is latched into the 16-bit register TCx • The input event (rising edge, falling edge, both, none) is set in a register (TCTL3 and TCTL4) • Flag is set in TFLG1 • Interrupt is generated if set in TMSK1
Input capture/output compare • Output Compare • Successful output compare when the value in TCNT equals the value in TCx • Flag is set in TMSK1 • Output pin is changed according to action set in TCTL1 and TCTL2 • None, set, clear, toggle • Interrupt generated if set in TMSK1
Overflow Interrupt • The system also has the ability to flag / generate an interrupt on TCNT overflow • Interrupt set from TMSK2 • Flag in TFLG2
Registers • TIOS • Input capture / output compare • TCNT • Counter • TSCR • Enable, fast clear, wait and background mode • TMSK1 • interrupts
Registers • TMSK2 • Prescalers • TFLG1 • Flags for the interrupts • Write a 1 to clear • TCx • This is where you write the values you are using for OC
Servo Motor control • Period of ~21ms • Pulse width determines angle (from ~0.9 to ~2.1ms) • You will need to calibrate it
LCD • There is test code on the web that you can use to test the LCD setup before you try to use it in your program • You may utilize the code to write your own program, but you need to make sure that you understand what the code is doing and why
Interrupts on the HC12 • You will need to use interrupts if your main program is waiting for user input • D-Bug12 re-maps the interrupt vector table • Either use the D-Bug12 subroutine to set the vector, or set it yourself using the remapped locations (last slide) • More detailed information in the appendix
Hints • The scope can be very helpful to check your output • If you don’t know how to use it, please ask • Check the LCD setup using the test code before you try to write to it
Academic Misconduct • Reports and demos are submitted as a group, but it is a SINGLE group effort • You may talk with other groups but sharing code or reports is NOT ALLOWED • Copying code/reports from previous years is also NOT ALLOWED • If we find copying we are REQUIRED to report it