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!!
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 but this example drives led using pwm and my problem is that i want to drive vibration motor using pwm waveform.so how to define gpio pins ?how to generate pwm waveform on gpio pins?can you explain me in detail how to interface vibration motor to nrf51822?
If you need PWM on 2 GPIO pins, use APP_PWM_DEFAULT_CONFIG_2CH(). If you need PWM on 1 GPIO pin, use APP_PWM_DEFAULT_CONFIG_1CH().
The first argument is the period in microseconds, and second argument is the GPIO pin you want to use.
In the PWM library example we have this:
app_pwm_config_t pwm1_cfg = APP_PWM_DEFAULT_CONFIG_2CH(5000L, BSP_LED_0, BSP_LED_1);
So you can just remove the BSP_LED_0and BSP_LED_1, and replace it with the GPIO pin number you want to use.
Thanks for your reply i have replaced the BSP_LED_0and BSP_LED_1 with gpio pins 5 and 6 and i connected pin 6 to pwm input of vibration motor.but my vibration motor is not running .the gpio pins give me pwm voltage between 0 to 2.9v.how to increases pwm output voltage? how to change the period and duty cycle in this program? what are the changes i have to make in my program?
You can change the duty cycle with the function app_pwm_channel_duty_set, i.e to set it to 50% duty on PWM channel 0:
while (app_pwm_channel_duty_set(&PWM1, 0, 50) == NRF_ERROR_BUSY);
To increase the voltage, you will need a higher voltage soruce, and use e.g. a transistor to amplify the PWM signal.