- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi everybody,
I'm trying to implement a timer on FX3 to measure the length of time for which an input pin (button) stays low. I want to configure the GPIO pin of the button as a Complex Gpio.
I tought that the best option for me would be to configure the pin mode as:
gpioComplexConfig.pinMode = CY_U3P_GPIO_MODE_MEASURE_LOW;
However, this way I am not able to understand where could I see the time measured, as "CyU3PGpioComplexSampleNow" can be used ONLY with CY_U3P_GPIO_MODE_STATIC.
Does anyone have any suggestion? Thanks
Solved! Go to Solution.
- Labels:
-
USB Superspeed Peripherals
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello,
If CY_U3P_GPIO_MODE_MEASURE_LOW mode is used, CyU3PGpioComplexGetThreshold API can be used to get the threshold value. This function reads the current threshold value associated with a complex GPIO. This function is used in the various MEASURE modes of the GPIO to get the measured pulse/signal duration.
Please let me know if this helps.
Rashi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello,
If CY_U3P_GPIO_MODE_MEASURE_LOW mode is used, CyU3PGpioComplexGetThreshold API can be used to get the threshold value. This function reads the current threshold value associated with a complex GPIO. This function is used in the various MEASURE modes of the GPIO to get the measured pulse/signal duration.
Please let me know if this helps.
Rashi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks Rashi!
So far I am having some troubles. I'll try to explain what Ive done:
I set the GPIO input corresponding to a button as a ComplexGPIO. I've called this as TIMER_GPIO, as I'd like to measure the time of the button press. This is what i've done:
CyU3PReturnStatus_t GPIO_TIMER_setup(void) //timer per quando sta basso
{
CyU3PReturnStatus_t apiRetStatus = CY_U3P_SUCCESS;
CyU3PGpioComplexConfig_t gpioComplexConfig;
apiRetStatus = CyU3PDeviceGpioOverride (GPIO_TIMER, CyFalse); //GPIO of the button
if (apiRetStatus != CY_U3P_SUCCESS)
{
CyU3PDebugPrint (4, "\r\nCyU3PDeviceGpioOverride failed for GPIO_TIMER, error code = %d", apiRetStatus);
return apiRetStatus;
}
gpioComplexConfig.outValue = CyFalse;
gpioComplexConfig.inputEn = CyTrue;
gpioComplexConfig.driveLowEn = CyFalse;
gpioComplexConfig.driveHighEn = CyFalse;
gpioComplexConfig.pinMode = CY_U3P_GPIO_MODE_MEASURE_LOW;
gpioComplexConfig.intrMode = CY_U3P_GPIO_INTR_POS_EDGE;
gpioComplexConfig.timerMode = CY_U3P_GPIO_TIMER_HIGH_FREQ;
gpioComplexConfig.timer = 0; // valore iniziale
gpioComplexConfig.period =100000000000;
gpioComplexConfig.threshold = 0;
apiRetStatus = CyU3PGpioSetComplexConfig(GPIO_TIMER, &gpioComplexConfig);
if (apiRetStatus != CY_U3P_SUCCESS)
{
CyU3PDebugPrint (4, "\r\nCyU3PGpioSetComplexConfig failed, error code = %d",apiRetStatus);
return apiRetStatus;
}
return apiRetStatus;
}
When the interrupt is called, I make a flag go high. In the common thread this flag high calls CyU3PGpioComplexGetThreshold API.
Problem is I get the error: " CyU3PGpioSetComplexConfig failed, error code = 68ERROR"
Why do I get the error? Is my method wrong?
Thanks!!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello,
Please call CyU3PDeviceGpioOverride(GPIO_TIMER, CyFalse) before calling CyU3PGpioSetComplexConfig and let me know if the error is seen
Rashi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
it works! I have two other questions:
1) The interrupt is called everytime i push AND release the button (so both on negative and positive edge). Is it correct? Why does it happen?
2) I'd like to measure the button press, so in the order or microseconds or seconds. Is it possible using Fast or Simple GPIO Clock? How can I make the conversion between ticks and microseconds?
Thanks a lot for your precious help!
Linda
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello,
The interrupt is called everytime i push AND release the button (so both on negative and positive edge). Is it correct? Why does it happen?
>> Please let me know which interrupt are you referring to
I'd like to measure the button press, so in the order or microseconds or seconds. Is it possible using Fast or Simple GPIO Clock? How can I make the conversion between ticks and microseconds?
>> Yes, Fast and simple clock can be configured for getting appropriate delay as mentioned in this KBA https://community.cypress.com/t5/Knowledge-Base-Articles/How-to-Get-a-0-1-%C2%B5s-Unit-Timestamp-wit...
Rashi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
the interrupt on the GPIO of the button, on which I set the timer. When I set "gpioComplexConfig.intrMode = CY_U3P_GPIO_INTR_POS_EDGE;" I expected the interrupt to happen only on the positive edge, while it happens also on the negative one. Why does it happen?
Another question: would it be possible to call CyU3PGpioComplexGetThreshold and to have a continuos update of the value ? Like to have, every instant, the incrementing value of how much time the the pin stays low. Now in fact I only get the value once the pin goes high.
Thanks a lot, you're being very helpful!!!
Best,
Linda
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello Linda,
I expected the interrupt to happen only on the positive edge, while it happens also on the negative one. Why does it happen?
>> Please let me know if you probed and checked the GPIO. There are chances of glitch due to button press on the GPIO which might lead to multiple interrupts
Another question: would it be possible to call CyU3PGpioComplexGetThreshold and to have a continuos update of the value ? Like to have, every instant, the incrementing value of how much time the the pin stays low. Now in fact I only get the value once the pin goes high.
>> Do you mean that you want to sample the low time value of the GPIO also? If yes, can you please try enabling both modes
gpioConfig.pinMode = CY_U3P_GPIO_MODE_MEASURE_LOW | CY_U3P_GPIO_MODE_MEASURE_HIGH;
Rashi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Rashi,
Please let me know if you probed and checked the GPIO. There are chances of glitch due to button press on the GPIO which might lead to multiple interrupts
>> This problem has been solved, I did configure the GPIO twice by mistake ! Now eveythink works fine!!
Do you mean that you want to sample the low time value of the GPIO also?
>> Not exactly. I'd like to sample the timer while the pin is still low (i.e. I don't want to wait for the positive edge to be able to access the timer value with CyU3PGpioComplexGetThreshold ). Is it possible ?
Thanks a lot,
Linda
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello Linda,
>> This problem has been solved, I did configure the GPIO twice by mistake ! Now eveythink works fine!!
>> Glad to hear that the problem is resolved.
I'd like to sample the timer while the pin is still low (i.e. I don't want to wait for the positive edge to be able to access the timer value with CyU3PGpioComplexGetThreshold ). Is it possible ?
>> Yes, you call this API outside the GPIO callback (i.e. when interrupt for positive edge is triggered)
Rashi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Rashi,
sorry for the late reply.
Yes, you call this API outside the GPIO callback (i.e. when interrupt for positive edge is triggered)
>> I managed to do that by setting the gpioComplexConfig.pinMode = CY_U3P_GPIO_MODE_STATIC and calling CyU3PGpioComplexSampleNow.
Another question: I'd like to reset the timer every time there is an interrupt. How can I do that?
Thanks a lot,
Linda
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Linda,
Which timer is being referred to here?
Best regards,
AliAsgar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi AliAsgar,
I'm asking referring to the timer set like this:
gpioComplexConfig.outValue = CyFalse;
gpioComplexConfig.inputEn = CyTrue;
gpioComplexConfig.driveLowEn = CyFalse;
gpioComplexConfig.driveHighEn = CyFalse;
gpioComplexConfig.pinMode = CY_U3P_GPIO_MODE_STATIC;
gpioComplexConfig.intrMode = CY_U3P_GPIO_INTR_BOTH_EDGE;
gpioComplexConfig.timerMode = CY_U3P_GPIO_TIMER_LOW_FREQ;
gpioComplexConfig.timer = 0;
gpioComplexConfig.period = 4000000000;
gpioComplexConfig.threshold = 0;
Thanks,
Linda
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Linda,
Reconfiguring the complex GPIO will reset the timer.
Call the CyU3PSetComplexConfig(..) API to reset the timer. Make sure that the CyU3PGpioComplexConfig_t structure is made global.
Best Regards,
AliAsgar