MC9S08GT16A Interrupts?

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

MC9S08GT16A Interrupts?

2,774 Views
Kerms
Contributor I
Hello, I am trying to use a MC9S08GT16A to measure a PPM signal from an RC receiver.
 
As such I need to measrue the duration of a train of pulses. This is easily done with an interrupt and a timer, but I am wondering which pins can trigger an rising/falling edge interrupt?
 
The documentation says there are several user defined interrupt vectors, but I am not sure how those work.
 
I would like to be able to measure 4 different pulse trains so it looks like PTD0-PTD4 would all work, but can I also get it to trigger an interrupt on any general purpose I/O pin as well?
 
Appreciate any information.
Labels (1)
0 Kudos
10 Replies

814 Views
PEREA
Contributor I
thanks mac,
 
I want to measure both, the code should be in C, please, Regards.
 
Sergio
0 Kudos

814 Views
bigmac
Specialist III
Hello Sergio,
 
You have yet to clarify the repetition period of the pulses you are attempting to measure.  This is important, if longer than twice the maximum pulse width period previously stated.
 
There are also some other aspects that will need to give thought, that may determine the feasibility of what you are trying to achieve -
  • The bus frequency you intend using.
  • The period measurement resolution you expect to achieve (cannot be smaller than the bus period).
  • Whether you require to totalize or average the period for multiple input cycles (to reduce the effects of jitter).
  • How you intend to store the period data, ready for further processing.
  • Whether you also have PWM output from other channels on the same TPM module.
 
Regards,
Mac
 
0 Kudos

814 Views
PEREA
Contributor I
thanks peg,
 
I need to measure the time between the pulses, duration of pulses are about 250 to 1500 us, please you could send me an example and I will try to understand it.
0 Kudos

814 Views
bigmac
Specialist III
Hello,
 
Could you confirm whether your question concerns the variable pulse width signal from a RC receiver (as the original post did).  Are you attempting to measure the pulse width period, the period between successive pulses, or both?  For the case of a RC signal, the period between successive pulses will be approximately 20ms.
 
Please indicate whether code examples should be in assembler or C.
 
Regards,
Mac
 
0 Kudos

814 Views
PEREA
Contributor I
I AM A BEGINNER, COULD YOU HELP ME WITH THE CODE OF SOME EXAMPLE? I USE DEMO9SO8QG8, M9S08QG8CPBE AND CODEWARRIOR V. 5.1, THANKS, BEST REGARDS.
0 Kudos

814 Views
peg
Senior Contributor IV
Hello and welcome to the forums,

There are two basic methods to measure frequency.
With one you measure how many pulses within a fixed timeframe.
The other is to measure the time between the pulses.
You may need to do both depending on the frequency range.
Which version you choose/need depends on several factors:
1. Expected frequency range of the sampled signal
2. Expected update time of the output
3. Sampling frequency of the measuring device

When counting pulses, you need to ensure you get enough pulses to prevent to much granularity at the lower end. If this time period is too long for your expected output update rate then you need to measure the time between the pulses. Here you have an issue with if the frequency goes to zero, how long do you wait for thet next pulse to come in? When the frequency gets to high you start to get granularity problems again.

So, before you can get a simple answer, we need some specs of what you are trying to do.

0 Kudos

814 Views
PeterHouse
Contributor I
Kerms,

I have written code to receive data from an RC receiver using a 6811 a while back.

Using the '08,  I would recommnd using one of the pins which can interrupt on both edges like a timer capture interrupt pin.  At the end of the idle period you want to stop, clear and restart the timer along with a channel counter.  On each succeeding channel pulse edge you will stop, read to temp location, store, and restart the timer and then store the reading to the correct channel location based on the channel counter and exit the interrupt.  Make sure to check your channel counter for validity so you don't write to the wrong memory location.

Configure the timer period for the resolution you desire and so the overflow interrupt will indicate a loss of valid signal so you can set a flag to handle that condition.

Good Luck,

Peter House
0 Kudos

814 Views
Kerms
Contributor I
Thanks Peter,
 
That is basically the method I was going to try. What I am trying to find out is if I have to use PTD0-PTD4 or if I can interrupt on any of the general purpose I/O pins.
 
Also do you have any recommendations on how to track 4 different PWM inputs using only one timer? My current method is to use 4 intergers, and on each interrupt, my pulse duration would be (current timer - counter) plus a bit more for the overflow conditon where counter > current timer. This would just require the timer to run continously and for me to do 2 to 3 16bit subtractions per channel.
0 Kudos

814 Views
bigmac
Specialist III
Hello,
 
The most straightforward way to measure the pulse width of four different RC channels is to use input capture associated with four different TPM channels.  For a total of four channels, you will need to use either three channels from TPM1, and one from TPM2, or alternatively two channels from each of TPM1 and TPM2.  For input capture, you must use the appropriate PTD pins.
 
The advantage of using input capture over other possible methods is that any interrupt latency (delay until an interrupt is serviced) will not affect the measured pulse width accuracy.  For simplicity of operation, the periods you are measuring should not exceed the TIM overflow period - you then do not need to take into account any timer overflows, but require a simple unsigned subtraction of two 16-bit values, for each of the four channels.  For each TPM module, leave the TPMxMOD value at the default.
 
You will require separate (but similar) ISR code for each channel.  I would suggest that you first interrupt on a positive edge, and then toggle the detection edge during the processing of each interrupt (don't set up for interrupt on both edges).  This will avoid any ambiguity of the particular edge currently being processed.
 
Regards,
Mac
 
0 Kudos

814 Views
peg
Senior Contributor IV
Hi,

The method Mac has proposed is exactly what I would suggest.
The only reason I can think of for doing it any other way would be that you have already used the timer channels for other purposes.
This is exactly what the input capture mode of the TPM module is for!
Doing this by using 4 seperate interrupts that don't automatically latch the counter value could lead to significant errors when 4 edges occur at almost the same time.

0 Kudos