Detecting Taps with an Accelerometer: Disco Bike Light part 4

Tap Control of the Disco Bike Light

In last week’s blog I talked about looking into using an accelerometer output as a user interface for the Disco Bike Light design.  This week I took the next step of actually implementing a method of detecting taps with an accelerometer and using them as an on-off signal.

For a quick refresher, the Disco Bike Light is a design where I’ve decided to replace the guts of a Schwinn bike light with my own electronics. I wanted more color and more brightness.  I put some constraints on myself for the design.  One was that I couldn’t destroy the existing bike light in the process of making my new one.  For on/off/color control I was left with few options…

[Read more…]

Accelerometer as User Input Signal: Disco Bike Light Part 3

dbl_all_layers

Welcome to another edition of “Disco Bike Light: adventures in electronic design”.  In last week’s blog I talked a little about the printed-circuit-board (PCB) design and the Lithium battery charging circuit.  This week I’ll touch more on the circuit board, and a little bit on the user interface.

[Read more…]

Charging a Single Cell Li-Po Battery–Disco Bike Light Part 2

dbl_charger_only

In last week’s exciting episode of “Disco Bike Light” I covered some of the issues I had with this electronic design.  In summary, I’ve decided to convert my bike light to a multi-color kaleidoscope of mobile joy.
[Read more…]

Disco Bike Light–Part 1

disco_bike_light

I’ve been working with some high power LEDs around here.  I also ride my bike to work.  The cheap bike lights I’ve owned kind of suck. In fact, some barely illuminate the road.  And none of them flash groovy colors.  Last week I bought a $20 Schwinn light (pictured above).  I really like the shape of the light, and although it is an improvement over my last lamp, it’s still pretty tame in the light production department.  So I’ve decided to pump up the lumens, taste the Technicolor rainbow, and build a disco bike light.  And if I use the Schwinn body I can avoid some of the mechanical design effort.

The Schwinn bike light breaks down into several pieces.  The main body is the black tube where I’ll need to fit my electronics.  Normally it carries three AAA batteries (shown on the left).  I’ve added a AA battery for size comparison, because that ends up mattering later on.  There’s also a screw-in base that has the on/off/flasher circuit in it.  It’s the part with the spring attached that presses against the negative terminal of the battery pack.  This part is a little strange.  It operates without the battery pack and provides an open, short, or 500ohm resistance from the case to spring (ground).  I’m guessing there’s a microcontroller embedded in there, but I swore not to take it apart (I’ll need that light in the coming weeks).  The last piece of the light is the aluminum LED holder.  It’s a thin threaded inset that connects the single white LED to the positive battery terminal.

I want to use the same parts we have on our BM014 Super Bright RGB LED Module, because, well we have them in stock.  I also want to be able to program color and brightness settings, so that means a microcontroller and user interface.  I’ll also have to replace the 3-AAA batteries with something else.  1-AA Lithium Ion battery would provide a similar voltage, and give me some extra room for circuitry.

The first step in this design is realizing that I’ll need to fit the Lithium Ion battery, a circuit board, and USB connector into the main body of the light and onto a PCB (for charging and communicating with the microcontroller on board).

I turned to Sketchup 8 to do some simple modeling.  If I mount the USB connector directly under the rear battery mount everything works well.  To do this I would have to clip and sand the through-hole tabs on the battery mount (PN: BK-92-ND at Digi-Key).  If there’s no room for it anywhere else I can go that route.   The image below shows what I’m going on about.

disco_bike_light_2

The circuit board that fits inside the tube is pretty big, I calculate it at 0.725”x2.0”.  So I think I’ll have room to move the USB connector.  On the top side of the circuit board will be the battery mounts.  On the other will be the USB-to-serial converter, a Lithium Ion charging circuit, and an LED drive circuit.  I can rotate the USB connector and get it to fit further in from the battery clips.  I would also have to notch the circuit board so a USB cable will fit into the USB connector.  Maybe I can find some surface mount battery tabs?

disco_bike_light_3

Lastly, since the housing of the bike light is conductive, I’ll have to make sure the battery terminals can’t touch the sides of the enclosure.  That’s tricky, but I have some ideas about how to do it with the PCB.  I’ll discuss that in the next blog on this topic.

