Motorola HC08 interrupts

Do you have a question? Post it now! No Registration Necessary

Translate This Thread From English to

Threaded View
Hi,


I'm very new to the motorolla chips (or programming MC for that
matter). i am tryin to figure out how to write an interrupt service
routine for the Keyboard interrupt.



Quoted text here. Click to load it


interrupt 15 void KBI_ISR (void) {
...some code
}

is this right? if so, can i replace KBI_ISR with some other name? and
if i want to write an interrupt for IRQ, how do i know which interrupt
number to use? how do i know which interrupt number to use for any of
the interrupts?


I've read the 230 page manual and couldn't find it in there, is it
there?

I'm using MC68HC908QY4 chip.


Thanks in advance,
Aria


Re: Motorola HC08 interrupts
Quoted text here. Click to load it

The '08 core has a table of interrupt vectors in the memory map.  You need
to populate these vectors correctly so that the 2-byte addresses point to
the interrupt service routines.

Interrupts are largely a hardware thing.  The hardware fetches the
associated vector.

The name of the interrupt service routine, with most development tools, is
irrelevant.  You could name it "my_dog_fido" and it would be OK, so long as
the name of the routine matched the name used to populate the interrupt
vector.

However, with most development tools (and you should have let us know which
tools you're using), you would want to give the function a special qualifier
(typically "interrupt" or "_interrupt_" or "@interrupt") to the compiler
know it is compiling an ISR.  This affects the termination sequence (RTI
versus RTS), as well as rules about how to use and restore certain registers
and memory areas.

Dave.




Re: Motorola HC08 interrupts
Hi Dave,

Thanks for the reply. Like I said, I'm new to this and unfortunately I
have no idea how to populate this "Interrupt Vector" that you talk
about. I know what you mean by it I just don't know how to populate it.

I'm using CodeWarrior to write the code and download them to my chip.

Thanks in advance,
Aria


Re: Motorola HC08 interrupts
Quoted text here. Click to load it

Look at the examples supplied with CodeWarrior, like the demo M68QTY
demo board software.

Re: Motorola HC08 interrupts
The vector table for the QY is found on the datasheet. Please refer to
page 32 of the datasheet (Rev. 5) found here:

http://www.freescale.com/files/microcontrollers/doc/data_sheet/MC68HC908QY4.pdf

To populate the interrupt vector table for the interrupts you are want
to use (you don't have to populate them all unless you are willing to
use them) in Codewarrior you simply define an interrupt service routine
(and populate its vector table entry at the same time) as the
following:

interrupt NN void YourInterruptNameHere (void)
{
}


Where NN is the vector table entry.

0 for Reset (NEVER CHANGE THIS UNLESS YOU PROVIDE YOUR OWN STARTUP
FILE)
1 for the Software Interrupt
2 for the external IRQ
3 Not used
4 Timer Channel 0
...
15 Keyboard Interrupt
16 ADC

Example:

interrupt 15 void MyFirstKeyboardInterrupt (void)
{
    KBSCR |= 0x04;    /* Ack this interrupt */
    /* Do your stuff here */
}


void main (void)
{
    KBIER |= 0x5;    /* Enable KBI0 and KBI2 IRQs */
    EnableInterrupts;
    /* main loop goes here */
}


To simply test your Interrupt handing you can use the simulator and
write a handler to populate and process the Software Interrupt. Here is
the example;

interrupt 1 void MySoftwareInterrupt (void)
{
    __asm ( "nop" );    /* Place your breakpoint here */
}


void main (void)
{
    EnableInterrupts;
    __asm ( "swi" );    /* Perform a sowftare interrupt */
    for (;;);
}


Happy coding!


Re: Motorola HC08 interrupts
Hi,

Thanks for the helpful post. Just one thing is unclear now:

You say "Where NN is the vector table entry". Are you talkinga bout the
vector table on page 32 of the manual? because in that one it says that
IF15 is the ADC vector so i figure the ADC interrupt should be 15 but
this is obviously not the case. So, what vector table are we talking
about and how do i access it to see what number is what?

Thanks,
Aria


Re: Motorola HC08 interrupts
Quoted text here. Click to load it

Hi,

Thanks for the response. It is very helpful. Only one thing remains
unclear and I can't figure it out. You say where "NN is the number in
the vector table." How are you reading this number? and where is this
vector table? is it the one on page 32 of the datasheet? Because
looking at that one, It says
Quoted text here. Click to load it

so i figure 15 would be the interrupt for ADC, but obviously it's not
so i guess i don't know how to read the table. Which table should I use
to read these numbers and is there a special method to reading them?
(sorry if this questions sounds too unprofessional but i'm just
learning).

thx in advance,
Aria


Re: Motorola HC08 interrupts
Yes, I know it sounds confusing. The vector table is basically a table
of 16-bit addresses that the CPU indexes so it can know to which
address "jump" when an interrupt happens. When an interrupt happens
the CPU loads the contents of the vector table to its Program Counter
register so it can start executing interrupt code.



When you say



$FFDE ADC conversion complete vector (high)
$FFDF ADC conversion complete vector (low)



You are actually referring to the locations in flash memory on which
the 16-bit address of the ADC Interrupt function can be found.



However an easier way to refer to these locations is by naming them by
pair. So $FFDE and $FFDF is pair number 16. Why?



Because of the following:

FFFF:FFFE pair 0  - RESET

FFFD:FFFC pair 1 - SWI

FFFB:FFFA pair 2

And so on...

FFDF:FFDE is pair 16



Ignore what the Vector Column in Table 2-1 says. By naming IF1 through
IF15 to vectors

pairs 2 through 16, the authors wanted to differentiate the interrupts
that are usually related to hardware events and have NOTHING to do with
the way Codewarrior defines interrupt vectors. The later defines
interrupts vectors as pairs starting from 0. Simply count the rows from
bottom up on TABLE 2-1 starting from 0 (reset) and that will give you
the vector number NN for Codewarrior.


Re: Motorola HC08 interrupts
phew! thx a lot. you just brought an end to 4 days of searching for how
they were numbering these interrupts. thx again.


Re: Motorola HC08 interrupts
The vector table for the QY is found on the datasheet. Please refer to
page 32 of the datasheet (Rev. 5) found here:

http://www.freescale.com/files/microcontrollers/doc/data_sheet/MC68HC908QY4.pdf

To populate the interrupt vector table for the interrupts you are want
to use (you don't have to populate them all unless you are willing to
use them) in Codewarrior you simply define an interrupt service routine
(and populate its vector table entry at the same time) as the
following:

interrupt NN void YourInterruptNameHere (void)
{
}


Where NN is the vector table entry.

0 for Reset (NEVER CHANGE THIS UNLESS YOU PROVIDE YOUR OWN STARTUP
FILE)
1 for the Software Interrupt
2 for the external IRQ
3 Not used
4 Timer Channel 0
...
15 Keyboard Interrupt
16 ADC

Example:

interrupt 15 void MyFirstKeyboardInterrupt (void)
{
    KBSCR |= 0x04;    /* Ack this interrupt */
    /* Do your stuff here */
}


void main (void)
{
    KBIER |= 0x5;    /* Enable KBI0 and KBI2 IRQs */
    EnableInterrupts;
    /* main loop goes here */
}


To simply test your Interrupt handing you can use the simulator and
write a handler to populate and process the Software Interrupt. Here is
the example;

interrupt 1 void MySoftwareInterrupt (void)
{
    __asm ( "nop" );    /* Place your breakpoint here */
}


void main (void)
{
    EnableInterrupts;
    __asm ( "swi" );    /* Perform a sowftare interrupt */
    for (;;);
}


Happy coding!


Site Timeline