This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

how to define gpio pins and generate pwm on gpio pins?

Hi There, i am new to nrf51822 and new to program this kind of controller.I searched over the website, I couldn't find a good introductory documentation for programming the nrf51822, specifically the nrf51-dk. i have two problems 1.i want to connect a led and buzzer to gpio pins of nrf51822 so how to declare gpio pins in program for ex. suppose if i press button on nrf board the buzzer connected to gpio pins (for (ex. p0.0) should be on (make some sound). 2.i want to generate a pwm on gpio pin (for ex on p0.1) how to declare this pin as output for pwm how to use functions to declare gpio,led and other stuff as i gone through the tutorial it is not well defined and the tutorials are very much confused and easy to understandable can anybody give me the good explnation about this a good tutorial with each and every line explained will be great help!! Regards, Abhijeet Kapse

Parents
  • Hi,

    As an introduction, I would recommend the Getting Started guide and our examples in the SDK. For PWM generation on the nRF51, you should take a look at the PWM library example. You can find the example in the folder: <SDK_InstallFolder>\examples\peripheral\pwm_library

  • Thanks man, your code is working but now i want to run my vibration motor using a ir sensor.This is my code

    int main(void)
    {
        adc_config();
    
        uart_config();
    		nrf_gpio_cfg_output(pin_number1);
    
        printf("\n\rADC HAL simple example\r\n");
    
        printf("Current sample value:\r\n");
    
        while (true)
        {
    			  // trigger next ADC conversion
    			  nrf_adc_start();
            // enter into sleep mode
            __SEV();
            __WFE();
            __WFE();
    			
    			  nrf_delay_ms(100);	
    				printf("%d\r\n", (int)adc_sample); // out ADC result
    		
    			if(adc_sample<20)
    			{
    			
       // while(true){
       //  for(int i=0;i<=20;i++){
        nrf_gpio_pin_set(pin_number1);
        nrf_delay_ms(10);
        nrf_gpio_pin_clear(pin_number1);
        nrf_delay_ms(20);
     // }
    }
        }
    
    	}
    #endif /* NRF51 */
     //@} 
    

    My ir sensor gives me values between (14 to 255)as i configured it at 8 bit resolution.i want run my vibration motor whenever i am getting ir sensor values below 20.and my vibration motor should stop when my sensor giving values above 20.but in my main code after reaching value 20 my motor is just running and code get stuck and sensor does not giving me the values what are the changes i have to make in my code to get desired output.

Reply
  • Thanks man, your code is working but now i want to run my vibration motor using a ir sensor.This is my code

    int main(void)
    {
        adc_config();
    
        uart_config();
    		nrf_gpio_cfg_output(pin_number1);
    
        printf("\n\rADC HAL simple example\r\n");
    
        printf("Current sample value:\r\n");
    
        while (true)
        {
    			  // trigger next ADC conversion
    			  nrf_adc_start();
            // enter into sleep mode
            __SEV();
            __WFE();
            __WFE();
    			
    			  nrf_delay_ms(100);	
    				printf("%d\r\n", (int)adc_sample); // out ADC result
    		
    			if(adc_sample<20)
    			{
    			
       // while(true){
       //  for(int i=0;i<=20;i++){
        nrf_gpio_pin_set(pin_number1);
        nrf_delay_ms(10);
        nrf_gpio_pin_clear(pin_number1);
        nrf_delay_ms(20);
     // }
    }
        }
    
    	}
    #endif /* NRF51 */
     //@} 
    

    My ir sensor gives me values between (14 to 255)as i configured it at 8 bit resolution.i want run my vibration motor whenever i am getting ir sensor values below 20.and my vibration motor should stop when my sensor giving values above 20.but in my main code after reaching value 20 my motor is just running and code get stuck and sensor does not giving me the values what are the changes i have to make in my code to get desired output.

Children
No Data
Related