Sign in

username:

password:



Not a member?

Search 68hc12



Search tips

Subscribe to 68hc12



68hc12 by Keywords

68HC1 | 812A4 | 9S12DP256 | Bootloader | CodeWarrior | D60A | Debugger | DP256 | ECT | EEPROM | EVB | Flash | HC1 | HCS12 | I2C | IAR | ICC1 | Interrupts | LCD | M68KIT912DP256 | MC9S12DP256 | MC9S12DP256B | Metrowerks | Motor | MSCAN | Multilink | PLL | Quadrature | SDI | SPI | Transceiver | XFC

Ads

Discussion Groups

See Also

DSPFPGAElectronics

Discussion Groups | 68HC12 | RTI function for S12DP256B

Join our technical discussions about Freescale Microcontrollers: M68HC12. (Freescale Semiconductor is a Subsidiary of Motorola).

RTI function for S12DP256B - shepherd_shane - Oct 30 22:22:16 2006

Hey everybody,

I am using the syn code editor to code my microcontroller in c.I am
using the real time interupt to read from a port at a given cycle. I
am trying to figure out how to read in 8 values(0 or 1) from a pin 1
by 1 and then store that value in an array.

Can somebody help me
Thanks

______________________________
Stellaris® MCU Family: New Parts, New Package, New Price.


(You need to be a member of 68hc12 -- send a blank email to 68hc12-subscribe@yahoogroups.com )


Re: RTI function for S12DP256B - Jani Soderstrom - Oct 31 12:39:37 2006

shepherd_shane wrote:
> I am using the syn code editor to code my microcontroller in c.I am
> using the real time interupt to read from a port at a given cycle. I
> am trying to figure out how to read in 8 values(0 or 1) from a pin 1
> by 1 and then store that value in an array.
>

This sounds like a school exercise but I'll answer it anyway.

You can check an individual pin with a logical AND operation (you know
hexadecimal numbers?):
if (PORTA & 0x02) // logical 1
if ( !(PTH & 0x80) ) // logical 0

The usage of an array might be something like this if I understood you
correctly:
unsigned char i;
unsigned char array[8];
unsigned char mask = 0x01;
for ( i = 0 ; i < 8 ; i++ ) {
if (PORTB & mask)
array[i] = 1;
else
array[i] = 0;
mask <<= 1;
}

______________________________
Stellaris® MCU Family: New Parts, New Package, New Price.


(You need to be a member of 68hc12 -- send a blank email to 68hc12-subscribe@yahoogroups.com )

Re: RTI function for S12DP256B - Mohammed El Korek - Oct 31 14:16:23 2006

Well Jani i think Shane wanted to know the right header to use when using
the real-time interrupt header... the routine to continuously read in 8 bits
from pin 1 in a digital port like A should happen as follows:

void RTI_isr(void); // this is the interrupt service routine

/* interrupt pragma*/

#pragma interrupt_handler RTI_isr

/* initialize vector table */

#pragma abs_address: 0xFFF0 (CHECK THIS ADDRESS.... the supporting
documentation with your microcontroller must contain the vector address
revision addresses for each function; which is the RTI in your case)

void (*RTI_interrupt_vector[])(void)={RTI_isr};

#pragma end_abs_address

// check how these routines operate... the real-time interrupt must be
enabled

// and you should select a byte on the RTICTL (control register) that
corresponds to your preferred time scale

CRGINT = 0x80; // RTIE bit is set ; enable real time interrupt

RTICTL = 0x60; // interrupt every 2.048 ms (1.7 % percentage error)

asm("CLI\n"); // initialize interrupts

while(1){

; // wait for interrupt
}

// RTI function: capture 1 serial character

/*---------------------------------------------------------------------------------*/

/* Function: RTI_isr: RTI interrupt occurs every 2.048 ms */

/*---------------------------------------------------------------------------------*/

void RTI_isr(void)

