08M2 and pin C.3 as output

Svejk

Senior Member
If the need arises the pin C.3 (marked as input only) on 08M2 [and maybe other Picaxes] may be used as an output.

The setup involves a fet and a pull-down resistor as shown attached. The 1M resistor pulls the input to ground. Enabling the pullup for C.3 will make the pin go high, activating the fet.

Test code:

Code:
#picaxe 08m2
pullup $08
do:loop
PS: The serial download, power and decoupling capacitor circuits are left out for simplicity in schematics. I didn't have a 08M2 in library so I've used 08M.
 

Attachments

Last edited:

Svejk

Senior Member
Honestly, I don't know, how can I tell? I bought that desk of TradeMe a few years back from an just retiring lawyer and it makes a very good lab desk.
 

Svejk

Senior Member
That is a good question, when I tested I just pulled one from my junk box and once I've seen it working I tossed it back.
 

techElder

Well-known member
While quite novel, I would think that having the FET sitting there with a 1 MEG resistor on it's front side would make the switch susceptible to electrical "noise" turn-ons.

The problem I encounter more lately is "noise" from all of these new fluorescent bulbs of unknown manufacture.
 

nanogear

Member
While quite novel, I would think that having the FET sitting there with a 1 MEG resistor on it's front side would make the switch susceptible to electrical "noise" turn-ons.

The problem I encounter more lately is "noise" from all of these new fluorescent bulbs of unknown manufacture.
Maybe shielding the inside of the enclosure with conductive paint could save the circuit from noise
 

inglewoodpete

Senior Member
...I would think that having the FET sitting there with a 1 MEG resistor on it's front side would make the switch susceptible to electrical "noise" turn-ons.
Maybe shielding the inside of the enclosure with conductive paint could save the circuit from noise
When we start going to these lengths, I think it's time to have a rethink. I don't want to detract from the original idea: the concept of using an input's internal pullup resistor to create a makeshift output in quite ingeneous.

If I was designing a PICAXE-based circuit and needed one more output than the 08M2 could provide, I would use the 14M2. If space is really tight, I'd consider the SMD version.

Lets compare:
Code:
                       08M2 solution  14M2 solution
Benefit                 1 extra I/O    6 extra I/O
Extra components*          2                0
Extra holes to drill       5                6

* extra components have to be handled, stored, positioned and soldered
However, I think the idea has merit if you have an existing circuit and need to add another function by modding the existing board and not building an entire new board.
 
Last edited:

westaust55

Moderator
No, appears that it will not work.

Although there is a weak pull-up resistor on PIC pin RA5 = PICAXE pin C.5 = SERIALIN pin and we have the DISCONNECT command, If you look in PICAXE manual 2 under the PULLUP command for the 08M2 it indicates that only C.0 to C.4 are valid pins. 08M2 pin C.5 is not available for PULLUP.
 

AllyCat

Senior Member
08M2 pin C.5 is not available for PULLUP.
Hi,

But has anyone actually tried writing directly to the WPUA SFR (20Ch)? I appreciate that the PICaxe firmware may overwrite the value on occasions, but this might not preclude its use as an output. After all, Manual 2 is slightly "misleading" concerning PULLUP on the 14M2 because it lists pins which don't exist!

Cheers, Alan.
 

hippy

Technical Support
Staff member
08M2 pin C.5 is not available for PULLUP.
But has anyone actually tried writing directly to the WPUA SFR (20Ch)?
And there's always more than one way to skin a cat ...

b0 = $FF : PullUp b0

Hiding what is being done so the compiler can't tell nor complain about that doesn't mean it will always work, but in this case appears to, at least setting the bits in WPUA.

As to using C.5 as an output; you might have to jump through some hoops to get it to work without the PICAXE going into download mode or never getting out of it on power-cycling or reset.
 

Goeytex

Senior Member
While quite novel, I would think that having the FET sitting there with a 1 MEG resistor on it's front side would make the switch susceptible to electrical "noise" turn-ons.
The "noise" would have to bring the gate voltage higher than the gate threshold voltage for the MOSFET. Consider that we use 1meg and higher resistors in op-amp feedback circuits all the time.

In any case, the 1meg resistor can be reduced as long as voltage to the gate of the MOSFET exceeds the gate threshold voltage plus about 1 volt when the pullup is activated. A true logic level FET is preferred. For a 2N7000 FET with a typical gate threshold voltage of 2.1v, a 250K resistor should work fine.

I have one florescent lamp/ magnifier that when in close proximity to a breadboard with a Picaxe circuit causes the download to fail. Nothing wrong with the breadboard circuit, just a weedy lamp. Cheap imported junk from you know where. I stopped using it except for soldering .
 
Last edited:

erco

Senior Member
This related thread demonstrates that the internal pullup resistor value is around 35K ohms, which helps to visualize how Svejk's circuit works. 35K ohms is small compared to a full megohm. With the pullup off, the external 1 megohm resistor simply pulls the gate to ground and the MOSFET is off. With the pullup on, the internal 35K is in series with, and forms a voltage divider with the 1 megohm resistor, applying ~97% of Vdd to the gate, turning it on. Very useful, and thanks again Svejk.
 

