08M2 actual pin4 change to adc function?

Rampz

Well-known member
Hello All, looking at altering an existing project that uses a 08m2, currently actual pin4 or C3 is and can only be an input i understand, what i want to do requires it to have ADC function, i seem to remember some pins can be made to do functions that they normally can't do, is there anyway to make pin4 or C3 have ADC function?
 
Last edited:

hex

Member
My understanding is that PICAXE08M2 is the same thing as PICAXE08M2+

Either way - No

PICAXE08M2+ is based upon PIC12F1822, which can only have ADC on pins 3, 5, 6 and 7

Pin 4 can only be MCLR or an input on PIC12F1822. PICAXE08M2+ is configured such that pin 4 is always an input, never MCLR.

What you want is not possible

EDIT: PICAXE08M2+ is of course PIC12F1840, not PIC12F1822. Many thanks to hippy for correcting my error
 
Last edited:

AllyCat

Senior Member
Hi,

No, not the conventional READADC command because the hardware just isn't present on that pin. However, it is on pins C.4, C.2, C.1 and indirectly on C.0 (using READDAC or some POKESFR+PEEKSFR commands).

Also, pin C.3 does have a partial Output function by enabling the Weak Pullup resistor (e.g. to drive a FET), or you might be able to cobble up a simple ADC function by adding a capacitor and high value resistor between C.3 and ground. Enable/Disable the Pullup and measure (loop-count) the time until the input logic level changes.

Cheers, Alan.
 

hex

Member
AllyCat has a devious and inventive mind.

I like it.

Had to think hard

Pin 4 CAN be an output of sorts

- but lets's pretend that this is not true
For my own sanity; I will continue to consider pin 4 as input only and not ADC capable
 

Rampz

Well-known member
Thank you for the replies from all the picaxe gods on here, its an existing project I wanted to adapt, being a pcb it's much harder to rearrange uses of pins, will play on a blank 08m2 and reconfigure when looking at another run of pcbs, Thank you all again for your answers and creative thinking.
 

hippy

Technical Support
Staff member
PICAXE08M2+ is based upon PIC12F1822, which can only have ADC on pins 3, 5, 6 and 7
My understanding is the 08M2+ is based on 12F1840, the 08M2LE was 12F1822, but the same with respect to I/O.

And, for all PICAXE which have an "Input Only" pin, they really are, will only accept a Digital Input, though tricks with pull-ups can create a pseudo output pin which may be useful in some cases.

But ADC, no.

If a PCB has been built where it was thought Leg 4, C.3, could be used as ADC, one fix may be to simply jumper that pin to another which has ADC. You lose other use of both pins but it may save the day.

Another trick is to build a strip-board circuit which plugs into the socket which routes the socket pins to suitable legs on the PICAXE. That can sometimes be easier than cutting tracks and creating cross-overs.
 
  • Like
Reactions: hex

AllyCat

Senior Member
Hi,
... one fix may be to simply jumper that pin to another which has ADC. You lose other use of both pins but it may save the day.
That might be a problem if all of the pins are fully allocated, but there are a number of tricks that might "free up" a pin or allow it to be shared between functions. Firstly, C.5 and C.0 have primary defined "Programming" functions, but may be used as secondary digital inputs, and C.0 even as an ADC input.

Then, a single pin might share an input and output function. For example a white or blue LED wired on a pin, probably won't significantly affect an ADC (or digital) input level up to (or down to) about half of the supply voltage. Also there are various "multiplexing" solutions, perhaps the simplest being to wire one LED to 0v, another to the supply rail and activate one with a High or Low output as appropriate.

Cheers, Alan.
 

lbenson

Senior Member
Also, pin C.3 does have a partial Output function by enabling the Weak Pullup resistor (e.g. to drive a FET)
This is clever, and I have an immediate use. Can you provide code (are pokes required?) and suggest a suitable n-ch mosfet (preferably one which would work at 3V3)?
 

AllyCat

Senior Member
Hi,

Generally, a PULLUP command is all that you need, i.e. PULLUP %1000 or PULLUP 8. However, if you want to control multiple Pins/Pullups independently, or either of the two Programming pins (C.0 or C.5), then it may be better to write a subroutine using POKESFR commands, because the PICaxe interpreter won't allow you to PULLUP the Programming pins.

It depends how much FET current you want to sink, but you should probably put around a 1 Mohm pulldown resistor on the pin anyway. The internal Pullup resistors are around 33 kohms (although the data sheet implies they might be much larger) so connecting the pin directly to an NPN base will give around 100 uA and a collector current similar to a normal PICaxe output pin, with any supply voltage. I rarely use FETs and cannot recommend any one in particular, but sometimes use a 2N7000 which generally should sink a few hundred mA at Vgs = 3.3v.

Cheers, Alan.
 

lbenson

Senior Member
Thanks. I should have specified what I would like to be able to power: an ESP32 S2Mini, which would be powered off most of the time, but would be brought back up to send a temperature change detected by the 08M2 (or other signal, such as motion-detected or additional temperature sensors). If I can use C.3 plus a fet to enable 0V on the S2Mini, then another pin would be freed for more flexibility.

I had read that a 2N7000 would not switch reliably at 3V3--but I'll try it and see. I currently have an IRL7833 wired up (not yet tested), but I'd prefer a TO-92 package.

I will probably ultimately design a PCB for a 14M2 or 20M2, but I had an 08M2 handy.

This is for a low power, battery operated design. I know I can get very low power with a PICAXE running at the slowest speed.
 

hippy

Technical Support
Staff member
if you want to control multiple Pins/Pullups independently, or either of the two Programming pins (C.0 or C.5), then it may be better to write a subroutine using POKESFR commands, because the PICaxe interpreter won't allow you to PULLUP the Programming pins.
When the compiler refuses to accept something like "PULLUP %10001" that can often be worked round by using "b0 = %10001 : PULLUP b0".

While, in theory, a compiler could figure out what's in a variable up to the point it's used, that's so challenging to do without creating false positive and letting things through which it shouldn't, it's rarely deemed worth the effort.
 

erco

Senior Member
This is clever, and I have an immediate use. Can you provide code (are pokes required?) and suggest a suitable n-ch mosfet (preferably one which would work at 3V3)?
Forumista Manuka first posted about this when the M2s first came out, I thought it was amazingly clever. Many sharp minds here!

I like Allycat's RC timer too. Another thought I had was to configure an external VCO, possibly using the venerable old 555 timer. Lots of sample circuits out there. Feed your analog signal into that and let the Picaxe count the frequency to determine the voltage.
 
Top