Exemple #1
0
int main(void)
{
    nrf_pwm_config_t pwm_config = PWM_DEFAULT_CONFIG;
    
    pwm_config.mode             = PWM_MODE_LED_255;
    pwm_config.num_channels     = 2;
    pwm_config.gpio_num[0]      = 8;
    pwm_config.gpio_num[1]      = 9;  

    // Initialize the PWM library
    nrf_pwm_init(&pwm_config);

    // Configure the ADC
    // P0.1 is used for ADC input, apply a varying voltage between 0 and VDD to change the PWM values
    NRF_ADC->CONFIG = ADC_CONFIG_RES_8bit << ADC_CONFIG_RES_Pos | ADC_CONFIG_INPSEL_AnalogInputOneThirdPrescaling << ADC_CONFIG_INPSEL_Pos |
                          ADC_CONFIG_REFSEL_SupplyOneThirdPrescaling << ADC_CONFIG_REFSEL_Pos | ADC_CONFIG_PSEL_AnalogInput2 << ADC_CONFIG_PSEL_Pos;
    NRF_ADC->ENABLE = 1;  
    NRF_ADC->INTENSET = ADC_INTENSET_END_Msk;
    
    // Enable the ADC interrupt, and set the priority to 1
    NVIC_SetPriority(ADC_IRQn, 1);
    NVIC_EnableIRQ(ADC_IRQn);   

    // Start the ADC
    NRF_ADC->TASKS_START = 1;
    
    while (true)
    {
    }
}
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);
    }
}
Exemple #3
0
void InitFan(void)													//Initaling the fan
{
	GpioConfig(FAN_POWER_CONTROL_PIN,OUTPUT);
	GpioConfig(FAN_PWM_PIN,OUTPUT);
	
	//Seting the PWM Output for controling the motor
	nrf_pwm_config_t pwm_config = PWM_DEFAULT_CONFIG;						
	pwm_config.mode             = PWM_MODE_MTR_100;							// 0-100 resolution, 20 kHz PWM frequency, 4MHz timer frequency (prescaler 2)
  pwm_config.num_channels     = 1;														//Just one Channel
  pwm_config.gpio_num[0]      = FAN_PWM_PIN;
	nrf_pwm_init(&pwm_config); 																	// Initialize the PWM library
	
	OpenFan(60);														//60-duty-cycle  as default
}