This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
Hello! I'm just wondering if the sampling input is configurable for a single pin, or if we HAVE to use 8 pins (GPIO7-GPIO15) to use that function? I'd like to use it to read an ultrasonic sensor input which reads a digital input over an amount of time, and takes action based on what the sampling period determines. I am using multiple ultrasonic sensors but the data they collect is for different functions. I might be misunderstanding the reference guide, but I'd like to sample a single ultrasonic sensor with one pin over the period. Is that doable?
Andrew,
For clarity, that is a GPIO feature to help reject signal bounce/noise. The way to interpret that sentence is that you may configure the qualification window that is applied to the GPIO signals. However, each group of eight GPIO signals will share the same qualification window setting (because it would require an impractical number of register fields to allow per-pin configuration). The eight GPIO signals will otherwise operate independently of each other.
If you are interested in measuring pulse duration or duty cycle, I recommend that you look into the eCAP module. It was designed for that purpose.
-Tommy
Hey Tommy!
I hate to bug you more, but i'm having trouble understanding just exactly how this works. This is is my 2nd microcontroller as im just as 2nd year student, but I have some questions regarding this, and I hope you can help me! If not, just let me know and I'll post a new thread!
We're trying to set it up like this:
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?
Andrew,
Next time, it would probably be best to start a new post, but no problem.
In plain English what are you trying to do with the eCAP? Something like: I am trying to capture the on-time of every pulse. OR, I am trying to measure the duty cycle of the first pulse after an event "X".
Reading through your comments it seems like you are a little confused on the function of the eCAP. Lets talk about a few of them.
Andrew Wenaus said: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
The polarity bit simply sets what event will trigger CAPx to capture the timestamp counter(TSCTR). It wont have any effect on " start timing" or "return value".
Andrew Wenaus said: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?
These do not shadow CAP1 or CAP2. That functionality is only used when the eCAP is in APWM mode. This comment also makes it sound as if you are thinking of each of the CAPx registers as it's own timer. That is not the case, there is one time for the entire module and the CAPx registers simply store the value of the TSCTR when their even occurs.
Andrew Wenaus said:ECap1Regs.ECCTL2.bit.CONT_ONESHT = 0; // continuous because we want to keep the timer running after the first edge (event)?
You have 2 options 1. One-shot mode: the eCAP module will stop after the modulo counter reaches the value in STOP_WRAP. In continuous mode the eCAP module will continue to operate after the modulo counter reaches the STOP_WRAP value, "wrapping" back to CAP1 and beginning to overwrite values.
Andrew Wenaus said:ECap1Regs.ECCTL2.bit.STOP_WRAP = 3; // iwe just want the difference between the rising event and falling event so this doesn't matter?
This determines if the eCAP will stop and wait an indefinite amount of time for you to read out the values or if it will overwrite the CAPx registers if new rising/falling edges are detected.
I would recommend starting with an example and then reading the chapter so that you can understand what each line of code is doing. Luckily the eCAP is a very simple module and the chapter is verbose enough to explain of the finer details.
Regards,
Cody
Andrew,
The first thing you need to do is choose Continuous mode or One-shot mode.
You can disable CAP3 and CAP4 if you modify the STOP_WRAP value.Andrew Wenaus said:How do we 'reset' the event detection after we detect the 2nd event?
The eCAP doesn't automatically return the difference. When read, it returns the value of the TSCTR at the time of the event. If you want to save time and avoid preforming "CAP2-CAP1" in your code: You could setup the eCAP to clear TSCTR at CAP1's event and then the stored value in CAP2 would be the difference between these events.Andrew Wenaus said:which register is the difference stored in?
I know the eCAP looks daunting, but it's actually a simple module!! I would estimate that you could understand 95% of the eCAP's functions with ~4 hours of working with examples and reading the manual... Which may be faster than asking questions on the forum.
Look into the registers I mentioned above and if you have more questions keep them coming!
Regards,
Cody