This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Setting up an ISR for a PIT timer (homework help)

Hello,

I'm in a course in which we are supposed to learn to program an (ARM) microcontroller. This is my sixth homework task. I'm fairly new to assembler-programming, but so far I've managed to work out all tasks with the help of the internet, different course material, the reference manual of the microcontroller etc. But I'm overwhelmed with my current task, so I hope somebody can help me here. I really need a good solution, but I also really want to understand what I'm doing. I will try to note the steps that I'm trying to take and organizie and formulate my ideas. Maybe that will already help me a bit.

Task: I'm supposed to set up a PIT timer that creates an interrupt every second. An Interrupt Service Routine should catch the interrupt by setting another flag (I'll call it "sec") that tells the main program when a second has elapsed. The main program is supposed to respond to the set flag by doing something (I've already finished the part of "doing something" ;) ) .

So this is what I need to do:

(1) setting up the PIT in the main program

(2) write the ISR

(3) insert the interrupt vector in the interrupt vector table

(4) make the program notice when "sec" is set and then "do something"

I need help with all of those. I've tried to start with (1) and (2). I got the commands from the reference manual, but none of them is working. Is anything important missing? PIT_MCR etc. only gives me errors.

How do I do (3)?

And how do I generate my own flag? (So far I've created a byte-variable for that, but I guess there's a better solution?!)

.include "k60n512.inc"

	.text
	.align	2
	.global	main

ISR:		//Interrupt Service Routine
	push {lr}
		ldr r3, =sekunde		
		mov r0, #1
		strb r0, [r3, #0]
		
		PIT_TFLG1 = 1	//reset pit-flag
	pop {pc}


main:
// Initialisiere PIT und Timer 1
	PIT_MCR = 0x00
	
	PIT_LDVAL1 = 0x02FAF07F // set Timer-length to 50.000.000 clcles (1 second)
	PIT_TCTRL1 = TIE 		// allow Timer Interrupts
	PIT_TCTRL1 |= TEN 		// start Timer

lend:
	b lend



.data


sekunde: .byte 0x0

  • there is a timer calculator. download it and insert parameters. it will generate a code for timer values with interrupt in sec. after that write your interrupt service routine(ISR). then insert interrupt vector table.

    the image of timer calculator