A few weeks ago I bought a record player for a few quid at the local flea market. Even though we already have a nice vintage Marconi record player that’s in great shape and sounds fine, it has two disadvantages: 1) There are no external connectors, so all the sound comes from the built-in speaker. That’s fine, but it prevents you from either listening to your records with headphones, or to record them somehow (unless you use a mic at the speaker, of course). 2) The player is a mono player only. Again, that’s fine for playing both mono and stereo records, but of course you won’t hear any left-right differences when listening to stereo records. This second record player was supposed to fix both of these problems. It did, however need a few modifications.
After the flurry of activities in recent weeks on a previous post (thanks guys!) I finally went back and worked on the synth project some more. Some time ago I had already created a simple MIDI input and output circuit on a stripboard that the Discovery board could sit on. This would allow me to play notes or adjust parameters from any standard MIDI controller or the PC. The hardware setup for this was quite simple using a 6N137 optocoupler, which gets its 5V supply voltage directly from the 5V rail of the Discovery board. Since the output of the optocoupler is just an open drain, I didn’t even have to worry about any level shifting and directly connected it to the USART2 RX input on pin PA3, which I configured with an internal pull-up. (I have yet to test the output side, which is coming from USART2 TX on PA2 and goes to an external MOSFET.)
What made the STM32F4-Discovery board so attractive for me was the fact that it comes with a nice on-board Audio-DAC with integrated amplifier, the Cirrus Logic CS43L22. However, getting the combination of STM32F4 and CS43L22 to produce any sound is anything but trivial for someone just starting out with ARM microcontroller development (like me). After having spend quite a few hours in the last week making it happen, and I finally did, I thought it might be worthwhile writing it down here in case others want to follow along.
This tutorial assumes that you set up your development environment already, and have at least managed to get an LED to blink. If not, there are several tutorials on the web that should be able to show you how to do this. This tutorial will make heavy use of the “Standard Peripheral Library” that ST provides for it’s microcontrollers. It is integrated into the IDE I am using (CooCox CoIDE), and I found it incredibly useful, especially in combination with the documentation that comes with in in form of a .chm (compiled HTML help file).
One way in which it’s easy to tell that I’m still relatively new to the whole electronics and microcontroller hobby is by the amount of new developments in this area I tend to miss until much later. One of those is the release of the STM32F4-Discovery evaluation boards from ST Microelectronics. While I was aware of some of their other STM32 ARM based boards (and had considered buying one of them), this particular one had escaped my notice until a few weeks ago. But why is this such a big deal, you will ask. Well, the big deal, for me at least, is that the STM32F4-Discovery comes with a microcontroller and a few peripherals that fit perfectly with my particular interests.
So what do you get with an STM32F4-Discovery board? At the heart of the board is an STM32F407VGT6 microcontroller. That’s a 32-bit ARM Cortex-M4 based microcontroller with 1MB onboard Flash and 197kb RAM, which can run at up to 168 MHz. Importantly for me, it is classified as a “Digital Signal Controller”, because the Cortex-M4 core is essentially a Cortex-M3 core with added DSP instructions. While it certainly wont be able to compete with dedicated DSP devices, it should still provide a decent amount of computing power for moderate DSP applications. What’s also nice is that every single one of the 100 pins of the LQFP100 packaged device is routed to two headers on the board, although only about half of them are still unused. The other pins are already connected to some of the onboard peripheral devices.
The other devices on the board are the ST-LINK/V2 section at the top, which is used to program the device, but can also be used stand-alone to program and debug external devices. This alone makes the STM32F4-Discovery a very interesting board. Even more important for me, however, was the fact that it includes am onboard DAC with headphone amplifier (a Cirrus Logic CS43L22) and a headphone jack of course. It also includes a digital microphone (ST MP45DT02), a MEMS accelerometer (ST LIS30DL) and a few LED’s, 2 push-buttons and a micro-AB USB connector. This should make it very easy to try out some sound-related applications and other little things (how about changing cutoff frequency and resonance of an audio filter by tilting the board?)
So last weekend I ordered the STM32F4-Discovery from Farnell/Element14 for just under 10 Pounds (+VAT). I filled my 20-Pound minimum order with a few 8/16-bit micros (several TI MSP430’s and an Atmel AVR), which should come in handy as support chips for slightly more complex prototypes. The order arrived 2 days later, but I haven’t had much time to play with the board yet (partly due to extreme weather conditions here). However, I’m very excited to get my proverbial hands dirty with this little board.
I like taking stuff apart, especially stuff with electronics in them, so when I saw an old VCR next to a trash bin in the alley behind our house, I had to take it in. There are obviously quite a few interesting bits inside a VCR, both mechanical and electronic. One of the things I was mostly interested with the VCR was the different electrical motors in it. Altogether there were at least two: one to operate the mechanism to load and unload the video cassette and the so-called capstan, the part that actually pulls the tape. The video drum also seems to have some sort of motor like components (permanent magnets and coils), but I haven’t figured out yet if they actually produce rotations, or if they are used for the reading and recording of the video tracks on the tape.
The capstan motor was placed on its own little module and was therefore very easy to take out. It came with a small PCB with a few surface mount components, most notably a 34-pin QFP. The part number LB1952 identified it as a brushless motor driver specifically for VCR capstans. The datasheet for the device was very easy to find.
The pins on the connector on the board were also nicely labelled so it was fairly easy to identify which of the connector pins connected to which pins on the IC. I only mixed up the two voltage pins. I had falsely assumed that VCC1 would be the controller voltage supply, as it was next to S-GND (=signal ground?), whereas VCC2 would be the output, i.e. motor supply voltage (since it’s next to M-GND =motor ground?). It turned out to be the opposite, which I found out after I measured the voltage at VREF, which if unconnected should show a level of approx. 0.43 x Vcc. Besides the supply voltages, the three important signals are F/R, CONT and LIMIT. F/R specifies the direction of rotation (forward/reverse), so can either be tied to ground or Vcc. CONT is the main speed control voltage, in the range VREF to Vcc. LIMIT is a current limiting control. As mentioned, VREF can be left unconnected. FG seems to connect to the FG-OUT pin on the device, the “FG amplifier output pin”. I have yet to learn what that means and how to use it – it seems to related to some sort of feedback mechanism, so may very well be quite useful. However, for now I left it unconnected.
To control the speed I decided to make use of the Boarduino I had laying around. I still use the default bootloader it came with, but wrote the program for the ATmega328P in AVR Studio to have tighter control over the timing of things. To generate a variable control voltage I used one of the 16-bit capture/compare timer modules to generate a PWM signal. I set the module up for 10-bit “fast-PWM” mode, and have the counter running at the main clock frequency (16Mhz), i.e. without a clock prescaler. I set it up to turn off the timer output pin on compare match and to turn it on when the counter overflows (in this case, reaches the maximum possible with 10 bits). Adjusting the compare value therefore sets the duty-cycle directly. This should give me a main PWM frequency of approximately 15.6kHz (=16MHz/2^10). I implemented a simple 2-pole RC low-pass filter to smooth the voltage. This probably wouldn’t be necessary, as the momentum of the motor itself should act as a filter, but I figured it couldn’t hurt.
For my first tests I connected two push buttons to increase and decrease the duty cycle via the comparator value. I used pin-change interrupts and one of the other timer modules (this time with heavy prescaling and overflow counting) to implement a simple software button bounce algorithm. This had the neat side effect that main() ended up being an empty while(1) loop. I could have probably even put the micro into a sleep mode – I’ll have to look into this.
The whole setup seemed to work quite well, though it was fairly clear that the relationship between the control voltage and the speed isn’t a simple linear one. The next step will be to actually measure the rotational speed with the microcontroller so it can dynamically adjust the control voltage(s) to maintain a set target speed.
A few weeks ago I did what I had wanted to do for a long time: take the old computer power supply I had laying around and convert it to a simple bench power supply. There are plenty of instructions on the web on how to do this. The idea behind all of them is quite simple: Since a standard computer power supply provides several different voltage levels to the motherboard and the built-in peripherals (hard drives, graphics card, etc.), it would be useful to make these outputs available via standard connectors (often banana plugs). You can then use these voltages during prototyping of any of your electronics projects. This is especially useful when you need multiple voltages. The two main voltage levels provided are +12 Volts and +5 Volts, but often you also have a +3.3 Volt output and a few negative supplies (-5, -12). For my conversion I used the three positive outputs only, though I may connect the negative outputs in the future as well. In my supply, the red socket provides the 5V output, blue the 3.3V and yellow the +12V. The two black sockets are ground.
The switch came from an old hot air gun that had stopped working. Even though the PSU has a power switch on the mains input side, I wanted a switch on the ‘user’ side as well. I also added a red LED, which I connected to the “power good” signal (via an appropriate resistor).
When I first opened the PSU, I was shocked to see the poor quality of the device. It came from a fairly cheap old PC, so I didn’t expect great quality, but I was surprised by all the exposed mains connections and the giant solder blobs on the bottom (I should have taken a picture!). I also had to replace two of the capacitors – the ones that where in there had blown. That at least wasn’t a surprise. The one positive surprise was that the fan still works flawlessly, and is probably one of the quietest fans of that size I had ever heard. When I first turned it on after my conversion, I thought the fan wasn’t working any more because I could hear nothing. But a quick look showed that it was spinning happily.
So, all in all the conversion seems to have gone well, and I can now stop using wall-wart supplies or batteries when I want to try out a new circuit. If you are considering doing such a conversion yourself, be sure to follow the appropriate safety precautions. Remember that you are dealing with mains voltages in parts of the circuit, so there are all kinds of real dangers! More so if you have a cheaply constructed design such as I had!