{

// reset the RTI interrupt flag

CRGFLG = 0x80;
// insert the code you need to read from the digital port here

}

Hope this helps! WHEN i did my first RTI code.. it definitely was not
classwork ;)

On 10/31/06, Jani Soderstrom wrote:
>
> shepherd_shane wrote:
> > I am using the syn code editor to code my microcontroller in c.I am
> > using the real time interupt to read from a port at a given cycle. I
> > am trying to figure out how to read in 8 values(0 or 1) from a pin 1
> > by 1 and then store that value in an array.
> > This sounds like a school exercise but I'll answer it anyway.
>
> You can check an individual pin with a logical AND operation (you know
> hexadecimal numbers?):
> if (PORTA & 0x02) // logical 1
> if ( !(PTH & 0x80) ) // logical 0
>
> The usage of an array might be something like this if I understood you
> correctly:
> unsigned char i;
> unsigned char array[8];
> unsigned char mask = 0x01;
> for ( i = 0 ; i < 8 ; i++ ) {
> if (PORTB & mask)
> array[i] = 1;
> else
> array[i] = 0;
> mask <<= 1;
> }



(You need to be a member of 68hc12 -- send a blank email to 68hc12-subscribe@yahoogroups.com )

Re: RTI function for S12DP256B - Shane Shepherd - Nov 1 19:53:49 2006

Thanks a lot its actually for a project...

I am also having a hard time figuring out the exact process with a real time interrupt. is this a good understanding of it you can generate a timer overflow with a specific count value depending on how many times you want the interrupt to happen, once the interupt happens you reset the count and clear the rti flag.

----- Original Message ----
From: Jani Soderstrom
To: 6...@yahoogroups.com
Sent: Tuesday, October 31, 2006 12:36:17 PM
Subject: Re: [68HC12] RTI function for S12DP256B

shepherd_shane wrote:

> I am using the syn code editor to code my microcontroller in c.I am

> using the real time interupt to read from a port at a given cycle. I

> am trying to figure out how to read in 8 values(0 or 1) from a pin 1

> by 1 and then store that value in an array.

>

This sounds like a school exercise but I'll answer it anyway.

You can check an individual pin with a logical AND operation (you know

hexadecimal numbers?):

if (PORTA & 0x02) // logical 1

if ( !(PTH & 0x80) ) // logical 0

The usage of an array might be something like this if I understood you

correctly:

unsigned char i;

unsigned char array[8];

unsigned char mask = 0x01;

for ( i = 0 ; i < 8 ; i++ ) {

if (PORTB & mask)

array[i] = 1;

else

array[i] = 0;

mask <<= 1;

}



[Non-text portions of this message have been removed]



(You need to be a member of 68hc12 -- send a blank email to 68hc12-subscribe@yahoogroups.com )

Re: RTI function for S12DP256B - Mohammed El Korek - Nov 2 0:08:17 2006

Exactly... but you also have to make sure that, in addition to the setting
of the registers which will initialize and end a real-time interrupt run...
you have to also set the RTICTL (control register) as your counter... this
counter will serve as the time you need to interrupt your program and invoke
the service routine (which in your case will read bits 1 by 1 from a digital
port)..

the documentation of 9S12DP256B should help.. let me know if you need more
details on it...

by the way: what EVB/ target board are you using??

Mohammed El Korek
Student Member, IEEE and IEEE C.S
American University of Sharjah
Dubai, United Arab Emirates
Cell #: 00-971-50-749-3133

