Real Time Interrupts

Started by coolguyclay March 2, 2004
Hello. My group (school project) is using the ICC12 C compiler to
run our controller. We are having a hard time getting the interrupts
to work. Right now out movement is based on loops, but for more
accurate movement and to incorporate sensor control to our robot, we
think we need interrupts. We'd appreciate any suggestions, code
snippets, or advice you can give. Thanks!



In a message dated 3/2/04 8:33:47 PM Eastern Standard Time,
writes:
Hello. My group (school project) is using the ICC12 C compiler to
run our controller. We are having a hard time getting the interrupts
to work. Right now out movement is based on loops, but for more
accurate movement and to incorporate sensor control to our robot, we
think we need interrupts. We'd appreciate any suggestions, code
snippets, or advice you can give. Thanks!
==================================================
You have any kind of spec or hi level design you are programming to? What
kind of hc12 board are you using? Tech Arts? If you have good comments in the
prog or a paragraph description of how to run the motors, read the sensors, etc,
we can look at what you have and make suggestions... go ahead and post what
you have so far



Thanks for replying so quickly!

We are using a hcs12dp256 Motorolla Microcontroller. The purpose of
our robot is to navigate a game board (the game board of the Trinity
Firefighting robot competition) and retrieve an object. We want our
servo motors to run for a specific time and stop either because the
time came up or because an IR sensors says a wall is in the way or
something.

/* 520 */ void setISR ( void ( * func_ptr ) ( void ) )
/* 521 */ {
/* 522 */ asm("LDD %func_ptr") ;
/* 524 */ asm("PSHD") ;
/* 525 */ asm("CLRA") ;
/* 526 */ asm("LDAB # 56") ;
/* 527 */ asm("LDX 0xEEA4") ;
/* 528 */ asm("JSR 0 , X") ;
/* 529 */ asm("PULD") ;
/* 530 */
/* 531 */ }

RTICTL = 0x0014;
CRGFLG = 0x80;

DBug12FNP->SetUserVector(56, (char *)Timer);
printf("Loc: %x -- %p\n", Timer, _ADDR(0x3e70)); #pragma interrupt_handler Timer
void Timer()
{
count++;
CRGFLG = 0x80;
asm("rti");
}

OK, there is some of the code we are trying to use. The first chunk
was a test with some assembly we saw that supposedly got the
interrupts working (or something that we could test). ICC12 has the
feature of writing assuembly right into the program, which is cool,
but it didn't really work for us.

The second section of code is where we try to set the timer and real
time interrupt (rti) with allocated vectors and such. It actually
spits out the output shown and is what we set it up to be, but then
nothing works in the last section of code.

We wanted the loop to just use our interrupt handle to stop the
program (interrupt it), increase the number, and move on, but when
we run it, the output just stays at zero.

Thanks again for your help. If seeing the interrupt_handle function
would be helpful, I can post that guy too!

Later.

Clay



A number of things look strange to me.

Read the ICC12 help on the calling sequence stack frame. When you invoke a
C function with a single parameter, that param,eter is already in the D
register. your LDD %func_ptr is redundant. besides, the name reference for
the asm equivalent of a C name is the name preceeded by an underscore. i.e.
_func_ptr .

I will assume that you properly used the debug12 function to install the
interrupt vector, and that somewhere you properly declared count.

In ICC12, when you use #pragma interrupt_handler, thr rti return is
automatically coded. you do not have to add it with an asm statement.

You did not show any code to initialize and enable the timer, and rti
interrupt. without this, the timer interrupt will never be called. At 03:40 PM 3/3/2004, you wrote:
>Thanks for replying so quickly!
>
>We are using a hcs12dp256 Motorolla Microcontroller. The purpose of
>our robot is to navigate a game board (the game board of the Trinity
>Firefighting robot competition) and retrieve an object. We want our
>servo motors to run for a specific time and stop either because the
>time came up or because an IR sensors says a wall is in the way or
>something.
>
>/* 520 */ void setISR ( void ( * func_ptr ) ( void ) )
>/* 521 */ {
>/* 522 */ asm("LDD %func_ptr") ;
>/* 524 */ asm("PSHD") ;
>/* 525 */ asm("CLRA") ;
>/* 526 */ asm("LDAB # 56") ;
>/* 527 */ asm("LDX 0xEEA4") ;
>/* 528 */ asm("JSR 0 , X") ;
>/* 529 */ asm("PULD") ;
>/* 530 */
>/* 531 */ }
>
>RTICTL = 0x0014;
>CRGFLG = 0x80;
>
>DBug12FNP->SetUserVector(56, (char *)Timer);
>printf("Loc: %x -- %p\n", Timer, _ADDR(0x3e70)); >#pragma interrupt_handler Timer
>void Timer()
>{
> count++;
> CRGFLG = 0x80;
> asm("rti");
>}
>
>OK, there is some of the code we are trying to use. The first chunk
>was a test with some assembly we saw that supposedly got the
>interrupts working (or something that we could test). ICC12 has the
>feature of writing assuembly right into the program, which is cool,
>but it didn't really work for us.
>
>The second section of code is where we try to set the timer and real
>time interrupt (rti) with allocated vectors and such. It actually
>spits out the output shown and is what we set it up to be, but then
>nothing works in the last section of code.
>
>We wanted the loop to just use our interrupt handle to stop the
>program (interrupt it), increase the number, and move on, but when
>we run it, the output just stays at zero.
>
>Thanks again for your help. If seeing the interrupt_handle function
>would be helpful, I can post that guy too!
>
>Later.
>
>Clay >
>
>--------------------To learn more
>about Motorola Microcontrollers, please visit
>http://www.motorola.com/mcu
>o learn more about Motorola Microcontrollers, please visit
>http://www.motorola.com/mcu
>
>Yahoo! Groups Links >
>




You may want to check out the book by Han-way Huang (ISBN 0766834484) which
is specifically for the 68hc12 series processors, covers assembly and C
examples throughtout the book if profuse manner, has the code on CD, and can
be purchased used reletively cheaply - I got mine for $35. Best book I
found and I bought 8 of them! Sydney
----- Original Message -----
From: coolguyclay
To:
Sent: Tuesday, March 02, 2004 8:30 PM
Subject: [68HC12] Real Time Interrupts Hello. My group (school project) is using the ICC12 C compiler to
run our controller. We are having a hard time getting the interrupts
to work. Right now out movement is based on loops, but for more
accurate movement and to incorporate sensor control to our robot, we
think we need interrupts. We'd appreciate any suggestions, code
snippets, or advice you can give. Thanks!
--------------------To learn more
about Motorola Microcontrollers, please visit
http://www.motorola.com/mcu
o learn more about Motorola Microcontrollers, please visit
http://www.motorola.com/mcu

----
--
Yahoo! Groups Links

a.. To