mc9s12dp256 pulse accumulator

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

mc9s12dp256 pulse accumulator

5,833 Views
yklein
Contributor I
Hi,

I'm trying to measure a unknown pulse with the pulse accumulator interrupt.
I did not understand which register holds the time between the rising edge and the falling edge of the pulse, and when the PAIF is set.
My code is attached.
Yuval
Labels (1)
0 Kudos
8 Replies

683 Views
Steve
NXP Employee
NXP Employee
The pulse accumulator has two modes: it counts the number of pulses or it counts the amount of active time in a stream of pulses. It does not detect the start and stop times of individual pulses. That function is normally performed by the input capture function.
The S12DP256 has the enhanced capture function which can detect two events on a single input using the input capture buffer so you may be able to use that or you may choose to use two input capture pins. It really depends on the frequency of the pulse stream.
0 Kudos

683 Views
yklein
Contributor I
Hi Steve,

Let me explain what's mine final goal with the pulse accumulators. I have an ultrasonic sensor and a wheel encoder sensor I would like to capture the time the ultrasonic sensor output was high (to measure the distance) using PACA and capture the wheel encoder output using PACN0 or PACN1. What do you think is the best why to do it.

Yuval
0 Kudos

683 Views
Steve
NXP Employee
NXP Employee
The usual approach to measuring times is to use the timer input capture function. You record the time the event began and then the time the event ended and subtract the results to find the difference (accounting for timer overflows). Depending on the frequency of the signal you may have to use two input capture channels connected to the same signal. With two channels you can record differences down to one timer tick.
For the encoder the pulse accumulator can tell you how many pulses each output has produced but it may be more tricky to determine the direction of the encoder since the pulse accumulator does not directly record the time that a pulse occured. If you need to know the direction of the encoder rotation then you need know which edge is occuring first so it may be easier to use input captures for this again. Depending on the frequency of rotation you may not need to use the timer pins for this since a keyboard interrupt may be able to respond quickly enough.
0 Kudos

683 Views
yklein
Contributor I
I understand. I thought that the PACA in "gated time accumulation" will save the use of to input captures. Am I right?
Regarding the encoders I do not need to know the direction.
I'm trying to use PACN0 and PACN1 at record the wheel encoders and PACN2+PACN3 to capture the time the ultrasonic sensor output was high. The problem is the the wheel encoders are not working. here is my initialization:

oid initialize(){
PACN0=PACN1=PACN2=PACN3=0; /* let PACNA, PACN0 and PACN1 counts up from 0 */
TSCR1 = 0x90; /* enable TCNT and fast timer flag clear */
pulse_width=0;
TSCR2 = 0x00; /* set TCNT prescaler to 1 */
DDRT = 0x00; /* configure all timer port pins for input */
*(void (**)())0x3fda=pai_isr; //PA A interrupt vector;
PACTL = 0x61; // set PA to gated accumulator mode with input interrupt
PBCTL = 0x00;
TCTL4 = 0x05;
ICPAR = 0x03; //set PACN0 PACN1 to count W.E
asm("cli");
}
0 Kudos

683 Views
Steve
NXP Employee
NXP Employee
Gated-time may work depending on the incoming signal. Remember the clock for gated time is /64 so the resolution is limited to +/- 64 clocks. Also the PA will also accumulate multiple pulses so deciding when to read the result may require extra software.
0 Kudos

683 Views
yklein
Contributor I
Hi Steve,

if I'm using the PACA what will be the way to actually capture the time? (PACN3?)

yuval
0 Kudos

683 Views
Steve
NXP Employee
NXP Employee
You capture the time of an event by enabling the input capture for that pin (with the appropriate edge detection) in TIOS & TCTL3/4. The value of the main timer will be captured and stored in the input capture register TC3. You can use this value to determine when an event occured with respect to other edges on the same or other pins. Check the timer configuration bits to make sure things like the timer period etc. are configured as you require and remember to clear flags after the capture occurs.
0 Kudos

683 Views
yklein
Contributor I
Thanks Steve,

Just to make sure I understood you, If I'm enabling PACA, (PACTL=0x62), I need to enable the IC , (TIOS=0xC0), as well and capture the time using TC3/4?
0 Kudos