Hello everyone,
First of all, thanks for providing such an informative and helpful forum. E2E and it's contributors are a fantastic reasource. Please bear with me as I am an analog guy, just (3 weeks) new to uC programming with C and the MSP430 launchpad, and very much enjoying myself.
I would like explore the feasibility of using an MSP430F5172 (with the high resolution Timer_D module) to control and measure pulse trains for a compact ultrasonic time-of-flight flowmeter. For the flowmeter measurement principle to work properly, I need to generate acoustic signals and determine their transit time down to +/-10ns.
My time crictical routine is:
1) Write a sequence of deterministic pulses to 4 separate pins/channels to excite the transmit transducer
2) Idle for yet-to-be-determined amount of time (~60us after first excite pulse)
3) Start Timer_D
4) Capture 2 rising edges and 2 falling edges during the middle of an incoming, signal-conditioned pulse train sequence from my receive transducer
5) Prevent the CCR registers from overflowing
Note: My transducer frequency is 300kHz. So with MCLK = 25MHz, I should be able to service CCIFG interrupt and stop Timer_D within 39 clock cycles.
For this scheme to work, I have to know that my time-critical execution will always take the same number of MCLK cycles.
------------------------------------------------------------------------------
Translated into pseudocode:
1) Disable all interrupts except for CCIFG in Timer_D
2) Set up Timer_D: 200MHz, Up count, CCR1 capture rising edges, CCR0 falling edges, etc.
//Time T=0: ***Time-Critical execution of code starts here***
P1OUT = 0x01; // Start of +HV pulse
__delay_cycles(10)
P1OUT = 0x00; // End of +HV pulse
__delay cycles(HV+_delay)
P1OUT = 0x02; // Start of -HV pulse
__delay_cycles(HV-_length)
P1OUT = 0x00;
... more P1OUT writes for other pulses ...
__delay_cycles(until_arrival) // Delay until known midpoint of incoming pulsetrain
TDxCTL0 |= MC__CONTINOUS // Start Timer_D
while(1); // Wait for 2 rising edge and 2 falling edge captures, to trigger Timer D CCR interrupt
__interrupt void TIMER1_D0(void)
{
TDxCTL0 |= MC__STOP; // Stop TDR before any capture overflows, read arrival time of the acoustic pulses
}
Here are the big questions:
Are there any "gotchas" that would cause +/- MCLK cycles of execution during my time cricial routine?
Outside of my time cricital routine I plan to do calculations and relay results over I2C/SPI. Would this affect my MSP's stack/heap/bus/flash/mojo and introduce uncertainty into my time-critical sequence exectution?
Will simple procedural code such as the above, with no branching, compile predictably, or do I need to learn assembly?
Thanks for your help!
-Thomas