Like Tree1Likes
  • 1 Post By Salem

How to write programs for PWM in C ?

This is a discussion on How to write programs for PWM in C ? within the C Programming forums, part of the General Programming Boards category; Hi, I am new to this C/C++, and would like to know how to write a simple program code using ...

  1. #1
    Registered User
    Join Date
    Oct 2012
    Posts
    5

    How to write programs for PWM in C ?

    Hi, I am new to this C/C++, and would like to know how to write a simple program code using C/C++ from analog output to PWM for a motor.
    Thank you..

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,490
    First of all, which operating system and compiler are you using?

    If you're using some kind of development board like an STK500, then we need links to relevant documentation.

    Regardless of whatever CPU you're using, you need some kind of circuitry between the processor and the motor, to amplify the logic signals to a level that will drive a motor.
    Some power PWM drivers for electric DC motors
    PWM - Pulse Width Modulation for DC Motor Speed and LED Brightness, Page 5 - Robot Room

    What are you interested in controlling - speed or power?
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    TEIAM - problem solved
    Join Date
    Apr 2012
    Location
    Melbourne Australia
    Posts
    1,343
    What are you using?
    Fact - Beethoven wrote his first symphony in C

  4. #4
    Registered User
    Join Date
    Oct 2012
    Posts
    5
    I am using National Instrument to a PMA Series DC Servo Actuators.
    I need to control the direction of the motor. More interested in the duty cycle.

  5. #5
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,490
    Do you have URL's for that?
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  6. #6
    Registered User
    Join Date
    Oct 2012
    Posts
    5
    Quote Originally Posted by Salem View Post
    Do you have URL's for that?
    National Instrument -- NI CB-68LP - Unshielded 68-Pin I/O Connector Block - National Instruments
    Actuator -- http://www.harmonicdrive.de/cms/uplo...ma-300-317.pdf

    Hope this help (:

  7. #7
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,490
    I must be missing something, because the NI CB-68LP is a data acquisition board, where things are primarily low power inputs.

    To drive a motor, you need outputs, and more power.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  8. #8
    Registered User
    Join Date
    Oct 2012
    Posts
    5
    Quote Originally Posted by Salem View Post
    I must be missing something, because the NI CB-68LP is a data acquisition board, where things are primarily low power inputs.

    To drive a motor, you need outputs, and more power.
    with a servo amplifier ( maxon motor : 145391 ) to the motor

    http://www.farnell.com/datasheets/484756.pdf

  9. #9
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,490
    And how is all that lot wired up?

    PC -> NI CB-68LP -> maxon motor : 145391 -> PMA 300

    How is the PC plugged into the I/O connector block?
    - Parallel Port / USB port?

    Did it come with any library files / DLL files / example programs (see their website)

    Which operating system and compiler are you using?
    Note that "TurboC" on any kind of windows OS means you need to upgrade your compiler.

    How much experience of C/C++ programming do you have in general (on your desktop machine).
    How much experience of programming external devices (such as this).

    If this is your first experience of programming real hardware, then I would suggest you start out with
    PC -> NI CB-68LP -> LED
    just to get familiar with the first step, and just making a light go on and off.
    Once you've mastered say "on for 2 seconds, off for 1 second" in a loop, then you'll be well-placed for adding the rest of the components.

    I know it's a lot of questions, but programming bespoke hardware is full of very fine detail. Even the smallest mistake or omission can result in it not working and having no idea where to look.
    stahta01 likes this.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. how to write programs in pelles c??
    By Abhas in forum C Programming
    Replies: 13
    Last Post: 04-11-2011, 12:32 AM
  2. Reroute where programs write to
    By willc0de4food in forum C Programming
    Replies: 7
    Last Post: 09-21-2005, 04:48 PM
  3. Possible to write adaptive programs?
    By crag2804 in forum A Brief History of Cprogramming.com
    Replies: 4
    Last Post: 06-16-2003, 04:35 PM
  4. Write to another programs edit box
    By Zahl in forum Windows Programming
    Replies: 2
    Last Post: 11-16-2002, 05:55 AM
  5. how to read and write from two different programs
    By Unregistered in forum C Programming
    Replies: 3
    Last Post: 07-18-2002, 11:38 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21