Arduino motor control shield

Is there anything that can’t be done with the right Arduino shield?

Adafruit makes a nice motor control shield that can control up to four DC motors or two stepper motors, as well as two servos. Since it uses L293D H-bridge drivers, it can use an external supply of up to 36V to drive the motors — and can pass up to 1A per motor. For higher-power loads, some heatsinking may be needed, but the board handles a pair of 12V, 100 ohm unipolar stepper motors nicely. The board can use all of the standard stepper motor drive modes (single-pole, double-pole, interleaved, and microstepping) — and drive modes and speeds can be switched on the fly.

The Adafruit motor control shield driving a pair of unipolar stepper motors. (Click for larger.)

The board comes as a kit, but since it is well-thought-out, uses all through-hole components, and has excellent assembly instructions available online, it’s straightforward enough to assemble. I wouldn’t recommend it as a first soldering project, but if you have a decent temperature-controlled soldering iron and can solder DIP16 components, you should be OK.

Like nearly everything Arduino, the board doesn’t ship with drivers or instructions — but it does have the support URL silkscreened onto the board. Since the drivers and assembly instructions have probably been refined since the board was made, this is a good thing; you automatically get the latest version of the drivers and instructions. Costs are also kept down, since there’s no need to include a CD-R for a few hundred k of files.

The software side of things is very straightforward, too. Copy the provided driver library into the Arduino Libraries folder, and with an include statement and a few lines of code, you’re up and running. (The provided examples are a great starting point.)

Overall, the board is great. I can definitely see ordering more of these as projects warrant. About the only improvement I can think of would be to include proper extensible Arduino header pins, to allow other shields to be stacked above this one. (This would require some layout changes, though, since more pins would have to be carried through.)

Posted in Arduino, C, Coding, Digital, Electronics, Reviews, Robotics | 1 Comment

An open letter to Senator Casey (and other SOPA/PIPA supporters)

The Honorable Robert P. Casey, Jr.
393 Russell Senate Office Building
Washington, D.C. 20510

Dear Senator Casey:

Although I have generally been not only a constituent but a supporter of yours, it was with some concern that I read about your support of the so-called “Protect IP Act“, or “PIPA” (S. 968) legislation, currently being reviewed in committee. While efforts to reduce IP content piracy can indeed be useful, S. 968 (as well as its counterpart in the House, H.R. 3261: “SOPA“), are dangerously broad in scope — and furthermore, would not even be effective at their stated goals of reducing online piracy.

Specifically, sir, such bills will restrict the activities of legal, productive websites far more than they will restrict the activities of online pirates. Although I am not an expert on the mechanics of BitTorrent, TOR, and similar technologies, even I can think of a half-dozen effective methods to counteract DNS filtering and so-called “deep packet inspection.” This technology will not do what it is claimed — pirates have been circumventing filters like this for years — but such restrictions will have very harmful side effects on legal, useful sites such as Wikipedia and YouTube.

Such invasive activities as S.968 proposes will, as many Internet advocates have noted, have a “chilling effect” on the majority of legal, online content. When even politically neutral sites such as Wikipedia deem the issue important enough to warrant a 24-hour blackout of the English language edition of the site, it becomes apparent that this is an important issue with the potential to cause great harm to the fundamental freedoms the Internet affords.

Senator, the open Internet is a unique, precious resource — in exactly the way Gutenberg’s invention of the movable-type press was. The freedom of expression and unimpeded exchange of information that it provides are vital to not only freedom, but the intellectual economy of the modern world.

I strongly urge you to withdraw your support of this bill, and pledge to vote against it should it come up for consideration by the full Senate or any committee on which you serve.

Respectfully yours,
M. Eric Carr
Philadelphia, PA
eric@paleotechnologist.net

 

Posted in Current Events, Digital, Digital Citizenship | Leave a comment

Made by Monkeys

Sometimes, humor can be an effective way of making a point about bad design choices. Products which fail — often spectacularly — due to poor design can still lead to better engineering practices, if they inspire a discussion about what went wrong and how to fix it.

Design News’ “Made by Monkeys” column is a good read, and is often informative. It’s a good exercise in engineering ethics to read through the articles and conclude what made each particular design “Made by Monkeys.” Often, cost is the driving factor: a few cents saved by cutting corners here and there doesn’t keep the design from working immediately, but causes problems down the road.

Here are a few especially good articles that I’ve come across:

Enjoy — and remember, sometimes the monkeys have valuable lessons to teach!

 

Posted in Design | Leave a comment

FPGAs for microcontroller geeks

If you’re like me, you’ve heard a lot about FPGAs and how useful they can be in a design. Perhaps you’ve read a bit about them, learning what they are and a bit about how they work. If your background (like mine) is in microcontroller-based design, though, getting started in working with FPGAs is not necessarily intuitive. Here are some of my thoughts and experiences as I begin working with FPGA-centric design.

