Hi all,
I am working on a project which uses a vibration motor. I want the vibration motor to vibrate with different patterns. I have read online that a 20kHz PWM can be used to control the vibration power by varying the duty cycle.
I am using the PWM driver example from the SDK as a reference and sort of understand how it works, but please correct me if my understanding is wrong.
The PWM frequency is set by Fclk/ .top value and the duty cycle is set by the seq_values array. For example if .base_clock is NRF_PWM_CLK_125kHz and .top_value is 25000, then the PWM frequency is 5Hz. If I use the seq_values:
static uint16_t /*const*/ seq_values[] = { 0x8000, 0, 0x8000, 0, 0x8000, 0 };
This means the I will have duty cycle of 32% for the first clock period (200ms) then 0% for the next clock cycle (200ms) , and this repeats 3 times.
In my application, I want to have the motor PWM at 20kHz ramping up from 0% duty cycle to 100% duty cycle over a period of 2 seconds, then off for 2 seconds and repeat again.
To get 20kHz PWM frequency, I would need to set .base_clock NRF_PWM_CLK_1MHz and .top_value to 50. If I want to ramp up from 0% duty cycle to 100% duty cycle over a period of 2 seconds, does it mean that I would need a seq_values array with 40000 elements? But somehow it seems like its not the right way to do it. Is there a better way to do this?
Another vibration pattern I am looking at is ON at 75% for 1 sec, OFF(1 sec) and repeat.
Any one can advise? Thanks!