Phase Drive a DC Motor

Phase_Drive_HBRIDGE

During the design of various motor control systems I’ve run into a few ICs that allow for a peculiar drive method.  I’ve seen it referred to as phase drive and direction drive.  I’ve never implemented it in a product that’s been produced, but lately I have decided to give it a shot.  The traditional method I’ve used for driving a DC motor in a closed-loop application is, simply stated, to drive it forward or reverse.  At a direction change the drive signal is typically small.  This is particularly true if you implement step limits on the PWM signals change from update-to-update.  Doing it this way reduces inductive voltage spikes from high speed reversals, saving your circuit from from death and destruction.

[Read more…]

Measuring small currents with an oscilloscope

When designing systems with microcontrollers, it is often necessary to make them low power and to ensure they draw minimal current.  Unfortunately, common desktop instruments do not allow for easy verification of these currents.  A DMM can really only show DC currents and can’t capture transients.  An oscilloscope typically can only measure down on the order of 2mV per division range.  These limitations pose a problem for microcontroller systems that typically have to wake up periodically to check things and then go back to sleep:  the current waveform is too active for the DMM to measure and too small for the oscilloscope to resolve.  A simple and obvious method around this is to amplify the current measurement so that a scope can reliably show the current waveform.  This blog entry describes one, easy-to-implement method for accomplishing this.

The figure below shows the schematic for the amplification circuit using an instrumentation amplifier.  A brief description of the circuit follows. 

current sense amplifier.

  • The instrumentation amplifier is the Linear Technologies LT1920. This is a basic instrumentation amp (IA) that comes in a DIP package so it is easy to prototype and even breadboard with. It is readily available from Digi Key.
  • The gain of the circuit is set to 1000. With the expected minimum current of the DUT(on the order of 100uA) and a gain of 1000, the output will be about 100mV. This is an easy voltage to see with a scope. In addition the maximum current is about 5mA, so a gain of 1000 gives an output voltage about 5V. Again, this is easy to see with a scope.
  • The gain bandwidth product of the IA is large enough to show the transitions of the circuit.
  • The circuit is run off of +-10V so there is enough headroom to output the approximate +5V output. Dual supplies are necessary because the minimum allowed voltage input is V- + 1.5V.
  • The 10k provides a load so that output of the IA has a return path.
  • Pin 5 is tied to ground so that the output is referenced to ground.
  • Outside of the circuit are the Device Under Test (DUT) power supply, the DUT, and the current sense resistor. The current sense resistor is sized to ensure that the current can be adequately measured and that it does not affect the DUT performance. In this case a 1-ohm resistor is used because it meets these requirements and allows for easier math (see below).
  • The amplifier circuit was only bread-boarded so the actual accuracy is not dialed in, but the results are close enough to show the idea.

A typical low-power micro spends most of the time in a low-power state an wakes up periodically to check conditions.  The average current can be modeled as shown in the equation below.

clip_image002

To get the total average current the amplifier can be used to show the current on an oscilloscope and then the equation can be filled in.  Below is a scope capture of a typical micro current consumption while in a sleep condition.  The asleep/awake behavior can be seen. For approximately 80% of the time the current is low – the voltage is approximately 250mV which is equivalent to 250uA.  For the remaining 20% of the time, the micro is waking up and then for a real short time it is at full power as it performs its actions before it goes back to sleep.

image

By zooming in on the higher current portions the following times and currents can be found for the DUT.

Micro State Duration Current (Measured Voltage/1000)
Asleep 813ms 250uA
Waking Up 185ms 925uA
Active 2ms 5.5mA

Using these measured values, the average current equation can be filled out as shown below.

clip_image002[7]

So in this case, the average current for the micro system is 385uA. 

This method can be modified to measure smaller currents by increasing the current measurement resistor and/or increasing the gain of the IA.  Also, more accurate measurements can be made by placing this circuit on a PCB.  Also other IA ICs can be used to get better performance.  Hopefully there are some ideas that you use to help troubleshooting in the future.

PID Motor Control with an Arduino

