Robots, et al.

Building robots, hacking electronics.

Motor Controller Mini-workshop – Applying PWM for Speed Control

leave a comment

Last Tuesday we had a mini workshop on controlling DC brushed motors using an Arduino.  We covered controlling the speed and direction of a DC motor (in both directions) using an H-bridge. Some important take-aways from this are:

  • The motor cannot be connected directly to the Arduino, motors typically require more current and voltage.  The ATmega328 (the chip inside the Arduino) can handle a maximum of 40mA of current.  Motors (even small ones) pull 100mA to 10′s or 100A.  If this much current was pulled from the processor it would likely blow up the output port.
  • Approximated to the first order, the speed of a motor is porportional to the voltage applied to the motor.
    • This is a very first-order approximation, the speed will change when a load is applied to the resistance drops in the drive circuitry and the motor.
  • Approximated to the first order, the load on the motor (how hard it is pushing against a load), is proportional to the current through the motor.
  • In order to change the voltage on the motor, a voltage is switched on/off quickly at a certian duty cycle (on some of the time, off the other).  This is known as PWM (pulse-width modulation)
  • On an arduino, the PWM functions are called using the functions “analogWrite”

Example code from the class is:

 void setup() {                
   // initialize the digital pin as an output.
   pinMode(3, OUTPUT);
   pinMode(5, OUTPUT);  
 // the loop routine runs over and over again forever:
 void loop() {
   digitalWrite(3, LOW);   // turn the LED on (HIGH is the voltage level)
   analogWrite(5, 200);
   delay(5000);               // wait for a second
   digitalWrite(5, LOW);    // turn the LED off by making the voltage LOW
   analogWrite(3, 200);
   delay(5000);               // wait for a second

PDF Presentation: Controlling_DC_Brushed_Motors_Using_Arduino

Schematic of the circuit we breadboarded: Motor_workshop_1_Schemtic

Note: This post is cross-posted on the Interlock Rochester Blog

Written by Alex Sojda

October 30th, 2013 at 2:37 am

Posted in Uncategorized

TI App Note: AN-2020 Correction

leave a comment

TI App Note: AN-2020 Thermal Design By Insight, Not Hindsight is a really good app note to help calculate thermal impedances and estimating heat sinking required on a circuit board.

Page 4 (table 1) contains an error in its calculation of the thermal impedance of a 12-mil via.  The problem is the calculation uses the finished plating hole thickness as the outer radius, since this is the finished thickness it should be the inner radius.  This changes the via thermal impedance from 261 C/W to 239 C/W.  Equation (3) should be:

\theta_{via}=\frac{0.25\frac{^{\circ}C cm}{W}*0.165cm}{\pi*((0.01524cm + 0.00175cm)^2+(0.01524 cm)^2}

Just thought I’d tell the world, I hate errors in app notes.

Written by Alex Sojda

May 10th, 2013 at 7:00 pm

Posted in App Note,Electroncs

I’d like to dedicate this code to Ratatat

leave a comment

I’ve been doing more embedded coding lately and need music that’s up-beat, with no vocals.  My latest pick is the album LP4 I can listen to this album for 8-hours straight on repeat – AMAZING.

I especially like the random clips they add to the songs like a German clip before ‘drugs’ or the clip at the end of ‘Party with Children’:

I’ve been thinkin’ what to do with my future, I could be a mud doctor checkin’ out the earth underneath.


Written by Alex Sojda

August 18th, 2012 at 3:37 pm

Posted in Code

Adding Constant-current Buzzer to Lab Power Supply

leave a comment

I’ve been a fan of the relativly cheap power supplies sold at MPJA.  In the past I’ve been used to the larger supplies that will trip relays when over-currenting the supply and that is usually enough to get my attention.   The newer solid state supplies are much lighter and don’t have any relays in them.  I have not yet blown up any circuits, but prememptivly I decided to add a constant-current buzzer.

Overall, these are nice supplies.  We got a few at work and other then the fan being loud on one of them we have no complaints.

I knew that the signal to show whether these supplies were in contant-voltage or contstant-current mode was being sent to the low-voltage LCD display so I started probing around in the connector between the power board and the LCD board.

The white connector on the bottom of the board connects to the actual high-power regulator board.  I discovered that pin 4 (or two if you count from the other side), carries a signal that is 12V when in constant-voltage mode, and 0V when in constant-current mode.

The plan:  use buzzer, turn it on when constant current mode is enabled.  First I tried just connecting the buzzer between the signal line and 12V.  This didn’t work and the LCD got very cranky – must be this line is not as low-impedance as I hoped, time for plan B:

I needed a way to drive an active-low signal without having to drive 74xx logic or anything.  The solution: P-type Mosfet.  When the gate is at 12V (Vgs = 0V), the FET is off, and therefore the buzzer is off.  When the gate is low, Vgs = 12V, the P-FET turns on and the buzzer is on.  The great thing about using MOSFETs instead of BJTs is that there is no gate current when the circuit is not switching (I don’t anticipate this thing jumping in and out of constant-current mode, that means I need to turn the currrent limit up).

I wired in a TO-92 leaded PMOS, connecting R2 to the gate, C3 (12V) to the source, and connected ground on the buzzer to the ground on the backlight for the LCD.  This seems to be working great and doesn’t seem to be too loud once it’s in the enclosure.

Written by Alex Sojda

March 9th, 2012 at 3:40 am

Posted in Analog,Electroncs

Kickstarter: Open Spectrometer

leave a comment

The guys at MakerHaus and I are getting together to make an Open Spectrometer.  We just kicked off our Kickstarter and I’ll be posting the status of the hardware on here and the Open Spectrometer website.

So far I have roughed out code on the F28069 and I should have a block diagram up soon.  The code is being hosted on GitHub.

Long-term plan is to use a slightly more user-friendly architecture, I just got in my LM4F232 Evaluation Kit, and hopefully alpha prototypes will be a daughtercard for that dev kit.

Written by Alex Sojda

October 20th, 2011 at 12:13 am

Posted in diyBio,Electroncs

whirr, the most awesome quadcopter EVER

leave a comment

Over the past month or so I’ve been devising a quadcopter.  What I’ve come up with is pretty much the same as every other vanilla-quadcopter.  I decided that I don’t want to use ESCs to control the motors – I’m going to do sensorless field-oriented control (FOC) using a F28069 controlStick.

I’m hoping that using FOC control is going to improve the efficiency of the motors.  I’m not entirely sure about this, but I doubt efficiency is the main concern of the cost-down RC speed controllers.

The main reason I’m doing this is because it’s a awesome engineering challenge.  Who doesn’t want to do 4-motor sensorless FOC control with an an awesome DSP.

So far the progress I’ve made on this is to layout a 3-phase H-bridge board with low-side current sense.  I submitted it to batchPCB and the boards came back.  So far I am able to power them and not draw any current (when the gate drives are disabled).  I’m hoping to get some preliminary firmware going to get at least one motor spinning in the next week or two.


Front side of board


Backside of the board


Written by Alex Sojda

October 15th, 2011 at 5:42 pm

Motor simulation tools

leave a comment

This is really awesome Finite Element Method Magnetics – I’ll have to check this out soon.

Written by Alex Sojda

October 14th, 2011 at 5:02 pm

Posted in BLDC

Open Source Hardware and Maker Faire

leave a comment

This weekend I attended the Open Source Hardware Summit.  It was great getting to meet all the people who’s blogs I read and hardware I look at (and sometimes buy).  One talk that especially inspired me was Amanda Wozniak’s talk on Open Sourcing the Engineering Process, this encouraged me to finally start a blog and document all the engineering I do for fun.

It was great to have lunch with Jeff from Mighty Ohm, and seeing a talk on manufacturing with Ian from Dangerous Prototypes and Eric from Seeed Studio.

I also was inspired by Geoffrey Barrows talk to order one of the optical flow sensors from Centeye.  I’ll be sure to post when I get them in.

Written by Alex Sojda

September 20th, 2011 at 3:25 am

Posted in Uncategorized