Looking for suggestion for 100hz Pulse generating to GPIO on BCM20732S?

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
Anonymous
Not applicable

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.

0 Likes
1 Solution

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.

View solution in original post

4 Replies
Anonymous
Not applicable

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?

0 Likes

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.

Anonymous
Not applicable

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?

0 Likes

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.

0 Likes