Showing posts with label analog. Show all posts
Showing posts with label analog. Show all posts

Sunday, February 24, 2013

Gyro King Electronic Design and the STM32F40RGT6 Microcontroller

Gyroscope

The control board is centered one of Analog Devices' highest rate gyro, the ADXRS649, rated for 20000 degrees per second but extendible to 50000 degrees per second, or around 8000 RPM. We chose the gyroscope as opposed to Open Melt's accelerometer method to avoid noise issues. While accelerometers will pick up any and all vibrations, gyroscopes are quite a bit more noise resistant. This is offset by the difficulty of finding a gyro with a large enough range and having to place the gyro at the exact center of rotation, since applying acceleration to a gyroscope causes error. Otherwise, all the other challenges are there, such as keeping the sensor in a constant position and orientation as the robot spins around and smashes things.

Analog to Digital Converter (ADC)

The gyroscope outputs a 5V analog signal, with zero rotation at 2.5V. This works out to 50 uV per degree, ideally. Our gyroscope ended up with a range of around 65000 degrees per second due to some curious part choices, making it 38 uV per degree. Thus, we needed accuracy in converting the analog to a digital signal. We used a 24-bit, 14 kSPS ADC from TI, the ADS1259.

Microcontroller

The ADC feeds into the STM32F405RGT6, an ARM Cortex-M4 32 bit microcontroller. The microcontroller was provided from Newark, a pretty good place to get parts. Why this microcontroller?

What stands out is this is an extremely high power chip without being weird. First thing we noticed is how little physical space it needs. It uses a standard 3.3 volt input, avoiding a separate 1.7 volt supply. There's no external RAM or even an oscillator required. All it needed was power. Instead of using the giant 20 pin ARM JTAG nonsense, it uses just 4 wires. On a space limited board such as Gyro King's, every square millimeter counts. And in return we got a 168 MHz processor with a floating point unit, allowing us to avoid the performance vs. fixed point tradeoff, extremely powerful timers, which was used in a previous project to control two three-phase motors with center-aligned PWM, dead time, and ADC triggers, and DMA on many peripherals to save your cycles and automate data capture. Notably, it has a completely free toolchain for compiling programs. Although difficult to set up on OSX, it is possible and certainly usable. Finally, this STM32 is RTOS (Real Time Operating System) friendly. We used the open source ChibiOS. This let us use higher level programming, such as multiple threads, and abstracted a lot of the lower level access. All things considered, a solid microcontroller.

Three Phase Motor Control and Drive

While it is entirely possible to generate the drive motors' three phase commutation signals and sense the rotor position directly from the microcontroller, we were pressed on time and feeling a bit lazy. We turned to Allegro MicroSystems' A4960 Automotive Sensorless BLDC controller. These chips perform sensorless commutation, start up, directly drive the motor MOSFETS, and current limiting all from some configuration from the microcontroller and a PWM signal. Using these significantly reduced development time, though we still have to tune all the parameters of commutation, such as dead time, zero crossing window, phase advance, and commutation blank time.

The Allegro controllers directly connect to a trio of half bridges composed of the IRFH5301TR1PBF N-channel MOSFETS, rated for 35A at 30V.

Board Layout and other Doodads

Connectivity was handled by a little Bluetooth doodad, the Roving Networks RN41-I/RM board. It was directly soldered on to the control board. It connected to a laptop running a pygame based GUI displaying things like spin speed, power, and direction. The controller is a PS3 controller.

The control board also had some good ideas, like a few status LEDs and what looks like a bar of ceramic bus capacitors, since electrolytics would not fit height-wise. A digital Hall-effect sensor was also on there to be used for calibration. Ideally, it would function as an on-board tachometer to a magnet held above it, providing an absolute reference for the rate of rotation, but was never implemented in software.

The board used four layers, to provide full ground planes to try to separate the combination of sensitive analog, digital, power regulation, and motor control on a tiny single board.

A notable bad idea was using test pads as the programming header. Due to space limitations we couldn't fit a full through hole header, so we used surface mount test pads. Of course they ripped out.

Conclusion

This was a pretty solid control board, surviving the impacts of robot battle while tracking well enough to provide a near constant direction at speeds up to 2000 RPM, the max we've seen it spin at. The component choices were all well made. We wouldn't use test pads as headers again though. Xo would go on to make a variation of this board with one brushless driver and two brushed drivers, but otherwise similar hardware.

I should also take pictures next time too.

Tuesday, March 27, 2012

Strain gauges

In the Velociryder versions 1-3, turning was achieved using a tilting rear section. This tilting section prevented the back foot from helping the rider balance forward and backwards. I would not stand for this in version 4. I planned to use an actual skateboard deck and strain gauges to measure the tilt of the rider. This will minimize moving parts and ideally make it easier to ride. Not only that, knowing the weight of the rider can improve the board's response.

Part 1: Acquiring Strain Gauges

