Experiment 7 EE583 7-1 Fall 2004 J E Lumpp Experiment 7: Digital Voltmeter Objectives: To gain experience with HC12 interrupts. To gain experience with the HC12 ATD subsystem. To gain experience with the HC12 TIM subsystem. Reading: CPU12 Reference Manual. D-Bug12 source code. M68EVB912B32 Evaluation Board Users Manual Course Text, Chapters 1-7 Introduction: Interrupt processing is one of the most useful features in a microcontroller. In this lab we will program the Real-Time Interrupt subsystem (RTI) in the HC12 to provide periodic real-time interrupts and also use the TIM to generate interrupts in response to external signals. We will use these interrupts to determine when to sample a channel in the analog to digital converter system (ATD) in the HC12. Finally, we will update the display on the PC to show the voltage currently applied to the analog input, thereby implementing a rudimentary real-time voltmeter with your M68EVB912B32 Evaluation Board. Experiment: Part 1: You will write and demonstrate two programs for this lab. As in previous labs, you will fill in the missing pieces of the program shown below (a copy is also available on the course web page). To measure the passage of one second, you will set the RTI subsystem to interrupt every 8.192 ms and then have an interrupt service routing (ISR) manage a counter to determine when enough 8.192 ms interrupts have been triggered so that you know one second has passed. When a second has passed, the ISR will then call functions to: read the ATD; convert the raw value to a voltage; and display the voltage on the PC screen (via the SCI). (Note: To test your code, you should connect a potentiometer between ground and +5V and then us the pot to provide various voltages to the ATD.) Demonstrate the operation of this program to the instructor. ;********************************************************************** * ; Lab Digital Volt Meter ;********************************************************************** ; ;********************************************************************** ; ; In this lab you will implement a simple volt meter using the ATD ; system in the HC12 as well as the HC12 interrupt system. ; The program will sample an analog input channel once each second, ; convert the value into a 3-digit decimal number (N.NN), and update Experiment 7 EE583 7-2 Fall 2004 J E Lumpp ; the value displayed on the PC screen. ; ;********************************************************************** ; ; some ASCII chars ; ESC equ 1bh RET equ 0dh LF equ 0ah CR equ 0dh BACKUP equ 08h ; ; HC12 register declarations/usage ; ; Real Time Interrupt ; rtictl equ 0014h ; RTI control register rtiflg equ 0015h ; RTI flag register ; ; Analog-to-Digital Converter ; atdctl2 equ 0062h ; ATD control register atdctl4 equ 0064h ; ATD control register atdctl5 equ 0065h ; ATD control register atdstat equ 0067h ; ATD status register (lower byte -- CCF flags) adr7h equ 007Eh ; ATD Channel 7 result register ; ;********************************************************************** ; ; Main program for volt meter ; ; After performing the initializations, main outputs ; the string "V = " to the terminal screen and then waits for ; an ESC character to be entered (to terminate the application). ; org 0800h main bra rti_isr main_cont ; recall we are using this trick to nail down ;********************************************************************** ; ; RTI interrupt service routine ; ; This routine keeps track of when "one second's worth" of ; RTI interrupts has passed and calls the SAMPLE routine ; followed by the VDISP routine ; ; Declarations ; rticlr equ 80h ; real time interrupt flag bit mask rticnt rtifin rti_isr fcb equ 00h 122t ; running interrupt count ; integration period count ; be sure to enter the address for this function into ;the jump vector in byte addressable ROM Experiment 7 EE583 7-3 Fall 2004 J E Lumpp ; < place your code for the RTI interrupt service routine here > rti ;********************************************************************** ; Main continued ;********************************************************************** main_cont sei jsr cli ; disable interrupts until initialization complete ar_ini ; initialize ATD and RTI subsystems ; enable interrupts ; < place remainder of main program code below > ;********************************************************************** ; ; ATD and RTI initialization routine ; ; Initialize the ATD to sample a D.C. input voltage (range: 0 to 5V) ; on Channel 7 (to test this hood ch7 to a potentiometer between 5V ; and ground). The ATD should be operated in a program-driven (i.e., ; non-interrupt driven), normal flag clear mode using nominal sample ; time/clock prescaler values. ; ; Note: Vrh (the ATD reference high voltage) is connected to 5 VDC and ; Vrl (the reference low voltage) is connected to GND on the HC12 ; evaluation board. ; ; Also, be sure to initialize the RTI to generate an 8.192 ms interrupt ; rate ; init_rti_atd ; < place your ATD and RTI initialization code here > rts ;********************************************************************** ; ; ATD sampling routine ; ; This routine will initiate an ATD conversion on input Channel 7 ; (by writing to register ATDCTL5), wait for the conversion to ; complete (by monitoring the appropriate CCF flag in register ; ATDSTAT), read the ATD result register once the conversion ; completes, and return the converted analog sample in the A ; register. ; Experiment 7 EE583 7-4 Fall 2004 J E Lumpp sample ; < place your code for the ATD sampling routine here > rts ;********************************************************************** ; ; STEP 5: Voltage display routine ; ; This routine converts the sample taken by the ATD (range: 0-255), ; passed in the A register, into a 3-digit decimal number (N.NN), ; ranging from 0.00 to (approx.) 5.00 volts. The value displayed ; should be refreshed "in place" on the terminal screen. ; vdisp ; < place your code for the voltage display routine here > rts include ; "dvm_io.asm" include ; if you run out of space put these ; EEPROM "dvm_vec.asm" ; Be sure to set the vector ; for the RTI isr in the EEPROM end ;********************************************************************** Experiment 7 EE583 7-5 Fall 2004 J E Lumpp Part 2: Next, we will modify the above program to take samples in response to external signals (those from off the HC12 chip) instead of from a signal from the RTI. For example, we may have another piece of hardware in an embedded system that will generate a TTL signal to let the processor know when to take an ATD sample. The HC12 includes a powerful “Timer and Pulse Accumulator” subsystem (TIM) that time and count many types of signals input to the HC12. We will use one of the capture inputs to recognize an edge and generate an interrupt. The ISR for this interrupt will simply call the sample and output functions from the previous program (no need to count the interrupts here). (Note: With a periodic signal from a function generator set to pulse at one second, we could achieve the exact same functionality as the previous example.) Here is a starting point for functions to initialize the TIM and to respond to the interrupts: TIMInit movb movb movb movb rts ___,TSCR ___,TCTL4 ___,TMSK1 ___,TFLG1 TIMIsr ; ; ; ; turn on the TIM capture rising edges enable CH1 interrupt clear CH1 flag ; clear CH1 flag ; call appropriate functions rti When you have this version of the program working, demonstrate it for the instructor. Instructor Signature (Part 1): Instructor Signature (Part 2):