int main(void) { uint32_t counter = 0; nrf_pwm_config_t pwm_config = PWM_DEFAULT_CONFIG; pwm_config.mode = PWM_MODE_LED_255; pwm_config.num_channels = 4; pwm_config.gpio_num[0] = LED_1; pwm_config.gpio_num[1] = LED_2; pwm_config.gpio_num[2] = LED_4; pwm_config.gpio_num[3] = LED_3; // Initialize the PWM library nrf_pwm_init(&pwm_config); while (true) { // Update the 3 outputs with out of phase sine waves nrf_pwm_set_value(0, sin_table[counter]); nrf_pwm_set_value(1, sin_table[(counter + 25) % 100]); nrf_pwm_set_value(2, sin_table[(counter + 50) % 100]); nrf_pwm_set_value(3, sin_table[(counter + 75) % 100]); counter = (counter + 1) % 100; // Add a delay to control the speed of the sine wave nrf_delay_us(8000); } }
void ADC_IRQHandler(void) { // Clear the END event NRF_ADC->EVENTS_END = 0; // Read the ADC result, and update the PWM channels accordingly uint8_t tmp = NRF_ADC->RESULT; nrf_pwm_set_value(0, tmp); nrf_pwm_set_value(1, 255 - tmp); // Trigger a new ADC sampling NRF_ADC->TASKS_START = 1; }
void SetFanSpeed(uint8_t duty_cycle) //Changing the duty-cycle of motor when the fan is openning { nrf_pwm_set_value(0,duty_cycle); }