Shop OBEX P1 Docs P2 Docs Learn Events
can someone tell me if an arduino can do this level of motor control and multitasking — Parallax Forums

can someone tell me if an arduino can do this level of motor control and multitasking

rwgast_logicdesignrwgast_logicdesign Posts: 1,464
edited 2012-11-21 14:08 in General Discussion
so im planning to have my bot obviously mainely use a prop but ive been looking at arduino code and man is it super easy peasy kinda like the rad of microcontrollers, im sure picaxe is the same but i have atmega chips around and can easily program the arduino bootloader on them.

so this is what im thinking, im gonna throw an atmega168 on a piece of protoboard with a l293e. i want to use the atmega/arduino to be controlled via serial, this way i can interface to it via prop or terminal (for quick testing). I want the avr to be able to set speed and direction of two motors independentaley, i also want it to run pedetermined run left, right, forward, backward, and drive at angles like 45 degrees, using a pid loop based off the wheel encoders. the other point of the the arduino is monitor voltage and current on the motors and correct stalls, and then flip a boost regulator when the battery voltage goes low and i need more power. the motors need ever go over 18v 1.3amps.

so i guess what im really getting at is #1 is there any functionality found in commercial motor control boards that im missing and should add. #2 is the amount of multitasking im talking about, uart, dual pwm, reading encoders for a pid, and voltage/current feedback whithin the realm of an arduino using an 8mhz internal oscillator or even a 16mhz crystal? its just a cheaper more compact solution than a propeller, and i want the motor control done on a different mcu than all the robots brain work.if it is how do i pick resistors for the voltage divider and current shunt? the other reason i dont want to use a prop here is becuase i have a feeling id need an adc to do this as sigma delta and dip props dont mix well

