Connect with us

programming about motor..

Discussion in 'Microcontrollers, Programming and IoT' started by ikram1991, Jul 9, 2013.

  1. ikram1991

    ikram1991

    43
    0
    May 5, 2013
    Hi guys,
    Anyone can help about my project to control motor.
    I wan make my motor running few second and then stop automatically.
    Anyone can help me with the sample source code?
    Thx.
     
  2. KrisBlueNZ

    KrisBlueNZ Sadly passed away in 2015

    8,393
    1,266
    Nov 28, 2011
    What microcontroller are you using?
    Google the relevant words. There are many tutorials and project plans out there that will tell you how to do this.
    Also, look in the forums for the microcontroller you want to use.
     
  3. Harald Kapp

    Harald Kapp Moderator Moderator

    9,137
    1,846
    Nov 17, 2011
    Judging from his previous posts it is probably a PIC.

    You need a timer to set the interval (time) plus an amplifier (transistor stage) to drive the motor (the PIC's probably much too weak to drive the motor directly). Connect the amplifier to an output pin. At the start of the interval, set the output pin to active to start the motor. Also set the timer to the desired interval and start it. When the timer has finished reset the output pin to stop the motor.

    Any more detal will require you to post a schematic and reveal a few more details about your circuit.

    And follow Kris' advice on looking for tutorials.
     
  4. ikram1991

    ikram1991

    43
    0
    May 5, 2013
    i'm using pic16F877A
     
  5. ikram1991

    ikram1991

    43
    0
    May 5, 2013
    Actually i'm not connect the motor directly. I'm using relay circuit. but, i doesnt have any idea to program it like i mention in the first post.
     
  6. p.erasmus

    p.erasmus

    60
    0
    Jul 18, 2013
    Well you can go to this site and find examples to run motors in C,pacal or Basic language unless you intend to use assembly language
    http://www.mikroe.com/forum/
     
    Last edited: Jul 18, 2013
  7. CDRIVE

    CDRIVE Hauling 10' pipe on a Trek Shift3

    4,960
    648
    May 8, 2012
    If running and stopping a single motor is all you're going to do then that chip is way overkill. If you're new to uC's and programming I highly recommend Picaxe. Their 08M2 (8 pin DIP) will drive your relay coil to control your motor. The language follows Basic syntax and is fully documented in free .pdf files. The programming editor is also free!

    http://www.picaxe.com/


    Hello Peter and welcome to EP!

    Mates, I met Peter on the Tina forum and asked him to join us. He joined immediately, without any arm twisting. Let's give him a big welcome? He's quite bright and a quick study!

    Chris
     
  8. p.erasmus

    p.erasmus

    60
    0
    Jul 18, 2013
    Hallo Eveybody !
    Thank you Cris ,I am happy to be here,learn and help were I can :)

    Peter
     
  9. Frank3point14

    Frank3point14

    10
    0
    Sep 6, 2013
    void main() {

    short duty = 0;

    TRISD = 0b11111111;
    TRISC = 0b00000000;
    TRISB = 0b00000000;
    PORTB = 0b00000010;

    PWM1_Init(1000);
    PWM1_Start();
    PWM1_Set_Duty(duty);
    while (1)
    {
    if (!RD0_bit && duty<250)
    {
    Delay_ms(40);
    duty = duty+10;
    PWm1_Set_Duty(duty);

    }

    if (!RD1_bit && duty >0)
    {
    Delay_ms(40);
    duty = duty-10;
    PWM1_Set_Duty(duty);

    }
    Delay_ms(10);
    }

    }




    Use this code and i'm using PIC16F877
     
  10. CDRIVE

    CDRIVE Hauling 10' pipe on a Trek Shift3

    4,960
    648
    May 8, 2012
    It's been about two months (prior to your post) since ikram1991 replied. ikram1991 only asked to run a motor for a few seconds. This simple (Picaxe Basic) code will run a motor for 3 seconds after a switch is pressed and released. If the switch remains closed the motor will run continuously. He only needs a relay or SD driver to do this.

    Chris

    Code:
    'Author: CDRIVE
    'Chipset: Picaxe 08M2 (8 pin DIP)
    
    
    Start:
    	If Pin1=1 Then  ' If switch is closed
    	     High 2       'make pin 2 High
    	     Wait 3     'Energize Relay for 3 seconds
    	End if	
    	If Pin1=0 Then	
    	     Low 2        'make pin 2 Low
    	End If
    GoTo Start
    
     
  11. ikram1991

    ikram1991

    43
    0
    May 5, 2013
    Wowww..thx guys..that's help me a lot to learn how to program motor! :)
     
Ask a Question
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.
Electronics Point Logo
Continue to site
Quote of the day

-