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.

start and stop scanning triggered by external PWM

Other Parts Discussed in Thread: CC2540

Hello,

I have a cc2540 device, powered by a pwm-signal with varying pause times, which is continuously scanning. There are some back-up capacitors on the board, but I still have to conserve some power to keep it running through longer pause times. For this I want to stop my device from scanning on each falling edge and let it start on each rising edge again if the pause time is longer than 2 ms. the pwm-frequency lies between 70 Hz and 300 Hz.

I have an interrupt which is triggered by the external pwm. I found I can't start and stop scanning directly from the interrupt routine. I tried to set an event, but the delay for the execution of the event-handler was often bigger than 1 ms which is too slow. So I wonder if there is any faster way to start and stop scanning accurately. Especially the stopping needs to be accurate.

I set the scan -window and -interval to 4 ms each. I need to have my device scan as continuously as possible.

Any idea?

Thanks in advance and please tell me if you need any further information.

Robin

  • Hi Robin,

    If you set the scan window equal to the scan interval, it should scan continuously without having to interface to external PWM. Then when you get the GAP_DEVICE_DISCOVERY_EVENT signaling the end of the scan duration, you can set an event to restart scanning.

    Best wishes
  • Hi Zahid,
    this is exactly what I do when the pausetime of the PWM is shorter than 2 ms and until then it's working alright.
    If the pause gets longer than that, I have to stop scanning for the time of the pause to prevent the system from restarting because of power-loss. I am still searching for a way to achieve that.
    So I have an interrupt triggered by each falling and rising edge of the external PWM from which I set an event.
    I've tried two things:
    1. Call
    "GAPObserverRole_CancelDiscovery();" on every falling edge and
    "GAPObserverRole_StartDiscovery( ... );" on every rising edge but that does not seem to work well.

    2. Start scanning on each rising edge for the time, that the pwm-level will be high. For this I set an event on each rising edge and measure the pausetime and the period of the external pwm and the time between the "osal_set_event(...)" and the execution of the eventhandler. The variable "scanTime" is
    period-(pauseTime+ eventToExecutionTime)

    eventHandler:

        (...)
        GAPObserverRole_CancelDiscovery();  //Make sure scanning is stopped
        GAP_SetParamValue( TGAP_GEN_DISC_SCAN, scanTime ); //Set scan duration to be as long as the "on"-phase
        GAPObserverRole_StartDiscovery( DEFAULT_DISCOVERY_MODE, //start scanning for the time of the "on"-phase
        DEFAULT_DISCOVERY_ACTIVE_SCAN,
        DEFAULT_DISCOVERY_WHITE_LIST );
        (...)


    I don't know how long it takes to actually start scanning or if there is a lower limit of scan-duration but I thought that might be a problem.
    For example:
    70 Hz PWM with 80% duty cycle.
    14.3 ms period
    11.4 ms On
    1-4 ms from rising edge to execution of the event handler.
    means I'd want to restart scanning every 14.3 ms and set the scan duration between
    (11.4ms - 1ms = )10.4 ms and (11.4 ms - 4 ms = )7.4 ms
    And this is the lowest frequency I have to face.
    do you think that this can work?

    Edit:

    I found that TGAP_GEN_DISC_SCAN is described as "Minimum time to perform scanning" but I'd need it to be the point where the scanning definitely stops.

    So I thought that instead of setting TGAP_GEN_DISC_SCAN maybe it could work to reset scan -window and -interval in the following way on each rising edge:

    eventHandler:

    (...)

    GAPObserverRole_CancelDiscovery(); //Make sure scanning is stopped
    GAP_SetParamValue( TGAP_GEN_DISC_SCAN_INT, 400); //something bigger than PWM-period
    GAP_SetParamValue( TGAP_GEN_DISC_SCAN_WIND,scanTime);  //Set scan window to be as long as the "on"-phase
    GAPObserverRole_StartDiscovery( DEFAULT_DISCOVERY_MODE,
    DEFAULT_DISCOVERY_ACTIVE_SCAN,
    DEFAULT_DISCOVERY_WHITE_LIST );

    Can I be sure that the scan window will always be at the beginning of a scan interval?

  • So I guess that's alot of questions at once. 

    I'll try  to put the infos I need in a few sentences:

    1. what's the minimum value for scan interval and scan window?

    In the BT core document it says 0x11 for the window and 0x12 for the interval, but in my code the lowest I can set is 0x04. So is the scan interval then really 4*0.0625 ms = 2.5 ms?

    2.  is the lowest value I can set for scan duration the same as the lowest value for scan interval?

    3. is the scan window always at the beginning of an interval?

    4. how much time does it typically take from the call of GAPObserverRole_StartDiscovery(...) and the actual start of the scanning proccess.

    5. Same question for GAPObserverRole_CancelDiscovery(...)

    thanks

  • Hi,
    See answers below. Fewer is always better :)
    1. The scanWindow and scanInterval should be between 2.5 msec to 10.24 seconds. Also the scanWindow shall be less than or equal to the scanInterval.
    2. The Scan Duration is independent of the scanInterval and scanWindow.
    3. Yes, the scan interval, scanInterval, is
    defined as the interval between the start of two consecutive scan windows.
    4&5. We have have not characterized this. You could toggle a GPIO when you call GAPObserverRole_StartDiscovery() and GAPObserverRole_CancelDiscovery() and then look at the scope to see when it scans on the same time scale.

    Best wishes
  • thanks for the answers, I'll try to measure the time it takes to start and stop scanning the next days and inform you about the results.