Hi all,
I would like to control a stepper motor over BLE. The motor takes STEP(rising edge) inputs for each step. The motor move is based on pre-calculated look up tables for achieving accurate motor profile.
For example, in my use case is that I have to run 8 pulse with 0.00133s time period then the next 10 pulses with 0.00126s time period and so on untill the motor can attain the max rpm at 0.000667s timeperiod.
Basically I should be able to change the base frequency after n pulses untill the motor attain the maximum speed and then keep on that constant timeperiod.
I implemented the same using the "waveform mode" in the PWM driver to achieve this and seems to be working.
NRF52832
NRFDK - s132 - sdk 17
The sample code is given below. This will continue to execute the number of pulses as per the given time period in the two arrays.
static int sequence_count = 0;
// demo PWM time period in uS.
static int time_period_array[] ={600,700,800,900,1000,1100};
// demo PWM pulse repeat count.
static int pulse_count_array[] ={1,2,3,4,5,6};
static nrf_pwm_values_wave_form_t pwm_seq_values;
static nrf_pwm_sequence_t const wave_seq =
{
.values.p_wave_form = &pwm_seq_values,
.length = NRF_PWM_VALUES_LENGTH(pwm_seq_values),
.repeats = 0,
.end_delay = 0
};
/*
*@brief Function will change the pwm time period
*T pwm = T pwm_clk * countertop value.
*
*T pwm_clk = 1/500 ms = 2 uS . Hence countertop = value/2
*
*/
static void change_pwm_freq (uint16_t value)
{
uint16_t counter_top_value = value/2;
pwm_seq_values.channel_0 = counter_top_value/2; // 50 percent duty cycle
pwm_seq_values.counter_top = counter_top_value;
}
1. Is this an efficient method to achieve the purpose or are there any other more efficient method to do this by reducing processor interference so that we can achieve realtime control of motor without any apparent delays?
2. We are planning to integrate PWM and the central + peripheral example of sdk 17.0.2. I also wanted to know if there will be any delay in excecuting the pwm event handler when there will be a ble event which needs to be processed, and the things that we need to consider while designing BLE handlers so as to minimze the delay.
NOTE: while the motor is moving, both central and peripheral connection events need to be handled.
3. Any further comments on the scenario is also appreciated.
regards,
Vinu