Although FPGAs can often be a viable alternative to a microcontroller or microprocessor in a given embedded project, they are radically different devices. Microcontrollers are CPUs with various built-in peripherals and onboard memory, whereas FPGAs are collections of various logic units that are configured to perform certain (often very complex) functions. Programming a microcontroller involves writing a program to tell it how to behave. Programming (really, configuring) an FPGA involves creating a configuration file (a “bitstream”) that sets up the configuration of the FPGA to do the intended tasks.

In short, you tell a microcontroller what to do; you tell an FPGA what to be.

The traditional “Hello, World!” project for embedded systems is typically a blinking LED. Even as simple a project as this illustrates the difference in approach when using an FPGA as opposed to a microcontroller. When writing a “blinker” program for a microcontroller, the code would generally look something like this (using PIC-like C code):

void main(){
   TRISB = 0xFE;
   while(1){
      PORTB = 0x01;
      delay_ms(500);
      PORTB = 0x00;
      delay_ms(500);
      }
   }

This code would blink an LED connected to PORTB.0 on and off at a rate of 1Hz. The microcontroller would follow each command in sequence and change the LED state appropriately.

Conversely, when implementing a blinking-LED project with an FPGA, the general approach is to implement a digital circuit (using virtual gates, flip-flops, registers, counters, multiplexers, etc) to perform the same function. One strategy is to decide how you would implement the circuit using discrete (74xx, for example) digital logic, and then implement this design in either schematic form or your HDL design language of choice. (VHDL and Verilog are the two dominant languages; the following example is in VHDL):

entity blinker is
   Port (clk : in STD_LOGIC;
   led : out STD_LOGIC);
   end blinker;

architecture Behavioral of blinker is
   signal count : std_logic_vector(23 downto 0);
   begin
   process (clk) is
      begin
      if rising_edge(clk) then
         count <= count + 1;
         end if;
      end process;
   led <= count(23);
   end Behavioral;

This code describes a 24-bit counter which increments on each rising edge of the input clock. The LED is tied to the 24th bit of the counter; this divides the clock by 224 (about 16.7 million). The end result is that the LED blinks once every 224 clock cycles. With a 16MHz input clock, the LED should blink at a rate of not quite once per second.

This is a very simple example, taking up less than 1% of the resources of even small FPGA devices like the Xilinx Spartan3 series. By combining “entity” descriptions like these, though, larger, more complex designs can be implemented. As with C-style programming for CPUs, modularity makes development of larger and more complex designs possible. A top-down approach can be taken, for example, describing the inputs and outputs of the system as a whole, then breaking the internal function down into subsystems, circuits, and finally gates (Boolean expressions, etc.)

Although working with FPGAs can be unintuitive for designers used to working with procedurally-oriented devices like MCUs, there are many benefits. FPGAs can be much faster at certain tasks, since the device configuration can be optimized for specific operations. Efficient pipelines can be set up, for instance, to keep streams of data flowing. Most significantly, FPGAs are inherently massively parallel: rather than relying on a single CPU core processing a sequence of instructions one after the other, FPGAs are essentially a “sea of [logic] gates” that can work together or independently. Extending the above example, for instance, several dozen LEDs could be configured to each blink at a different rate, by duplicating the blinker design at various places in the FPGA, and modifying the count for each.

The largest drawbacks to working with FPGAs I’ve found, so far, is that they tend to be more expensive (tens of dollars for an entry-level FPGA like the Spartan3, as opposed to under $5 for a typical 8-bit MCU; really big FPGAs can be stupendously expensive), and more importantly are trickier to implement into a typical DIY project, since they tend to be available in QFN and similar packaging instead of the more hobbyist-friendly DIP format. Fortunately, modern dev boards like Digilent’s BASYS2 and Gadget Factory’s Papilio make prototyping easier.

Here are a few books that I’ve found to be useful. I’m starting out with an emphasis on VHDL and Xilinx Spartan3 parts, so the books I’m using tend to have those biases:

FPGA Prototyping By VHDL Examples

 

This is the primary book I’ve been using while getting started in FPGA projects in general and VHDL in particular. It is a step-by-step explanation of the important concepts in writing VHDL code, with a particular emphasis on Spartan3 FPGAs. Since both of the dev boards I use (Gadget Factory’s Papilio and Digilent’s BASYS2) use Spartan3 chips, this book has pretty much been a one-stop shop, thus far. If I were creating an undergraduate-level course in FPGA-based design, I would use this as the textbook, with the other two as recommended supplemental texts.

HDL Chip Design

 

Part textbook and part “HDL cookbook” containing all kinds of HDL designs in both VHDL and Verilog. It doesn’t strike me as the best book for starting out, but looks very useful as both a reference and a good way to learn more advanced techniques. I picked up a copy on Jeri Ellsworth’s recommendation. It’s not cheap (and can be hard to find), but looks to be well worth the money.

A VHDL Primer

 

This is a good introduction and overview of the concepts and syntax of VHDL. It is a bit more theoretical than the other two books, but does a good job of covering the language, and can be used as a language textbook and/or a VHDL desk reference.

I am working on a few FPGA-based projects, which I will post here when complete. My eventual goal is to develop standalone FPGA-based devices.

Posted in C, Coding, Digital, EET205, FPGAs, VHDL | Tagged , , , , , | Leave a comment