SparkFun Forums 

Where electronics enthusiasts find answers.

Everything ARM and LPC
By a.h
#130862
I'm going to be using my STM32F103ZG to drive an electric bike motor controller, i.e. I need to be able to put out a voltage between 0V and 3.3V -- with a current of maximum 1.5mA being drawn. I am slightly puzzled by the hardware aspects of how to do this though (Yes I'm rather new to microcontrollers and electronics).

The STM32 I have does have a built in DAC: this DAC has an output buffer as well, however I am not sure how much current I can draw from it (Datasheet can be found here -- right hand side of page -- look at pages 107-108) -- extensive googling has delivered no results. The MCU is operating at 3.3V, i.e. the DAC should in theory be able to supply 0-3.3V.

The datasheet says I can draw up to 25ma on the General Purpose IO pins, however there is no maximum current specified for the DAC (with the buffer switched on). What is specified that might be of relevance is Rload (Resistive load vs. VSSA [Ground] with buffer ON) with minimum 5kOhm. I'm not really sure how to interpret this -- does this mean any load I put between the DAC ouput and Ground must be at least 5kOhm? (In this case I wouldn't be able to connect directly to the bike since it looks like ~2.5kOhm.) Or does this specify what the buffer looks like to the DAC -- meaning I can in fact draw the 25ma of current that are specified for the GPIO pins?

The other issue I have seen is that the buffer seems to take away 0.2V from the top an bottom voltages, i.e. I can only get 0.2 to 3.13V? In this case I would need to use an output buffer: how do I go about adding this, i.e. what sort of chip would be suitable (I have power supplies of ~24V unregulated, 5V regulated and 3.33V regulated already available -- i.e. would I have to use some sort of rail-to-rail single supply opamp)? It doesn't particularly matter if the range of voltages I get is slightly larger than 3.3V, i.e. 5V output is perfectly safe.
By frankvh
#131505
I think you're correct in your interpretation of Rload. This is a common way to spec a DAC, and basically says that for a load lighter (higher resistance) than that, the DAC specs can be met. For a load heavier than that, the DAC specs won't be met.

Buffering is easily done with a unity-gain op-amp. Choosing a rail-to-rail is good because although you have headroom at the top end (eg if you use your 5V supply) you have no headroom at the bottom end (GND). Depending upon how good you need the specs to be, this circuit might be adequate:
http://en.wikipedia.org/wiki/File:Op-Am ... Buffer.svg
Take a look at the LM324 and its family members as a possible op-amp. Cheap, common, and works down to GND.
By hsutherl
#131545
Sorry about the late reply a.h. I finally took a look at a board I have. I'll post the results in case you're still in the planning stage. First though, I'll say that I consider myself to be reasonably competent at analog design, and IMO there isn't enough information in the specs for the DAC and buffer to enable you to do production design. So, some experimentation required.

Vdd on my board was 3.308V
Code: Select all
buf    load               vlo       vhi
----   --------------   ------    ------
off    open             0.003     3.302
off    1k pulldown      0.000     0.248
off    1k pullup        3.058     3.307
on     open             0.066     3.255
on     1k pulldown      0.054     2.768
on     1k pullup        0.571     3.263
Based on a sample size of one, your concern is probably justified. a) The buffer does reduce your voltage swing, and b) the un-buffered output certainly cannot drive your motor controller. I don't know anything about your motor controller, but if it needs the full 3.3V range, then you need a buffer. The good news is that the unbuffered output does swing rail to rail, so you can use the voltage follower circuit frankvh suggested.

I second the suggestion of an LM324. As Frank said, one of its key features is that the output can get very close to the negative rail with a moderate load. Also it doesn't mis-behave (lock up) if one of the inputs gets close to the negative rail. And it is one of (gulp) 12 analog IC's that Radio - er - The Shack still carries. (good thing we have SparkFun!).

One drawback to the LM324 is that it is a quad and you may only need one of the 4. If you have no use for the other 3 sections you can configure those as voltage followers also, and ground the inputs.

If you're laying out a board, you might leave provision to run the negative rail to either ground (first option) or to -24V (backup plan). Or, if power is of no interest, you could simply run it from -24.
By a.h
#131553
Whoops, It's actually a +24V I have, don't know why I wrote -24.

I think I'll probably just use the LM324, without the STM32 buffer switched on since I need the full range (the controller actually is specced to take higher input voltages, but saturates at 3.3V), and will report back once I've got it running. Thanks for the help.