Part Number:LAUNCHXL-F28069M
Hello! I'm terribly sorry for this wall of text but we don't quite understand how this is working and we could really use some help!
My partner and I are using the eCAP module to detect how close an object is to our ultrasonic sensors.
It works like this:
We're trying to set it up like this:
An ultrasonic sensor returns a high digital signal for a length of time based on how close it is to the object that is detected, ie. If its far away, the digital signal is high for say 100micro-seconds, if the object is close to the ultrasonic sensor, then the ultrasonic sensor will output a high digital spike for a very short period of time (say 1micro-second).
Ideally, Id like to detect the positive edge of the signal returned from the ulatrsonic sensor, and sample it over an amount of time. If it goes low really quickly, I know the theres an object close to the ultrasonic sensor. If it stays high, I know the object is far away.
We just want to measure t_pw.
We've set up ECCTL1 as so:
ECap1Regs.ECCTL1.bit.FREE_SOFT = 1; //stop after interrupt for debugging purposes
ECap1Regs.ECCTL1.bit.PRESCALE = 0; // no diviser
ECap1Regs.ECCTL1.bit.CAPLDN = 1 // enable capture units
ECap1Regs.ECCTL1.bit.CAP1POL = 1; // start timing on Falling edge
ECap1Regs.ECCTL1.bit.CAP2POL = 0; // return value on Rising edge
ECap1Regs.ECCTL1.bit.CAP3POL = 1; // start timing on Falling edge
ECap1Regs.ECCTL1.bit.CAP4POL = 0; // start timing on Rising edge
ECap1Regs.ECCTL1.bit.CTRRST1 = 1; // after detecting a rising edge, reset the timer
ECap1Regs.ECCTL1.bit.CTRRST2 = 1; // after detecting a falling edge, return the value
ECap1Regs.ECCTL1.bit.CTRRST3 = 1; // this just shadows eCAP1, so shouldnt it reset when we reset CTRRST1?
ECap1Regs.ECCTL1.bit.CTRRST4 = 1; // this just shadows eCAP2, so shouldnt it reset when we reset CTRRST2?
// CONTROL REGISTER 2
ECap1Regs.ECCTL2.bit.CONT_ONESHT = 0; // continuous because we want to keep the timer running after the first edge (event)?
ECap1Regs.ECCTL2.bit.STOP_WRAP = 3; // iwe just want the difference between the rising event and falling event so this doesn't matter?
ECap1Regs.ECCTL2.bit.SYNCI_EN = 1; // Enable sync in
ECap1Regs.ECCTL2.bit.SYNCO_SEL = 0; // Pass through
ECap1Regs.ECCTL2.bit.TSCTRSTOP = 1; // Start Counter
ECap1Regs.ECCTL2.bit.REARM = 1; // arm one-shot
ECap1Regs.ECCTL2.bit.TSCTRSTOP = 0; // Make sure the counter is stopped
ECap1Regs.ECEINT.bit.CEVT4 = 1; // 2 events (rising then falling) = interrupt, then we get the value
______________________
Does this make sense?
______________________
Also, a couple last quick questions!
We have 5 ultrasonic sensors, each that just need 1 pin. Looking at example code, I believe we have enough pins, is this correct?
Lastly, does the value returned represent the amount of cycles counted within the pulse width? And which register is the value of the timer returned to?