After some Googling and ebaying, I found strain gauges or pressure sensors either come in tiny or extra large, 1-3 pound range or industrial strength. All were too expensive. Then I realized digital bathroom scales must have something to measure weight. And since they're designed to both precisely measure human weights and not break under the heaviest of people, they are perfect. A quick search revealed digital bathroom scales going on eBay for a dollar.

Kilograms only? Good enough!
Disassembly followed. The strain gauges look like this.
It is supported by the side prongs. Pressure is applied on the top of the middle prong.

Part 2: Analysis

Electrically, they look like a potentiometer.


The outer blue and white wires measure a constant resistance, in this case 2 kOhms, while the middle red wire is the wiper, with roughly 1 kOhm resistance between the red and blue wire and the red and white wire. Pressing the gauge is equivalent to turning the potentiometer, though only a very slight amount. When five volts was applied to the outer wires, the middle wire deviated by about 4 millivolts over the range of 100-ish pounds. Since I had four, I used two pairs, one pair each for the left and right side. The power supply for each pair was put in opposition, so pressing on a pair of strain gauges causes one output voltage to go up, and the other to go down.

Left strain gauge/potentiometer goes up under pressure, right side goes down.
This create the biggest difference to amplify for your buck.

Electrically, it forms a wheatstone bridge. Measuring the voltage across the outputs gives a reading that varies linearly with pressure applied.
A wheatstone bridge. Voltage is measured in the middle.
The two strain gauges fully connected. Remember, one is connected upside down to get a differential voltage.



Part 3: Using Them

The tiny voltage difference needs to be beefed up. In comes a differential amplifier!
One channel of the differential amplifier with zero point adjustment and low pass filters. The Velociryder uses two, for the right and left side.
This is an almost standard diff amp configuration, with a couple extra bits. The capacitors C8 and C10 are (very) low pass filters to get rid of noise. Instead of a constant resistor on the non-inverting input, a potentiometer is used so any zero offset can be tuned out. This converts the range from 0-4 mV to 0-3 V, an excellent range for a microcontroller's ADC.

Protips

Since the op-amp will likely be used in single supply (unipolar) mode, use a rail to rail op-amp so the output won't crap out near 0 and 3 volts.

Monday, November 21, 2011

Fixing the Analog Signal

Routing an analog signal all over the place with ribbon cable and no filtering and no buffering made it extremely susceptible to any bit of noise, not to mention the voltage sag due to the loading of the ADC. Given that I'm using 5k pots and I need precision to roughly 0.3 degrees, the loading effects are quite significant. How to fix? Twisted wires, buffers, and some hardcore low pass filters.

The new revised board

 Twisted Wires
My friends advised I twist the wires to help reduce noise. To be honest, I'm not sure how it works with non-differential signals, but I supposed it was simple enough to implement, and it does clean up the rats nest. And so, twisted wires.


Low Pass Filtering

Nothing fancy like Chebyshev or Butterworth. Just a simple RC filter that does the trick. Using the formula 1/(2 * pi * R * C) = -3db frequency, a 3.9 kOhm resistor along with 2 uF capacitor, I get a cutoff frequency of around 20 Hz, which is plenty high enough for a mechanical system such as this. The schematic looks like this.
On the oscilloscope, it turns the input (black) into a nice smoothed line (red).
Sorry, I don't have a legitimate oscope capture. I promise it looked like this!


Learning About Op-Amp Response Ranges

To fix the loading problem by adding in some op-amp buffers. Using unity feedback, I boost the current supply from a couple microamps to a couple milliamps. Excellent for keeping a stable voltage. The schematic looks like this.

When I tried out my new circuit, the circuit seemed great. Until I hit the low ranges. Then the output shot straight up, as such. 
 And it does so at 1.3 V, suspiciously close to two diode voltages (0.7 volts). The problem is that op amps are normally not designed to operate near their rail voltages. Here I use +5 and 0 volts, with an input voltage of 0 to 3.3 volts. Thus, it craps out near zero volts.

The solution is some rail to rail op amps. I used some op amps from TI, the so called TLV2774 Quad 2.7-V High-Slew-Rate Rail-to-Rail Output Operational Amplifier. It is rail to rail, so it can operate near its supply voltages, has four op amps in one package, though I only need three, and has input bias current in the picoamps. Also, free samples!

The entire circuit looks like this, with incredibly stable output voltage.
Digital Filtering

In addition to the analog filtering, I implemented some (relatively) long working digital filter. It takes 24 samples at 100 microsecond intervals. It then drops the lower eight samples and upper eight samples, and averages the middle eight samples. Yeah filtering!

Precision in measuring voltage is absolutely essential. Unlike a standard cartesian robot, where a little imprecision creates a constant offset, incorrect calibration in the arms causes the robot to not draw on a plane, but on some curved surface (I don't exactly know what it looks like, as it is some complex surface).

And so, with this new precision, a new video of the drawing!
Comparison of the output, with version 1 on the left and 2 on the right.
What an improvement!