Double your outputs without a bigger chip!

laserhawk64

Senior Member
I simply can't imagine that I'm the first to think of this. Circuit uses the 08M/2 but could really work with ANY PICAXE chip as I understand it, maybe even non-PICAXEs like an Arduino (not sure) -- it's a nifty trick indeed. It's kinda odd that I haven't seen this mentioned here yet, because of how simple and useful it is.

I was thinking about a project of mine where I didn't really want to use a microcontroller, but that would likely wind up simpler and easier if I "broke down" and went with that instead of discrete circuitry (555 and a bunch of passives and transistors). An 08M or 08M2 would've been perfect, if it had two more outputs.

Then it hit me.

All of those IO pins are tri-state. They can be either logic high (positive voltage), logic low (shorted to ground, therefore negative voltage) or set to a high-impedance "off position" (no current flows). Use a set of homemade LED/phototransistor optocouplers (dead simple and fairly cheap) in a pseudo-charlieplexed connection scheme, and you get two outputs per pin. Wire the LEDs so that only one will come on when the output is positive, and the other when it's negative, and both will be off when the output is "off" (I think). The phototransistors will only conduct when the LEDs light up. (IR emitter/detector pairs are perfect here, IMO, although one could kludge something up with white --or green-- LEDs and a handful of CdS cells...)

Simple, cheap, AND effective -- although one would likely want a secondary (non-photoreactive) transistor to power anything of significance, or even a relay for the really beefy stuff. The IR emitter/detector pair that I saw on SparkFun Electronics ($2 a pair, so a little pricey) maxes out at 100mA of current for the "business end" here. (SparkFun sells it as part # SEN-00242.)

I've got a schematic here for you folks, too...

PICAXE 08M-08M2 Output Doubler Circuit.jpg
 

nick12ab

Senior Member
Unfortunately you can't have two pins from a pair on. Also pin3 is input only. Well you could quickly alternate between high and low using PWM which would make two LEDs controlled by the pair to appear to be both on, but they would be dimmer than normal.

It's not a rubbish idea if you only need one output of a pair on at once, but a shift register would probably be better. Shift registers can be driven with as little as two pins and are commonly available with eight outputs (but are available in other sizes too).
 

westaust55

Moderator
A further alternative is to use an i2c IO expander chip. These have bidirectional IO.

There is the MCP23017 providing 16 IO as two 8-bit ports
Or
The PCF8575 providing 8 IO pins.

Only needs 2 PICAXE pins (shift registers generally need 3)
And is faster than a shift register based approach.
 

laserhawk64

Senior Member
Oops on pin3. Sorry 'bout that -- I was working from memory (never a good thing with me!) Actually, for my purposes, that's just fine -- I only need two pins with this (and a couple transistors) to drive an H-bridge <g> The other two pins would've been inputs from a controller.

I don't think I've seen a SIPO shift register that worked with only two inputs, ever. Usually they need a minimum of 3. (74xx595, etc.) I'd be quite interested to see that circuit.

EDIT: westaust55, I think you and I were typing at the same time.

...I2C on an 08M...? I don't recall that being easy... ;)

OT: been meaning to ask you, westaust55 -- what is $FF, per your sig? Memory location or somesuch?
 

nick12ab

Senior Member
I don't think I've seen a SIPO shift register that worked with only two inputs, ever. Usually they need a minimum of 3. (74xx595, etc.) I'd be quite interested to see that circuit.
http://www.fairchildsemi.com/ds/74/74VHC164.pdf

Short inputs A and B together (because they are just ANDed internally) and tie MR to Vdd. Then there's only clock and data. That does have the disadvantage that if using something like LEDs they will all flash in turn briefly as the data is shifted in but that doesn't matter for other applications.

...I2C on an 08M...? I don't recall that being easy... ;)
It's only on the M2 8-pin PICAXE.

OT: been meaning to ask you, westaust55 -- what is $FF, per your sig? Memory location or somesuch?
$2B OR (NOT $2B) = $FF
 

darb1972

Senior Member
In addition to Nick's comments, it's probably worth noting that for only a bit over $1-00 extra, you can move up to a 14M2 and not much more and you are onto a 20M2. Still, I understand your intentions. You concept is a good idea. Prior to micros becoming so cheap and easy to program, I used to design everything with descrete components and/or basic logic gates. In recent years I have come to realise that it's very difficult to ignore the new gen of micros in terms of capabilities and cost.

As said, go for a "larger" micro or using a shift register could be the most cost effective approaches. If using an 08M2 you could even consider using an IO expander (I2C) such as the MCP23017-E/SP. It requires more complex code, and again, you have to weigh up the cost of this component verse a bigger PICAXE.

As a side note, and with reference to your circuit, as Nick suggested, the principal is good, but I have noticed a few issues with the design (if you were to use such a design). For starters, unless I am missing something, or the IR LEDs are current limited, what's stopping current flowing directly from ground to Vcc via the two LEDs? This would need current limiting. There are also a few switching issues related to correctly turning on/off the LEDs but I won't expand on this at the moment because I don't beleive the circuit will (at the moment) work as is. Also, RQ would limit the current through the Photo Transistors down to around half a milliamp (total). I probably also wouldn't use the Sparkfun unit suggested above. I think you might find it is designed to emit and then reflect off a surface (detect) something put in front of the sensor. If you wanted/needed isolation, you would be better off using opto-couplers.

Anyway, included here is an example of what I beleive will work (for pins that are outputs), however the concept hasn't been tested. Note that I have only given one example/branch for one leg. You would need to duplicate that on other outputs. Personally I still think it is easier and more cost effective to go for a bigger PICAXE, but I guess such a circuit mugh get you "out of trouble" should the need arise.

PS: Just uploaded Version 2 of the circuit. For anyone who looked/downloaded it, the circuit contained an error as the result of a lack of coffee. My bad. The attached circuit should now work without issue. Just had another coffee.
 

Attachments

Last edited:

westaust55

Moderator
...I2C on an 08M...? I don't recall that being easy... ;)
I saw the 08M/08M2 and by the time I got to typing had only remembered the 08M2 bit.
I recall hippy produced some code of about 90 bytes for bit-banged i2c comms but that is getting to be about half the program space of an 08M.

OT: been meaning to ask you, westaust55 -- what is $FF, per your sig? Memory location or some such?
Think nick12ab has given you the clue.
A neat play on a bit of Shakespeare combined with logical maths :)