dmaxben

Member
Old thread...but I had a question.

I assume this would work with a P-channel mosfet too?

I have a 14m2 driving a 7-segment common cathode LED display. Im short one output...so I was thinking...would it be possible to use C.3 with a P-channel mosfet to give +5v to the anode side of one of the 7 segments in the LED display??
 

AllyCat

Senior Member
Hi,

Presumably you're already using B.0 (Serial Out)?

Yes, in principle it should work, provided that the P-channel is switched ON with the 1 Mohms to Earth, and OFF with the gate at a few hundred millivolts below the supply rail (or vice versa for a depletion mode type).

But are you multiplexing the display? A MOSFET driven via a 1 Mohm resistor may not switch very fast, so you might see some "ghosting" of the segment in a fast-multiplexed display.

Cheers, Alan.
 

LKiwi

New member
pullup $08
I have a circuit up and working, basic "moister tester", Was wondering if I could drive a very small dc water pump using a BC377 NPN and Input pin C3? Holding C3 high with pullup.
The purpose would be to water a small container when it needs. I am using a 08M2, obviously I could use a bigger chip but have already set up and wonder if I can extend functionality. Breadboard without proposal attached. Code below, my first time posting.
Code:
symbol varA = w0

main:
    do
      call Moisture_Check
      do
        do
          if varA >= 200 then
            call Red_Led
          endif
        loop until varA < 200
        if varA >= 120 then
          call Yellow_Led
        else
          if varA >= 200 then
            call Red_Led
          endif
        endif
      loop until varA < 120
      call Green_Led
      sleep 1
    loop
    stop

Moisture_Check:
      let varA = 0
      readadc C.4, varA
    return

Red_Led:
      if varA >= 220 then
        high C.0
        pause 3000
        low C.0
        pause 2500
        readadc C.4, varA
      else
        high C.0
        pause 1000
        low C.0
        pause 1500
      endif
      call Moisture_Check
    return

Yellow_Led:
      if varA >= 150 then
        high C.1
        pause 3000
        low C.1
        pause 2500
      else
        high C.1
        pause 1000
        low C.1
        pause 1500
      endif
      call Moisture_Check
    return

Green_Led:
      high C.2
      pause 3000
      low C.2
      pause 1500
      call Moisture_Check
    return
 

Attachments

Last edited by a moderator:

AllyCat

Senior Member
Hi,

Welcome to the forum. It depends on the exact rating of the pump/motor but probably not reliably with a single BC337. The pullup resistor is typically 35k but the base PIC data sheet indicates that it could be much higher (IIRC 200k+). Thus the collector current may be limited to 10 mA or less, so I suggest a FET as above, or a pair of BC337s in a Darlington or emitter-follower driver configuration.

Cheers, Alan.

EDIT: The above was composed on my mobile phone so is perhaps mercifully concise for quite a complex issue. ;)

To "expand" on the detail, the Microhip data sheet specifies the pullup current to be between 25 and 300 microAmps with a supply of 5 volts and the pin at zero volts (~page 323 of the 08M2 "base PIC" data sheet). Many microcontrollers actually have "(Constant) Current Source" outputs (i,e, the current might be typically 100uA whether the pin is at zero or 4 volts) but the Microchip pullups do appear to be "normal" resistors, so we can calculate their value (from Ohms Law R = V/I). Thus the pullup resistors might be anywhere between 200k and 17k, but in practice they seem to be "nearly always" around 30k - 35k.

Thus the 1 Mohm pulldown suggested above for a FET is not unreasonable; if only 100k had been chosen then the voltage divider would be 35k : 100k and we would lose over a volt drop to the gate of the FET. Beware that not only is a "logic level" FET required, but their "Threshold Voltage" specifies the highest voltage where the FET may still be "OFF", so several more volts might be needed for it to conduct "well" (i.e. with a low voltage drop at a reasonable current).

For "low" voltages a bipolar transistor may be preferable because its base-emitter voltage is always around 0.6 volt so it will receive most of the available current from the pullup resistor. But bipolar transistors have a finite current gain (collector current divided by base current) of usually around 100, but a value nearer to 20 may be necessary if we want to use it as a "switch" with a low voltage drop. Hence my comment above that the collector current might be limited to 10 mA (i.e. 4v / 40k * 100 = 10 mA).

A "Darlington" configuration uses two similar (NPN or PNP) bipolar transistors with their collectors connected together and one emitter connected to the other's base. Using the remaining emitter and base (and the common collectors) it behaves like a transistor with a high current gain, similar to the product (multiplication) of their gains, i.e. over 1,000. However, it has two restrictions, the base-emitter voltage is doubled (i.e. to about 1.2 volts) and the lowest Vce "saturation" voltage is about 600 mV (because below this, the output transistor "steals" the base current from the first, via its collector diode). These somewhat compromise its behaviour as either a "switch" (emitter grounded) or as an emitter follower (collectors connected to the supply).
 