On 11/2/06, Shane Shepherd wrote:
>
> Thanks a lot its actually for a project...
>
> I am also having a hard time figuring out the exact process with a real
> time interrupt. is this a good understanding of it you can generate a timer
> overflow with a specific count value depending on how many times you want
> the interrupt to happen, once the interupt happens you reset the count and
> clear the rti flag.
>
> ----- Original Message ----
> From: Jani Soderstrom
> To: 6...@yahoogroups.com
> Sent: Tuesday, October 31, 2006 12:36:17 PM
> Subject: Re: [68HC12] RTI function for S12DP256B
>
> shepherd_shane wrote:
>
> > I am using the syn code editor to code my microcontroller in c.I am
>
> > using the real time interupt to read from a port at a given cycle. I
>
> > am trying to figure out how to read in 8 values(0 or 1) from a pin 1
>
> > by 1 and then store that value in an array.
>
> > This sounds like a school exercise but I'll answer it anyway.
>
> You can check an individual pin with a logical AND operation (you know
>
> hexadecimal numbers?):
>
> if (PORTA & 0x02) // logical 1
>
> if ( !(PTH & 0x80) ) // logical 0
>
> The usage of an array might be something like this if I understood you
>
> correctly:
>
> unsigned char i;
>
> unsigned char array[8];
>
> unsigned char mask = 0x01;
>
> for ( i = 0 ; i < 8 ; i++ ) {
>
> if (PORTB & mask)
>
> array[i] = 1;
>
> else
>
> array[i] = 0;
>
> mask <<= 1;
>
> }
>

--
[Non-text portions of this message have been removed]



(You need to be a member of 68hc12 -- send a blank email to 68hc12-subscribe@yahoogroups.com )

Re: RTI function for S12DP256B - shepherd_shane - Nov 2 12:15:43 2006

Thanks again, I am using the mini-dragon evaluation board. I am still
sketchy on what actually triggers the real time interrupt since I am
coding in c in my main function do I have a function that calls the
Interrupt service routine or do I set the count value in an if
statmnet and do whatever task if cntRti= 416 in my case.
Here are the functions I have :

__attribute__((interrupt)) void IsrRti(void)
{
cntRti++; // increment the counter
CRGFLG = 0x80; // clear rti flag

}

void InitRti(void)
{
cntRti = 0; // reset the cycle counter
RTICTL = 0x63; // 8.192ms with 16MHz Xtal
CRGINT |= 0x80; // enable RTI interrupt
}

--- In 6...@yahoogroups.com, "Mohammed El Korek"
wrote:
>
> Exactly... but you also have to make sure that, in addition to the
setting
> of the registers which will initialize and end a real-time interrupt
run...
> you have to also set the RTICTL (control register) as your
counter... this
> counter will serve as the time you need to interrupt your program
and invoke
> the service routine (which in your case will read bits 1 by 1 from a
digital
> port)..
>
> the documentation of 9S12DP256B should help.. let me know if you
need more
> details on it...
>
> by the way: what EVB/ target board are you using??
>
> Mohammed El Korek
> Student Member, IEEE and IEEE C.S
> American University of Sharjah
> Dubai, United Arab Emirates
> Cell #: 00-971-50-749-3133
>
> On 11/2/06, Shane Shepherd wrote:
> >
> > Thanks a lot its actually for a project...
> >
> > I am also having a hard time figuring out the exact process with a
real
> > time interrupt. is this a good understanding of it you can
generate a timer
> > overflow with a specific count value depending on how many times
you want
> > the interrupt to happen, once the interupt happens you reset the
count and
> > clear the rti flag.
> >
> > ----- Original Message ----
> > From: Jani Soderstrom
> > To: 6...@yahoogroups.com
> > Sent: Tuesday, October 31, 2006 12:36:17 PM
> > Subject: Re: [68HC12] RTI function for S12DP256B
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> > shepherd_shane wrote:
> >
> > > I am using the syn code editor to code my microcontroller in c.I am
> >
> > > using the real time interupt to read from a port at a given cycle. I
> >
> > > am trying to figure out how to read in 8 values(0 or 1) from a pin 1
> >
> > > by 1 and then store that value in an array.
> >
> > >
> >
> >
> >
> > This sounds like a school exercise but I'll answer it anyway.
> >
> >
> >
> > You can check an individual pin with a logical AND operation (you know
> >
> > hexadecimal numbers?):
> >
> > if (PORTA & 0x02) // logical 1
> >
> > if ( !(PTH & 0x80) ) // logical 0
> >
> >
> >
> > The usage of an array might be something like this if I understood you
> >
> > correctly:
> >
> > unsigned char i;
> >
> > unsigned char array[8];
> >
> > unsigned char mask = 0x01;
> >
> > for ( i = 0 ; i < 8 ; i++ ) {
> >
> > if (PORTB & mask)
> >
> > array[i] = 1;
> >
> > else
> >
> > array[i] = 0;
> >
> > mask <<= 1;
> >
> > }
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> > --
> [Non-text portions of this message have been removed]
>



