Help with GPIO and Bluetooth

Hello everyone,
hope someone can help me with my issue.

I have one MetaWearRG device and have a special use case for it.
I need to send on 1 GPIO pin every 20ms a signal of high voltage for 1-2ms (ms = millisecond) and then turn it off for 20ms and so on in an endless loop...

I have tried to implement the use case in two ways:
1. Bluetooth commands
Send command every 20ms via Bluetooth to set the high voltage signal for 1-2ms and loop until turned off.
image
As you can view from the image, every 1 out of 3 signal is incorrect. Is Bluetooth to slow for this?

2. Internal timer
Send the internal timer a command to set the GPIO signals as on timers on and off. The device becomes unstable and unresponsive for more then 5 minutes... and I'm afraid of using this way, because the whole system become unstable.

I have an issue with the timer not being consistent enough either way :(
Am I doing something wrong? What is the right way?
Hope someone can point me in the right direction.

Thanks!
Tine

Comments

  • Hi @Tine

    Great detail on what you have tried.

    In the first case, yes, the bluetooth link is a little too slow.  Bluetooth LE uses a low duty cycle communication scheme -- it has a short conversation every so often.  Depending on your platform, that conversation will be every 20 ms or 37.5ms at the fastest setting.  Multiple words can be exchanged during each conversation, up to 4 or 6 depending on your platform.

    In your pulses that are working as expected, the "Set 1" and "Set 0" commands are succeeding within one of those conversations -- the BLE "connection interval".  On the erroneous pulses, the commands are likely split between intervals, so your signal stays in the "1" state for a connection interval.

    With some optimization, you may be able to get more consistent results.

    How accurate does your pulse generator need to be?  How much variation can you tolerate in the high and low times?

    In the second case, if you are using separate timers they may be getting similarly out of sync.  For consistency, my suggestion would be to use two timers, one for the 20ms period, and one for the 1-2ms high time. So something like this:

    20 ms Timer (repeat forever)
    -> "Set 1"
    -> Start 1-2 ms Timer (one shot)
    -> "Set 0"

    In the future, we could provide a fixed delay command for micro second delays, which could enable short pulses with a flow like:
    "Set 1"
    "Delay 50 us"
    "Set 0"

    The MetaWear timer may vary by 1-4 ms when it is interrupted by the radio.  To achieve sub 1-5% accuracy we would need to devise a pulse generator using hardware timers.  This is something we could provide in the future by adapting the buzzer driver, which generates a stable 4kHz square wave in hardware.

This discussion has been closed.