Comments

  • pjvpjv Posts: 1,903
    edited 2012-11-17 12:48
    rwgast......

    I believe that what you describe, including an A/D (sigma delta) function can readily be done inside a single propeller; no extra chips required, just some power transistors.

    But you will need to do the programming, and hence will benefit by learning how to implement multitasking.

    Not so much "easy peasy", but a TON of fun.

    Cheers,

    Peter (pjv)
  • rwgast_logicdesignrwgast_logicdesign Posts: 1,464
    edited 2012-11-17 13:12
    Im not really sure if this is the answer I was looking for, like I said I dont want to use a propeller for the motor control, its a waste of silicon on top of being a physically big chip. I dont want to dedicate a cog of the bots brain to the motors either for various reasons one just being a simple physical location issue, I have a feeling betwwen wii cams, lasers, mems sensors and pings Im gonna need all the free cogs I can get in the brain. Basically the brain prop should say oh theres an object in 6 inches send turn left to the arduino which is generating a PWM in a PID loop already, thats the extent of the props motor control.

    If an arduino is not up to this task im looking at the dip format arm chip with the basic compiler that erco posted, the thing with arduino is have plenty of atmegas on hand and plenty of recourse from books to pre written librarys for the h bridge
  • Martin_HMartin_H Posts: 4,051
    edited 2012-11-17 14:12
    It sounds like you want to build your own serial motor controller using an Arduino, and yes it should be fine for that. Google Wulfden dorkboard for a compact and cheap freeduino. At around ten bucks it's cheap and low risk.
  • rwgast_logicdesignrwgast_logicdesign Posts: 1,464
    edited 2012-11-17 14:30
    ohh i already have an rbbk or something to prototype with its a tinny bread board module with a 328.. pretty nice kit, my only quam is the programmer pin placement.

    i have some blank avr i keep around but no xtals or feedback caps. id planned to just program the arduino bootloader on a 168 and us the internal 8mhz oscillator, if it will be fast enough for me, mostly to save space and do less soldering. then i was gonna hook up the l293 and a boost boost regulator, along with whatever resistors to divide voltage and shunt current, call it a day. i originally wanted to do this with a bs2 but found out a single pwm would lock the whole module leaving no room for any other tasks, so thats why im leary of just soldering an arduino into my motor control, i want to make sure its capable of doing all this stuff at once, and id like to just get the hardware out of the way.

    i would be very grateful if you could tell me the best way to do the analog pin work. i dont want the voltage divider or current shunt using to much power, as im thinking of cutting my system from 18 to 16v anyways.. i know the voltage divider should be in the k ohms region, but as far as a current shunt idk what the best way to do this is, i was thinking 1ohm resistor but ive read some stuff that confused me more, i should probably just go to the duino forums but i figured someone here would probably know
  • tingotingo Posts: 87
    edited 2012-11-17 14:53
    They use AVR's as the brains of a QuadCopter: ArduCopter. Wikipedia on ArduCopter, Ardupilot. http://store.diydrones.com/product_p/br-ardupilot-01.htm
    So yes, Arduino and AVRs can do what you want.
  • NWCCTVNWCCTV Posts: 3,629
    edited 2012-11-17 18:05
    ohh i already have an rbbk or something to prototype with its a tinny bread board module with a 328.. pretty nice kit[/QUOTE

    HMM, Why does this sound familiar????
  • Martin_HMartin_H Posts: 4,051
    edited 2012-11-17 19:08
    Use a breadboard and some jumpers to test the whole circuit, then solder it together. That way you'll know it will work before you commit.
  • LoopyBytelooseLoopyByteloose Posts: 12,537
    edited 2012-11-17 22:41
    Im not really sure if this is the answer I was looking for, like I said I dont want to use a propeller for the motor control, its a waste of silicon on top of being a physically big chip. I dont want to dedicate a cog of the bots brain to the motors either for various reasons one just being a simple physical location issue, I have a feeling betwwen wii cams, lasers, mems sensors and pings Im gonna need all the free cogs I can get in the brain. Basically the brain prop should say oh theres an object in 6 inches send turn left to the arduino which is generating a PWM in a PID loop already, thats the extent of the props motor control.

    If an arduino is not up to this task im looking at the dip format arm chip with the basic compiler that erco posted, the thing with arduino is have plenty of atmegas on hand and plenty of recourse from books to pre written librarys for the h bridge

    I suspect an Arduino can do it, but so might a PIC or even a BasicStamp.

    If it is all about using AVR or ATmega stuff you have on hand and needing support about their ADC, go to.....them, AVRfreaks or whatever.

    You might use a tiny Propeller packaged chip - there are the Propeller Proto Board, the SchmartBoard Propeller board, and a lot of other very compact Propeller formats that are both cost effective and smaller - even a Propeller that supports Arduino shields.

    If it is about space, it doesn't mean that you have to abandon a Propeller. You may just have to abandon DIP packaging.

    And then there is AmForth on the ATmega chips. Where do you want go is about what do you want to learn.

    A double Propeller board might be the best fit.

    I do understand that we all buy stuff out of curiosity and then feel that we should use it, but if it isn't a Parallax product - you aren't not really in the right place to ask for informed support.
  • LeonLeon Posts: 7,620
    edited 2012-11-17 23:02
    Microchip specialises in motor control applications:

    http://www.microchip.com/pagehandler/en-us/technology/motorcontrol/
  • LoopyBytelooseLoopyByteloose Posts: 12,537
    edited 2012-11-17 23:53
    The main point here is that it is up to you as the designer to create a complete inventory of your requirements and then to decide on the hardware to get the job done.

    Working backwards from what you have on hand, is simply working backwards. It may or may not get the job done. And you may have to buy more to make it work than having a direct approach. Nobody knows as your design process is rahter hidden.

    I like to use ADCs and I really don't like to construct them in software on the Propellera or any other chip. I am eagerly looking forward to Propeller 2 as I have always been attracted to chips that included ADC and possibly included RTCs as well.

    If you want to know why I don't like to construct ADCs on the Propeller, the few parts that are required have to be placed extremely close to the i/o pins and I am not sure I can consistently build these correctly. So, I'd much rather use a PIC or an AVR or an ATmega with built-in ADC or use a real ADC chip with the Propeller.

    OBEX has objects for using ADC chips with the Propeller. If you have doubts that 8 cogs is enough, maybe 16 cogs and an ADC chip will be comfortable.

    These days, I am beginning to think that I need two Propellers for just about everything new that I want to do. I guess that once you learn the Propeller, this is a reality. So look for or build a two Propeller system - either with two EEPROMs or with one being a EEPROMless Propeller and some other way to load software.
  • rwgast_logicdesignrwgast_logicdesign Posts: 1,464
    edited 2012-11-18 02:47
    like i said originally the propeller doesnt fit here its a waste of silicon, a prop could do this all in one cog most likely. as i mentioned above i had already hoped to do this with a bs2 but it cant be done, a singal pwm signal uses 100% of the bs2s resources. not using an arduino based chip i was afraid it may have the same issue, thats why i asked hoping someone knew the answer which they did. an ardunio turened out perfect, i made a two chip in dip format solution micro/hbridge, then watched a few you tube tutorials and have written half the motor code already becuade the arduino also served well as being about as simple as a bs2 which was another requirement. still plenty of power to spare if i decide to use it as a nimh chargeing solution too.

    as i said above i knew a prop could handel this but i wanted to keep my prop free of motor code so it could focus on more exotic things, and i learned a new platform in a few hours including interupts it was a win win :). using a second prop for this task would have also meant i would have needed an adc too most likely so not only am i not wasting power and silcon on an overkill chip but i only used 48 pins of space instead of around 70. granted leons solution may be the best and ill look into it, although im not sure i wanna change my design after the work put in.
  • rwgast_logicdesignrwgast_logicdesign Posts: 1,464
    edited 2012-11-18 02:53
    i think the slickest part of my solution isnt even creating a nice serial motor driver but if i want to do something really determenistic i can reprogram the avr using the propeller if my robot needs to change something about the motor control in an unforseen event, its kina like having 9 cogs instead of 8 ones just physically 6 inches away.
  • RobotWorkshopRobotWorkshop Posts: 2,307
    edited 2012-11-19 13:52
    Just use a 2nd Propeller chip. Have it do the motor control functions including reading the quadrature encoders. It can act as the intelligent motor controller and also perform a few other functions. If you want to use some servos then use one of the servo objects in another COG. That way it will handle all the motor control functions. It is not a waste to use the propeller at all for this task. One thing you gain is that you only need a single development environment for both of your controllers. That isn't a small thing. Needlessly complicating things by having multiple development tools doesn't make sense unless there is a good reason to do it.

    A few of my robots have a couple Propeller chips on board. I just embed a small/cheap USB HUB and with that I can download new code to either one.

    For my larger projects that would have a PC or Raspberry Pi for the highest level control then that same USB link can be used to send serial commands to each one and receive data.

    If you're just running with only propeller boards then just use a couple I/O pins on each one so they can directly talk to each other.
  • rwgast_logicdesignrwgast_logicdesign Posts: 1,464
    edited 2012-11-21 13:48
    Im pretty invested in this arduino project already but a propeller may have been the better choice in the end, it looks like im going to most likely having to do a battery charger from scratch too which i didnt expect. But whats really bugging me is the arduino cant generate the PWM signal I was hoping for. Im not super prop code wise yet but if I switch this out to a propeller can use a counter and two pins to generate a 100khz PWM signal, if so what would be the max resolution From what ive been told on the arduino forums to do a phase correct pwm, the highest I can get is 31khz with a resolution of 75 steps.. I was looking at doing a high frequency 100khz signal with maybe 1000 steps or so. This is arduinos max with an external crystal which i didnt want to use.
  • RobotWorkshopRobotWorkshop Posts: 2,307
    edited 2012-11-21 14:08
    Why did you pick 100Khz as the frequency for your motor controller? Is there a reason you need to go that high? You may want to do some bench testing first and see how everything works.

    If you want to learn more about motor control you may want to join the OSMC group on Yahoo. They have years of experience designing motor controllers and when you start getting into higher frequency control there are other issues like inductance of the motor you may have to start dealing with that may not be a factor at a lower frequency. Some links to review are:

    http://www.seattlerobotics.org/encoder/200011/pwm.html

    http://www.electro-tech-online.com/robotics-mechatronics/19246-suitable-pwm-frequency-motor-control.html

    http://forums.parallax.com/showthread.php?131700-Best-Frequency-for-PWM-DC-motors

    http://www.avrfreaks.net/index.php?name=PNphpBB2&file=printview&t=52972&start=0

    http://inst.eecs.berkeley.edu/~ee40/calbot/pdf/ChapterFive/ChapterFive.pdf

    http://en.wikipedia.org/wiki/Pulse-width_modulation

    http://ww1.microchip.com/downloads/en/appnotes/00893a.pdf
Sign In or Register to comment.