08M leg 7 out 0 usage

RadioBob

New Member
I am trying to output to leg 7 out 0. I can manipulate with high and low command, but cannot use pin0 as I would like to. Problem is using piezo speaker and wish to drive between two output pins to effectively increase voltage across the device. I have output on pin4 and wanted to use a command like pin0=pin4 xor $1 to make pin 0 the complement of pin 4.

Any suggestions? I am using pin1, pin2 and pin3 as inputs. I have thought of a transistor "invertor" driven by pin4 and connecting the piezo across the input and output of the invertor, but that is extra circuitry. Alternately, I have considered a cmos NAND gate or cmos invertor chip, but that adds more complexity. I really would like to do it within the 08M chip if at all possible. I have VERY little program space left -- not enough to use high and low and an if statement to check pin4.

Thanks for any suggestions.
 

hippy

Technical Support
Staff member
External logic or bit-banging are your only practical options. If you are out of program space there's only really the option of external hardware.

#Picaxe 08M
SetFreq M8
Low 4
Do
For w0 = 0 to 1000 ' Lower volume
pins = %00001
pins = %00000
Next
For w0 = 0 to 1000 ' Higher volume
pins = %00001
pins = %10000
Next
Loop
 

vttom

Senior Member
I am trying to output to leg 7 out 0. I can manipulate with high and low command, but cannot use pin0 as I would like to. Problem is using piezo speaker and wish to drive between two output pins to effectively increase voltage across the device.
Exactly how does driving it from 2 pins get you more voltage drop compared to driving one side from the PICAXE and tying the other side to GND or VDD?
 
Last edited:

RadioBob

New Member
Why the voltage is effectively doubled

Exactly how does driving it from 2 pins get you more voltage drop compared to driving one side from the PICAXE and tying the other side to GND or VDD?
Well, the piezo goes from 4.5 v (say pin 4) to gnd (on say pin 0), then by switching the 4.5 v to gnd and the gnd to 4.5 v, you have swung the piezo across 9 v as far as its inputs are concerned. This is twice the swing that you can get from one pin and gnd. I hope this explains what I am trying to achieve.

Bob
 

RadioBob

New Member
External logic or bit-banging are your only practical options. If you are out of program space there's only really the option of external hardware.

#Picaxe 08M
SetFreq M8
Low 4
Do
For w0 = 0 to 1000 ' Lower volume
pins = %00001
pins = %00000
Next
For w0 = 0 to 1000 ' Higher volume
pins = %00001
pins = %10000
Next
Loop
Well, I'm not completely out of program space -- but I only have about 5 bytes available. If I could address pin0, I have enough space to xor with pin4 I think, but pin0 doesn't seem to be defined as pin1 through pin4 are. That is what I am seeking -- some way of manipulating pin0 with logic, not just low pin0 or high pin0.

I must admit, I don't see that the program provided gives me any insight into my problem. Did I miss something? Can I set "pins=pin4 xor %00000001" to set leg 7 to complement of pin4? This passed syntax check but unfortunately exceeded the program space left!

Thanks for the info!

Bob
 

Technical

Technical Support
Staff member
outpin0=pin4 xor $1

Technically this shouldn't work, as it is reading the state of the pin 4 input buffer, which is not theoretically the same as the state of the pin 4 output driver. But in practice it does often work as the input buffer drifts to whatever the output buffer state is -try it!
 
Last edited:

RadioBob

New Member
Thanks, Technical. Good idea, but I'm afraid I didn't have enough memory left for that even. I guess I am back to a hardware solution -- either a single transistor and a couple resistors, or a cmos NAND, NOR or inverter gate. It means modifying my board a bit to add this -- I was hoping to achieve it in software and leave the board the same. This is for a morse code practice set for my amateur radio licensing class.

Thanks all that responded!

Bob VE3SUY
 

vttom

Senior Member
Well, the piezo goes from 4.5 v (say pin 4) to gnd (on say pin 0), then by switching the 4.5 v to gnd and the gnd to 4.5 v, you have swung the piezo across 9 v as far as its inputs are concerned. This is twice the swing that you can get from one pin and gnd. I hope this explains what I am trying to achieve.

Bob
Oh, I get it. Technically, you're not really increasing the swing to 9v. When 1 pin is hard-wired to VDD or GND, then you're driving it on/off/on/off. With both pins are driven differentially, then it's going forward/reverse/forward/reverse. What you're really doing is doubling the duty cycle.
 

BeanieBots

Moderator
@ vttom. The voltage swing is doubled, the duty remains the same.
It's an age old classic method of quadroupling the power output.

@VE3SUY.
Adding a single inverter (possibly using a NAND or similar) is your best. It could be done with a single transistor but just one transistor would only be able to conduct in one direction. Drive in the other direction would be limited to whatever you used as a pull-up load resistor. That would impact on your total available power and also be quite inefficient. To build a full inverting totem-pole output stage with descrete trnaistors would use more board space than adding a 14-pin gate/inverter chip.
It is possible to get single gates in very small SMD packages.
 
Top