When I first started using the line some years back I got quite a few queries about it.
Another member of this forum then stated using it on another forum site.
When queries diminished I figured we had a more erudite active membership here. ;)
 

laserhawk64

Senior Member
@darb -- that circuit you posted (the PDF) is really what I was looking for. I went with the LED config from another forum (IIRC random find on the Parallax forum. Google made me do it, lol)... the guilty party for the resistor values is a link in a thread recommended by SparkFun proper. (I do agree that SparkFun's pricing is rather high for an LED + phototransistor.)

@west -- I still don't get it. What is denoted by the three characters, '$FF'? I can read your little equation, but I don't know what it's telling me, other than a rather amusing Shakespeare reference... although I seem to recall that '$' in programming refers to a string variable -- in QBASIC (a language I'm rather familiar with) a string variable could be declared as such, eg: STRING$ = "blah blah blah" (I usually kept the programming commands in caps and whatever text went on the screen in appropriate caps/smalls... although I have been known to leave the capslock on for an entire program...)

That reminds me... (not sure this is brag-worthy) -- I once did a very short text adventure in QBASIC (don't put THIS on a Picaxe!) that had no parser. Longest program I ever did, and I'm only about 80% sure that all the bugs got worked out in the end... anyone care to see? :D
 

westaust55

Moderator
Code:
Shakespeare: to be or not to be

logic math:   2B   OR  (NOT 2B)  

    $2B = %00101011
NOT $2B = %11010100

%00101011 OR %11010100 = %11111111 = $FF
 

Paix

Senior Member
Ho ho, it's not quite the same when you have to explain it step by step though Westy, It must give you that slight sinking feeling that the level of erudition and understanding is lapping on the shore like a wave as the tide goes out.

Or you were being wound up ever so slightly . . . :)
 

