Solutions to Homework 6 | Microcontroller Applications | ECE 4510, Assignments of Microcomputers

Material Type: Assignment; Professor: Grantner; Class: Microcontroller Applications; Subject: Electrical & Computer Engineer; University: Western Michigan University; Term: Fall 2008;

Typology: Assignments

Pre 2010

Uploaded on 07/22/2009

koofers-user-lwe
koofers-user-lwe 🇺🇸

10 documents

1 / 2

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Solutions to Homework Assignment #6
Calculations for timing requirements
The Timer Overflow is used to monitor the timing requirements.
One period time for the timer to overflow = 41.2ns * 65536 = 2.73ms
For 8ms delay 8/2.73 = 3 TOF interrupts
Algorithm /code
#include <mc9s12dp256.h>
#pragma abs_address:0x1000
unsigned long int result = 0;
#pragma end_abs_address
int counter = 0;void main (void) {
ATD1CTL2 = 0x82;//enable interrupt on series complete
ATD1CTL3 = 0x40;//Set conversion sequence length to 8
ATD1CTL4 = 0x05;//Set 10-bit resolution
ATD1CTL5 = 0x83;//Right-justified, unsigned results, conversion
TFLG2 = 0x80;//clear TOF flag by writing 1
TSCR1 = 0x80;//enable timer
TSCR2 = 0x80;//enable timer over flow interrupt
asm("cli"); //Enable interrupts.
while(1) { if (counter == 3) {
while (ATD1STAT1 != 0xFF); //Wait for all CCF flags to go high
// indicating a complete sequence.
//Perform average of 8 converted values and place in result.
result = (ATD1DR0 + ATD1DR1 + ATD1DR2 + ATD1DR3
+ ATD1DR4 + ATD1DR5 + ATD1DR6 + ATD1DR7)/8;
ATD1CTL5 = 0x83;//Clear ATD flags (SCF, CCFs)
counter = 0;//Reset the overflow counter
}
}
}
#pragma interrupt_handler TOF_ISR
void TOF_ISR(void) {
TFLG2 = 0x80;//Clear TOF flag
counter = counter+1;//Increment TOF counter
}
#pragma abs_address:0x3E5E
pf2

Partial preview of the text

Download Solutions to Homework 6 | Microcontroller Applications | ECE 4510 and more Assignments Microcomputers in PDF only on Docsity!

Solutions to Homework Assignment

Calculations for timing requirements

The Timer Overflow is used to monitor the timing requirements.

One period time for the timer to overflow = 41.2ns * 65536 = 2.73ms

For 8ms delay → 8/2.73 = 3 TOF interrupts

Algorithm /code

#include <mc9s12dp256.h>

#pragma abs_address:0x unsigned long int result = 0; #pragma end_abs_address

int counter = 0; void main (void) {

ATD1CTL2 = 0x82; //enable interrupt on series complete ATD1CTL3 = 0x40; //Set conversion sequence length to 8 ATD1CTL4 = 0x05; //Set 10-bit resolution ATD1CTL5 = 0x83; //Right-justified, unsigned results, conversion

TFLG2 = 0x80; //clear TOF flag by writing 1 TSCR1 = 0x80; //enable timer TSCR2 = 0x80; //enable timer over flow interrupt

asm("cli"); //Enable interrupts.

while(1) { if (counter == 3) { while (ATD1STAT1 != 0xFF); //Wait for all CCF flags to go high // indicating a complete sequence.

//Perform average of 8 converted values and place in result. result = (ATD1DR0 + ATD1DR1 + ATD1DR2 + ATD1DR

  • ATD1DR4 + ATD1DR5 + ATD1DR6 + ATD1DR7)/8;

ATD1CTL5 = 0x83; //Clear ATD flags (SCF, CCFs) counter = 0; //Reset the overflow counter } } }

#pragma interrupt_handler TOF_ISR void TOF_ISR(void) { TFLG2 = 0x80; //Clear TOF flag counter = counter+1; //Increment TOF counter }

#pragma abs_address:0x3E5E

void (* interrupt_vector[]) (void) = {TOF_ISR}; #pragma end_abs_address