PICaxe as constant current source?

Cillakin

Member
While reading through the manuals and getting more general information with respect to each chip, I noticed that each pin can sink or source 20mA. After doing some digging on other current sources, mainly for driving multiple LEDs, a thought came to me and I was hoping to get some clarity on this.

Can any picaxe chip be used as a current source? My thinking is that if you simply turn all the pins high and have them all come together through some array, say through a Darlington Array, can you combine them to get the 200mA max provided by the chip as a current source?

If a 08M2, as an example was used, could you turn the pins high and feed them into a 6 input Darlington Array, tie the 6 outputs together and have (in this case) 120mA usable as a constant current? There exist many other ways to do this but just writing up some simple code and using a darlington array seems like a much easier and fool-proof method. So, is this possible? :confused:
 

rq3

Senior Member
While reading through the manuals and getting more general information with respect to each chip, I noticed that each pin can sink or source 20mA. After doing some digging on other current sources, mainly for driving multiple LEDs, a thought came to me and I was hoping to get some clarity on this.

Can any picaxe chip be used as a current source? My thinking is that if you simply turn all the pins high and have them all come together through some array, say through a Darlington Array, can you combine them to get the 200mA max provided by the chip as a current source?

If a 08M2, as an example was used, could you turn the pins high and feed them into a 6 input Darlington Array, tie the 6 outputs together and have (in this case) 120mA usable as a constant current? There exist many other ways to do this but just writing up some simple code and using a darlington array seems like a much easier and fool-proof method. So, is this possible? :confused:
No. The Picaxe outputs are current limited only by the impedance of the individual P and N channel MOSFETS that allow them to switch high and low. From previous research, the P channel is about 80 ohms, and the N channel about 30 ohms. At a worst case supply voltage of 5.5V, that would allow a source or sink current well in excess of the spec limit of 25 mA.

Having said that, it IS possible to drive SOME LED's if connected between two output pins (one high, one low, perhaps pulse width modulated). The current limit is then 110 ohms, and the supply voltage minus the LED drop, along with the PWM duty cycle, MAY get you into a range that is safe.
 

rq3

Senior Member
To clarify further, the pins are not limited to 20 mA internally. The current limit must be provided externally. In the case of driving a Darlington array, the array will sink whatever the base drive is, times the beta of the darlington. Probably won't hurt the Picaxe, since the Darlington input impedance is very high, but the Darlington will smoke unless current limited. So you've just shifted the current limit problem into a higher power area.

You could use a Picaxe as a constant current source by using using a current sense resistor to feed one of the A/D inputs, and then PWM an output to a transistor or mosfet to regulate the current flow through that power device. You could even low pass filter the PWM to force the transistor or mosfet into linear regulation of the current, but the power dissipation would rapidly get excessive.
 

Cillakin

Member
To clarify further, the pins are not limited to 20 mA internally. The current limit must be provided externally. In the case of driving a Darlington array, the array will sink whatever the base drive is, times the beta of the darlington. Probably won't hurt the Picaxe, since the Darlington input impedance is very high, but the Darlington will smoke unless current limited. So you've just shifted the current limit problem into a higher power area.

You could use a Picaxe as a constant current source by using using a current sense resistor to feed one of the A/D inputs, and then PWM an output to a transistor or mosfet to regulate the current flow through that power device. You could even low pass filter the PWM to force the transistor or mosfet into linear regulation of the current, but the power dissipation would rapidly get excessive.
Thank you for the reply.
I was afraid it wouldn't work, it just sounded to easy and to good to be true. In any case why is the 20mA rating given if it can sink/source more than that? It would appear using the tried and true method for current sourcing is still the best option as using a picaxe appears to be just an added step. Which means more room for error to me. Again, thanks for the reply. =]
 

SAborn

Senior Member
In any case why is the 20mA rating given if it can sink/source more than that?
All components come with limitations of max and min values, these are the safe operating range for use of the components, if you do not work within these limits you will likely damage the component, and perhaps let the magic smoke excape.
 

westaust55

Moderator
The 20 mA is the normal single pin recommended maximum current.
From the PIC datasheets, the absolute max is 25 mA and anything above can lead to imminent failures within the PIC chip.

Note also that PIC chips also have total current limits that may be as low as 95 mA and some also have limits per port (up to 8 pins).
Reading the corresponding PIC chip Datasheet is imperative if considering any loading on the chips.
 

rq3

Senior Member
Thank you for the reply.
I was afraid it wouldn't work, it just sounded to easy and to good to be true. In any case why is the 20mA rating given if it can sink/source more than that? It would appear using the tried and true method for current sourcing is still the best option as using a picaxe appears to be just an added step. Which means more room for error to me. Again, thanks for the reply. =]
Just as an example (I haven't tried this, but it should work): let's pretend we want to load test a 4.7 volt battery, so we short it to ground through a low ohm current sense resistor in series with an N channel power MOSFET. The current sense resistor supplies a voltage to a PICAXE A/D input, and we use another A/D input to monitor the battery voltage.

Then we wrap some code around the whole thing so that the Picaxe provides a PWM drive to the MOSFET gate. The code reads the A/D current value, and adjusts the PWM to maintain an average current drain from the battery through the MOSFET until the battery voltage reaches some predetermined level (read by the second A/D input). Now you have a programmable current sink. The Picaxe could even time how long it takes the battery voltage to sag, and send serial data to an LCD display to show battery capacity in mA-hours! Or it could turn on your coffee pot, or, or, or...
 

Dippy

Moderator
Absolutely what Westy says - for (theoretically) up to date electrical info always go straight to horse's mouth - in this case Microchip.
Whilst M'chip data Sheets are BIG the data is current (haha) and specific to the device - rather than just a generalised spec in a Manual which, of course, has already been read.


With PIC/AXEs you can, with supplementary components, make an adequate CC or CV supply for simple projects. Many people have already done this - often with Solar charging projects. However, in many cases, it's often easier and better (and usually more reliable) to use hardware Switcher based circuits and there are many done-for-you chips around for things like LED drivers.. Depends on app and requirements.
RQ3 describes a similar thing (I think?) where a current sense resistor (or any current sensing device) can be used. It's all about sense-feedback-adjust and here we can digress even further into response time and PID.



It's well worth a good old nerdaround to see what's going. Even if not exactly appropriate it can get the creative juices flowing :)
Enjoy!
 

rossko57

Senior Member
It would appear using the tried and true method for current sourcing is still the best option as using a picaxe appears to be just an added step.
Sure. The picaxe earns its keep when you want to something more than light a led, say flash out a morse code character in response to some radio signal,
 
Top