(You need to be a member of 68hc12 -- send a blank email to 68hc12-subscribe@yahoogroups.com )

Re: RTI function for S12DP256B - Jefferson Smith - Nov 2 14:16:30 2006

--- In 6...@yahoogroups.com, "shepherd_shane"
wrote:
>
> Thanks again, I am using the mini-dragon evaluation board.
> I am still
> sketchy on what actually triggers the real time interrupt since I am
> coding in c in my main function do I have a function that calls the
> Interrupt service routine or do I set the count value in an if
> statmnet and do whatever task if cntRti= 416 in my case.
> Here are the functions I have :
>
> __attribute__((interrupt)) void IsrRti(void)
> {
> cntRti++; // increment the counter
> CRGFLG = 0x80; // clear rti flag
>
> }
>
> void InitRti(void)
> {
> cntRti = 0; // reset the cycle
>counter
> RTICTL = 0x63; // 8.192ms with 16MHz
>Xtal
> CRGINT |= 0x80; // enable RTI interrupt
> }
I like the dragon boards too. Hopefully this explanation helps with
your RTI questions...

The only reason we need an RTI module in the mcu is that it works
automatically, without relying on your program controlling it. It is
basically a hardware counter (not the cntRti which you created in
software), so you don't even have to see it. When you write a value to
TRICTL, you are saying that you want the counter to be set at a
certain speed. smaller number would happen faster (more often).
Everytime the RTI "happens", it means that the hardware counter has
reached a certain count and when that happens, it automatically calls
the function you set up as the RTI handler (IsrRti).

Of course, every time the RTI happens, your variable (cntRti) will
count one more. Your regular program can do something with that value,
like display it.

What some people have warned is that since IsrRti() can be called
automatically, it could be right in the middle of something you were
doing with the variable that it modifies. With the ISR this simple,
however, it's probably not a problem for you.

______________________________
Stellaris® MCU Family: New Parts, New Package, New Price.


(You need to be a member of 68hc12 -- send a blank email to 68hc12-subscribe@yahoogroups.com )

Re: Re: RTI function for S12DP256B - Shane Shepherd - Nov 2 16:20:21 2006

Can you explain the output compare for me
----- Original Message ----
From: Jefferson Smith
To: 6...@yahoogroups.com
Sent: Thursday, November 2, 2006 2:12:13 PM
Subject: [68HC12] Re: RTI function for S12DP256B

--- In 68HC12@yahoogroups. com, "shepherd_shane"

wrote:

>

> Thanks again, I am using the mini-dragon evaluation board.

> I am still

> sketchy on what actually triggers the real time interrupt since I am

> coding in c in my main function do I have a function that calls the

> Interrupt service routine or do I set the count value in an if

> statmnet and do whatever task if cntRti= 416 in my case.

> Here are the functions I have :

>

> __attribute_ _((interrupt) ) void IsrRti(void)

> {

> cntRti++; // increment the counter

> CRGFLG = 0x80; // clear rti flag

>

> }

>

> void InitRti(void)

> {

> cntRti = 0; // reset the cycle

>counter

> RTICTL = 0x63; // 8.192ms with 16MHz

>Xtal

> CRGINT |= 0x80; // enable RTI interrupt

> }

