- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I'm trying to generate 100 hz pulse with fixed duty cycle. I found there may have two methods:
1. write in main while loop and use a delay function as follows:
gpio_setPinOutput(0, GPIO_PIN_LED, GPIO_PIN_OUTPUT_LOW);
delay(300); //microsecond
gpio_setPinOutput(0, GPIO_PIN_LED, GPIO_PIN_OUTPUT_HIGH);
delay(9700); //microsecond
I don't find there's a delay() function in SDK. would someone find any similiar function that can support to microsecond delay?
2. use PWM pin, configure clock to 100 hz, then set duty cycle.
Appricate any suggestion.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
See void bleapputils_delayUs(UINT32 delay) in bleapputils.h, where parameter delay is in microseconds you want to delay. Note that this is a busy wait (spinning in a loop). If the device takes an interrupt while in this loop, then it may run longer than delay microseconds. Make sure that this is not over a few milliseconds (thumb rule is ~10mS; use timers for longer delays). PWM is really the best option.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I try to generate 100 hz PWM and set duty cycle, that is working.
Unfortunitly, the device need to check the signal on specific point, so method 1 may be the right way.
Would someone know how to make a short delay of microseconds?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
See void bleapputils_delayUs(UINT32 delay) in bleapputils.h, where parameter delay is in microseconds you want to delay. Note that this is a busy wait (spinning in a loop). If the device takes an interrupt while in this loop, then it may run longer than delay microseconds. Make sure that this is not over a few milliseconds (thumb rule is ~10mS; use timers for longer delays). PWM is really the best option.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
When I set the scenarios with program as follows:
gpio_setPinOutput to GPIO_PIN_OUTPUT_HIGH
bleapputils_delayUs(300);
adc_readVoltage read adc pin value
gpio_setPinOutput to GPIO_PIN_OUTPUT_LOW
then I found on OSC, the duration of the pulse is always around 600 us.
Is that additional delay caused by ADC function? and how to estimate the ADC delay?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Move bleapputils_delayUs(300); outside your GPIO toggle. That is the ADC sampling delay, which includes turning on the ADC, sampling the input and turning off the ADC.