Buzby

Senior Member
... It must give you that slight sinking feeling that the level of erudition and understanding is lapping on the shore like a wave as the tide goes out. ...)
It's not all as bad as it looks, there are always people who are new to something, and there always will be.

A sig I saw on another website got me thinking, till I worked it out.

' The volume of a pizza is PIZZA '.
 

John West

Senior Member
That one took me a moment, Buzby. And then I recalled the old Bill Cosby "Ice Cream" comedy skit, and it fell into place.
 

westaust55

Moderator
Since we are way OT it would be a fair cow if I let this one slip:

Q: What is the first derivative of a cow?





A: Prime Rib!
 

laserhawk64

Senior Member
OK, now I get it. So $ signifies a hexadecimal pair, and % (in your explanation) means binary -- so when you reduce the hex to binary, and add its NOT complement, you get all '1's -- eight of which are represented in hex as FF.

It really was the $ that was throwing me for a loop.

Thank you for the patient explanation.

Here, have (as I suggested I might) a little game I made. It's in QuickBASIC. The *.BAS file is the source -- it's plain text, you can read it in eg Notepad. The *.EXE is the compiled game (you can compile in QuickBASIC, unlike QBASIC which is purely interpreted -- coincidentally that's the only real difference). Behold, the text adventure with no parser! (It's quite a sight...)

Source (BAS) file --> http://www.datafilehost.com/download-c2913ecb.html
Compiled (EXE) file --> http://www.datafilehost.com/download-247eb760.html

Er, if you want to compile from source, get QuickBASIC PDS 7.1 -- that's what I used to write it. I don't think I'm technically allowed to distribute it, but I can tell you that there are places which do, legitimately, if you go looking for them ;)
 

westaust55

Moderator
OK, now I get it.

So $ signifies a hexadecimal pair, and % (in your explanation) means binary -- so when you reduce the hex to binary, and add its NOT complement, you get all '1's -- eight of which are represented in hex as FF.

Yes, in line with PICAXE notation
From PICAXE Manual 2 (V7.9) page 6

Decimal numbers are typed directly without any prefix.
Hexadecimal (hex) numbers are preceded with a dollar-sign ($) or (0x).
Binary numbers are preceded by a percent-sign (%).
ASCII text strings are enclosed in quotes (“).

really the 2B should also have a $ prefix in the signature line but then more would be lost/confused.
 

laserhawk64

Senior Member
Aaaaaaaahhh... now I know why I'd never seen that convention before. (You can tell I don't program much, right?) BTW, I'd be interested to hear what you folks think of that game... code and play-through... hint on the game: DON'T "DROP GEM"!!
 

Paix

Senior Member
DEC system 10 disks had Retrieval Information Blocks, RIBs and the backup RIBs were known as Spare RIBs. Their Mixed Vendor Group were familiarly known as Mixed VeG.

Alas all part of history now.
 

Jamster

Senior Member
Not going to run the .exe because McAfee is telling me it might be dangerous (sorry) but it looks a lengthly game with an interesting plot...

Joke wise I always liked a bit of romantic poetry: :p
Roses are $FF0000
Violets are $0000FF...

And also if we're on the subject of games this is what i do in my non-PICAXE spare time, maybe one day I'll start making a living from it. :rolleyes: You reckon they'd run on a PICAXE? :p

Jamster
 
Last edited:

laserhawk64

Senior Member
Sorry, Jamster, didn't see your post till now for some reason -- you can safely ignore McAfee. As a computer nerd (I can't program, but I'm the hardware type, and I know a few things about PC repair...) I can tell you that the most polite word I have to describe that particular bit of software is... "junk".

I use Avast. It's free, it's mostly awesome (lately it has become a bit naggy regarding the pay-for versions...) but it's golden.

More to the point... the game is quite safe to run, McAfee is just sounding an alarm because it hasn't seen the file before -- it's not like I'm [insert common game-maker here] and churning out lots of content every couple weeks...

On the other hand, if you run it, and it gives your computer a cold, I'll start looking for a new AV program. But I really am not expecting that to happen ;)
 
Top