pid_firstbot

PID motor control with an Arduino can be accomplished using simple firmware.  In this example we use our Firstbot Arduino-Compatible controller to implement a PID based position controller using analog feedback and a potentiometer for control.  This is similar in operation to a hobby servo, but the potentiometer provides the control signal instead of a pulse from a receiver (and of course you are using a motor, not an RC servo).

[Read more…]

The travails of fixing an old design

 

data_erase

 

Recently I had the opportunity to fix a design I did way back in 2005.   It turned out to be a bit more trouble than I anticipated.  In the past I have talked about the need for good record-keeping and how that gets harder  and harder to do as the technology in question gets older and older.  Fortunately for me we had been conscientious enough to retain enough of our old-technology to allow me to fix the problem . . . . barely.

[Read more…]

Tracking days, hours, minutes, seconds with Excel

When testing different projects, sometimes it is helpful to know how long something has been running.  I recently ran into this while doing some final testing for a countdown timer for a client. For this particular design, I needed to test a circuit once a day for about a month. Unfortunately, I could not automate the test – I had to do it manually. Time to bust out a table.

 Microsoft Excel is usually my go-to application when I need to tabulate and collate some test information.   Excel is incredibly powerful and has a myriad of built-in functionality and programmability.  I am not an expert in Excel, but I can usually wrestle it into submission and get it what I want it to do.  For this particular testing procedure, I came up with a formula that may be of use to some of you out there.  Excel has some fairly powerful arithmetic capabilities built in.  Unfortunately, there appears to be a split between the Years, Months, Days operations and the Hours, Minutes, Seconds operations.  There are not any built in functions that allow the two types of operations.  I needed to roll my own.

I was going to run the test unit for 24 days.  I wanted to enter in a time and have the Excel sheet show me how much time would be left on the unit.  Here is the spreadsheet I came up with.  I will describe how each of the cells is derived along with some background.

image

A note on Microsoft Excel Time format.  Microsoft has a fairly unique time format for Excel.  See this link for information how it works.

The basic test was this: I put 24 days on my test unit and had it start count down.  Every day I would check to ensure that the test unit was counting down correctly.  Cell B3 shows the start of the test.  Cell C4 shows that 24 days are on the test unit.  Column B (Starting at Row 7) shows when the time was checked.  I could simply enter in the time and date in column B and the spreadsheet would take care of the rest.  After entered the time  into column B, Excel converted it to the Excel format.  I did that by simply setting the cell format to “General”.

Column D simply subtracts the converted time in column C from the converted start time.  So in D7, the “0.02083333” represents a half hour.  Column E shows what the time on the unit should be in the Excel format.  So in E7 the “23.97916667” represents 23 days, 23 hours, 30 minutes in Excel format.  Unfortunately, that is not easy to read.  Column F is where the magic happens.  The value in column F is given in the format of DAYS:HOURS:MINUTES:SECONDS.  So F7 is 23 Days, 23 Hours, 30 minutes, and the seconds values I don’t care about.  The formula to convert the E column value to the F value is given below:

=INT(E7)&":"& INT(MOD(E7,INT(E7))*24)&":" &  MINUTE(E7) & ":XX"

Here is how it works:

DAYS = INT(E7) – this is simply the integer value in E7, which in this case is “23”

HOURS = INT(MOD(E7,INT(E7))*24) – the “MOD” function, takes the decimal portion of E7.  By multiplying it by 24 (number of hours in a day), it gives the number of hours, in this case “23”.

MINUTES = MINUTE(E7) – this is a built in function that Excel has that tells how many minutes are in a cell, after all of the hours have been taken out.

With the help from Google. I was able to get a quick a dirty Excel spreadsheet to do what I needed.  Hopefully it will be of use to you.

Near Field Communication (NFC) with ST Micro CR95HF – Part 2

image

Near Field Communication (NFC) with ST Micro CR95HF.  A couple of weeks back I started working on a circuit board that holds ST Micro’s CR95HF NFC communication IC.  NFC stands for near field communication, and is basically an very short-range RF data link. Several communication protocol have been adopted for use with NFC hardware.

[Read more…]