I like the dragon boards too. Hopefully this explanation helps with

your RTI questions...

The only reason we need an RTI module in the mcu is that it works

automatically, without relying on your program controlling it. It is

basically a hardware counter (not the cntRti which you created in

software), so you don't even have to see it. When you write a value to

TRICTL, you are saying that you want the counter to be set at a

certain speed. smaller number would happen faster (more often).

Everytime the RTI "happens", it means that the hardware counter has

reached a certain count and when that happens, it automatically calls

the function you set up as the RTI handler (IsrRti).

Of course, every time the RTI happens, your variable (cntRti) will

count one more. Your regular program can do something with that value,

like display it.

What some people have warned is that since IsrRti() can be called

automatically, it could be right in the middle of something you were

doing with the variable that it modifies. With the ISR this simple,

however, it's probably not a problem for you.



[Non-text portions of this message have been removed]



(You need to be a member of 68hc12 -- send a blank email to 68hc12-subscribe@yahoogroups.com )

Re: Re: RTI function for S12DP256B - Mohammed El Korek - Nov 3 10:37:48 2006

Your comment is 100 % right on, Jeff Smith... I did actually use the RTI to
receive data from a medical sensor i was working with. That sensor was
sending data in standard RS-232 format (8-N-1)... i was able to allow the
Minidragon's serial communication interface to read from the transmit pin of
that sensor and store the serial data in a buffer. What was so fascinating
is that i was able to specify a certain time period for the RTI to interrupt
the serial and transmission and was was even better was that i managed to
call a custom delay function inside the ISR... this guaranteed that the RTI
interrupted the serial transmission at the exact time where meaningful
8-bit data would appear in the SCI data register.

Of course, managing RTI, SCI, and delays was a very painful yet rewarding
approach...

Mohammed El Korek
Student Member, IEEE and IEEE C.S
American University of Sharjah
United Arab Emirates
[Non-text portions of this message have been removed]

______________________________
Stellaris® MCU Family: New Parts, New Package, New Price.


(You need to be a member of 68hc12 -- send a blank email to 68hc12-subscribe@yahoogroups.com )

Re: RTI function for S12DP256B - Jefferson Smith - Nov 3 15:45:03 2006

--- In 6...@yahoogroups.com, Shane Shepherd wrote:
> Can you explain the output compare for me

===== Here is something I've written recently =======

General Use of Timer Module for the MC9S12 Family

The Timer module's Output Compare (TOC) gives an amazingly simple
method of setting an accurate and fast timer. There are typically 8
TOCs in the ECT of the MCU, and each can trigger an Interrupt Service
Routine (ISR). Refer to the ECT documentation for official
descriptions of features. While the fundamental concept of TOC is very
simple, keep in mind that there are enhanced features added, and some
tricks to learn in real-world situations.

INITIALIZE

Writing 0x80 to the TSCR1 register enables the main timer called TCNT
(16 bits). That is a free running counter, which means that after it
counts to max (0xffff) it starts over again.

Writing 1 to TIOS will enable only timer 0 (TC0) as OC. If an ISR is
written to handle this event, then its address should be placed in the
vectors table. Write 1 to TIE to enable the interrupt. The output pin
(IOC0/PT0) can be set to do certain things by setting the mode in
TCTL2 (bits 1,0).

SIMPLE CONCEPT

This function is called "Output Compare" because it is simply
comparing the timer (in this case TC0) with the system counter, TCNT.
Each time the register TC0 is the same value as TCNT, the timer
triggers, and sets the flag (bit 0 of TFLG1). If the TIE bit is set,
that also calls the ISR. If the right mode is set (TCTL2), the output
pin (IOC0) will change accordingly. The flag bit (C0F) will stay set
until you clear it. That is typically done by: (1) Read TFLG1 to see
that the flag is set; (2) write a new value to TC0.



(You need to be a member of 68hc12 -- send a blank email to 68hc12-subscribe@yahoogroups.com )