Last edited:

inglewoodpete

Senior Member
I have a circuit up and working, basic "moister tester", Was wondering if I could drive a very small dc water pump using a BC377 NPN and Input pin C3? Holding C3 high with pullup.
The purpose would be to water a small container when it needs. I am using a 08M2, obviously I could use a bigger chip but have already set up and wonder if I can extend functionality. Breadboard without proposal attached. Code below, my first time posting.
Welcome to the PICAXE forum.

Something that you need to consider when using a permanently inserted moisture sensor "probe" is the electrolytic impact of (minerals in the) moist soil on the metal probe. With passing time corrosion may occur, resulting in changing resistance of the probe/soil interface. Potentially, this can result in failure of the probe. You may need to have some spare probes or, at least, periodical checking/testing of the probe.
 

LKiwi

New member
Welcome to the PICAXE forum.

Something that you need to consider when using a permanently inserted moisture sensor "probe" is the electrolytic impact of (minerals in the) moist soil on the metal probe. With passing time corrosion may occur, resulting in changing resistance of the probe/soil interface. Potentially, this can result in failure of the probe. You may need to have some spare probes or, at least, periodical checking/testing of the probe.
using solid core wire so only a small portion of the wire is exposed, the code requests an occasional reading, thus is not constantly on. It is for a plant container so does not need to be always on. This should extend the life of the probes. Keeping an eye on them to see how durable this setup is, after a month still functioning perfectly which hardly any degradation. It's a bit of an experiment.

Thanks for your input
 
Last edited:

LKiwi

New member
Hi,

Welcome to the forum. It depends on the exact rating of the pump/motor but probably not reliably with a single BC337. The pullup resistor is typically 35k but the base PIC data sheet indicates that it could be much higher (IIRC 200k+). Thus the collector current may be limited to 10 mA or less, so I suggest a FET as above, or a pair of BC337s in a Darlington or emitter-follower driver configuration.

Cheers, Alan.
Thanks Alan, will investigate and have a fiddle with it and see if it works. using the test code from above Pin c3 is outputting about 0.69V down to 0.66V at the collector (3V supply). Tried to jerry rig a pulldown resistor 4.7M Ohm (don't have 1M ohm at the mo) but no change. Setup is now on Picaxe Proto board kit.
Will have to figure out the code to add. Pin3 = C3 Which is of course actually the 4th pin ;) just to clarify for myself.
3V pump similar to https://www.amazon.co.uk/gp/product/B07WDTCMNC/ref=ppx_yo_dt_b_asin_title_o05_s00?ie=UTF8&psc=1
Thanks again
Lyle
 
Last edited:

hippy

Technical Support
Staff member
My understanding is that passing an alternating current through the soil sensor can help to avoid erosion.

That can be achieved by controlling both ends of the sensor with PICAXE I/O pins and alternatively switching one end high and low with the other as the inverse. One end can be set low to 0V and the other end read to take an actual reading.

That might mean a larger PICAXE but would also give additional I/O pins to avoid the complexity of trying to use an input-only pin as an output.

Putting AC through the soil sensor should even be possible with an 08M2.
 

AllyCat

Senior Member
Hi Lyle

I've expanded my reply in #26 which may give a better indication of what can be expected from a "Weak Pullup" output.

Unfortunately the specification for your linked pump doesn't appear to indicate a typical running current, or even its dc resistance. The dc resistance (which I'd guess to be a few ohms) is useful to estimate the "stall" current of the motor (which might be about an Amp), simply by using Ohms Law. The stall current is higher than the norml running current, but might be needed briefly to overcome the "static friction" of the motor/pump and "kick it into life". Thus you should assume a drive current of up to an Amp, until you can measure the requirement more accurately.

We can learn a little more from the specification: The flow is 120 litres/hour which equals 2 per minute or about 33ml (cc) per second. That's about the same volume as an AAA cell each second, and would weigh 33 grammes. If we assume a lift (head) of 30 cms (the maximum is quoted as 40 - 110) then the "work" would be 33 * 30 = 990 grm.cms/second, say 1 kg.cm/second or about 0.1 watt. If its efficiency were 100% then the motor would need about 33mA (at 3 volts) but the efficiency of a tiny motor/pump will be much less, perhaps only 10%. That suggests the running current might need to be around 300 mA, reasonably typical for a motor of that type.

For that current at 3 volts you might struggle to drive either a FET or a "compound" (Darlington) transistor from a WPU output. So I'd suggest two separate (BC337 type) transistors, one on C.3 driving one of the LEDs from the Weak Pullup ("PULLUP 8") and another (perhaps a PNP BC327) on the C.2 output (which can deliver a full drive of 10 - 20 mA) to feed the motor at the hundreds of mA probably needed. Another advantage of C.2 is that it can be set as a PWM output to control the speed or current drain of the motor.

Cheers, Alan.
 
Top