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,Sigurd i know i understand this example but i dint want to use configured pwm example and i am just generating pwm using a simple for loop.i have problem with initialization of gpio pins .i want to connect led to gpio pin and i want set that led high for 10 ms and low for 20 ms so how should i write a code for that how to declare gpio pins: i have done this in my program but dint get any desired output :this is my code

    int main(void)
    {
    #include pin_number 1
    int main(){
    
    nrf_gpio_cfg_output(pin_number1);
    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);
    	}
    

    what are the changes i have to make i am using pin no. 5 to connect to led what should i do?what are the initialization and functions header files that i need to include in my program? please give a demo code for this really helpful to me if you can!

Reply
  • Thanks,Sigurd i know i understand this example but i dint want to use configured pwm example and i am just generating pwm using a simple for loop.i have problem with initialization of gpio pins .i want to connect led to gpio pin and i want set that led high for 10 ms and low for 20 ms so how should i write a code for that how to declare gpio pins: i have done this in my program but dint get any desired output :this is my code

    int main(void)
    {
    #include pin_number 1
    int main(){
    
    nrf_gpio_cfg_output(pin_number1);
    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);
    	}
    

    what are the changes i have to make i am using pin no. 5 to connect to led what should i do?what are the initialization and functions header files that i need to include in my program? please give a demo code for this really helpful to me if you can!

Children
No Data
Related