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

Hello world simple program to drive DC Motor

Hi

I'm working on a project to drive a DC motor, I really didn't find any example. I would like to know how can I program a pin in Keil, and I would be happy to have a simple example about it.

By the way Im using NRF51 DK.

Bests,

  • Examples and description are in the SDK, download it and look inside for the docs, then the examples. SDK something like: [your path]/nrf51_sdk_v6_1_0_b2ec2e6/Documentation/s110/html/index.html

    Something like the Blinky or PWM examples may help for Motors.

    Another option is to look at "mbed", I'm only just getting into this, but I believe the new nRF51-DK supports mbed nicely. The mbed supports debug printf through the USB serial without interferring with BLE.

    Paul

  • Hey, as Paul says, the Blinky and PWM examples in the SDK are good starting points. You can also have a look at this: github.com/.../nrf51-pwm-library

  • Hey Guys Thank you for your helps but one remaining issue about blinky example is that, it use a pre-defined functions to configure leds pin.

    I really need a simple example which goes directly to gpio.h and shows how to work with this library

  • nrf_gpio.h defines functions like nrf_gpio_pin_set() so you don't have to write directly to the registers. The blinky example shows how to use this library. Isn't that what you wanted?

    You write: "I really need a simple example which goes directly to gpio.h and shows how to work with this library". That is exactly what the blinky example does.

    If you want to go lower than that, you can have a look into nrf_gpio.h and see how the functions write to the registers on the chip. For example NRF_GPIO->OUT = 0xFF writes 1 to all pins. To see which registers you can write to and what they do, go to the nRF51 Reference Manual section 13.2

  • Thank you for your comment. As an example if I want to describe for you,

        enter code here
        #ifndef F_CPU
    #define F_CPU 8000000UL // 16MHz clock speed
    #endif
    
    #include <avr/io.h>
    #include <util/delay.h>
    
    int main(void)
    {
      DDRC = 0xFF; //PORTB as Output
      while(1)
      {
        //Rotates Motor in Antilockwise
        PORTC = 0x01; //00000001
        _delay_ms(4000);
    
        //Stops Motor
        PORTC = 0x00; //00000000
        _delay_ms(4000);
    
        //Rotates Motor in Clockwise
        PORTC = 0x02; //00000010
        _delay_ms(4000);
    
        //Stops Motor
        PORTC = 0x03; //00000011
        _delay_ms(4000);
      }
    }
    

    this is a simple example which gives me an idea how to control a port on microcontroller directly.My question is that whetehr such a simple senario is available?

Related