Using PIN serial in, like normal input, without response serial output

ok1if

New Member
Friends, I apologize for perhaps incompetent question. However, I am a beginner. For certain applications need to be used in the circuit 08M2 PIN C.5 (Serial IN) as a common input responsive LOG 0 and LOG1. In all experiments, however, when the status of input from log0 to log1 raises output response C.0 like it was programmed. However, since the output C.0 used as common output and this reaction was found to me. You can not use this input so that the circuit was not seen as an attempt to programming circuit? Thank you.
Milan Stejskal
 

darb1972

Senior Member
Hello ok1if

Welcome to forum. Never apologise for asking questions. It's all part of the learning curve.

Please see the DISCONNECT command. PICAXE manual 2, page 61. Be aware that using this command stops the PICAXE chip from scanning the Program Serial In Pin and requires a hard reset to reprogram the chip. Also see the RECONNECT command.

Also, depending on how you are using the Serial In pin might also require you to "switch" (maybe via a dip switch or jumper) between the hardware/circuitry needed for programming (refer to Manual 1) and the hardware/circuitry you might require on your input in normal operation.

I am not sure I understand what you are asking about C.0? Are you saying that because you are trying to use C.5 Serial In as an input, you are also getting unwanted activity on C.0? Maybe try the DISCONNECT command and see if that resolves the issue.

Regards
Brad
 

westaust55

Moderator
Further to the information provided by Darb above, for the C.5 input (SerialIn) pin, this pin MUST be held low until the DISCONNECT command is performed.
Even if the DISCONNECT command is the very first line in the program, from power up through the firmware initialisation to performing that command will take of the order of 50 to 100 msec.

Thereafter, pinC.5 is available only as a digital input.

Like Darb, I am unsure what you are asking with respect to the pin C.0.
This pin can always be used in a program as an output either: (a) as a digital output or (b) as a DAC output (DAC = Digital to Analog Converter) - the DISCONNECT command is not required to allow this use.
 

darb1972

Senior Member
Further top the information provided by Darb above, for the C.5 input (SerialIn) pin, this pin MUST be held low until the DISCONNECT command is performed.
Even if the DISCONNECT command is the very first line in the program, from power up through the firmware initialisation to performing that command will take of the order of 50 to 100 msec.
Thanks for adding that Westy. I didn't realise that was necessary prior to a DISCONNECT. Good to know. I'm still on the learning curve too!!!

Regards
Brad
 

AllyCat

Senior Member
Hi,

Like Darb, I am unsure what you are asking with respect to the pin C.0.
I think the issue is that if the serial (programming) input is taken High before the DISCONNECT command is executed, then the PICaxe takes its Serial Output pin High as a "Reply" to what it thinks is a request to download a new program.

So to summarise, it is essential that the Serial Input pin is NOT allowed to rise to a "Logic 1" level until after a DISCONNECT is executed by the program.

However, the need then for a "Hardware Reset" to reprogram after using a DISCONNECT, is something else that causes many newcomers serious confusion. They often believe (incorrectly) that they have destroyed their PICaxe so, as hippy often suggests: it's usually better to begin with something simpler. ;)

Cheers, Alan.
 

darb1972

Senior Member
Hello Westy/Alan

I am curious, how does one keep the Serial Input low until the DISCONNECT command is processed? Is this meant to be done with hardware or simply done in the software? I would like to further my understanding of this process. Is it as simple as something like;

Code:
Initialise:

Low C.5
Pause 100
Disconnect
;code
;code
;etc
 
Last edited:

AllyCat

Senior Member
Hi,

No, it generally MUST be done with some form of external hardware. The first thing that a PICaxe does before it executes any program code is to check the level on the serial input pin. If the level is High (logic 1) then it enters the program/download mode, which it confirms by raising the Serial Output pin High.

If the "Auxiliary" input might be High during the first few hundred ms after power is applied (or if the PICaxe resets for any other reason), then basically it's necessary to put a logic "gate" (of some form) in series with the "auxiliary digital input" on the Programming Input. Generally one would fit a hardware switch of some type, but it may be possible to use just a diode or a careful choice of resistor values to act as the gate. Of course nearly all the pins of an M2 or X2 are "floating" (configured as inputs) during the starting sequence, so the controlling input of the "gate" would need to be biassed to the "gate closed" mode by a resistor. Then when the DISCONNECT has been executed the controlling pin can open the gate. But that might require an additional pin, which largely defeats the whole object of trying to use the serial input as an additional pin !

I do have a method to allow the PICaxe to gate a logic signal onto the serial input pin, without the need for another pin, but it's quite an "advanced" method: Firstly, the programming signal (which must remain low at all times except when actually programming) needs to be connected to the programming input by a much higher resistance than the usual 22k (say 100k or more). Then the auxiliary digital signal is connected to the programming input via a diode, so that it can only pull the input Low (i.e. anode to the pin).

The "trick" then is for the program to execute a DISCONNECT and then enable the "Weak Pullup Resistor" on the programming input pin. That value is quite high (about 30 k) which is why it was necessary to increase the input pull-down resistance. Now, the pin can rise to a High level, unless the auxiliary input pulls it Low (via the diode).

Unfortunately there's one more twist: the PE won't accept a PULLUP command for the programming input pin :( So it's necessary to use a POKESFR command, which for 08, 14 and 20 pin M2s is: POKESFR WPUA,%00100000 or simply POKESFR $8C,32.

Cheers, Alan.
 

darb1972

Senior Member
Hello Alan

Thanks for the detailed response. All of that makes perfect sense to me.

One last thing, you mentioned that the PE won't accept a PULLUP command. You have to poke the registry. Is this to use the internal pullup when the serial in pin is being used as a normal input or is this to return it to being a serial in for programming? What is the purpose of RECONNECT? Does it do something similar?

Thanks again.

Regards
Brad
 

AllyCat

Senior Member
Hi Brad,

Virtually all PIC pins/chips have Weak Pullup resistors, but the "nanny" PE gives an "error" message and won't enable it for the Programming Input (nor Output) pins. The reason is to protect "novices" because (even with an external 22k series resistor) the PULLUP might cause the chip to enter programming mode and Reset/Restart.

POKESFR doesn't write to a "regsitry", it's just to one of many registers (not really very different to the RAM/Byte variables) which control how the "silicon" (chip) hardware works. Actually, many "normal" PICaxe commands do little more than write directly to a SFR, not just PULLUP, but PINSx, DIRSx, CALIBFREQ, DACLEVEL, ADC configuration and many others.

RECONNECT simply "undoes" the DISCONNECT and allows the PICaxe to be programmed normally again, without a Hard Reset. Personally, I always try to include a RECONNECT whenever possible (in particular after using SERRXD, which issues a hidden DISCONNECT); it's possible to disconnect and reconnect as many times as you like!

Cheers, Alan.
 

darb1972

Senior Member
Ok thank you very much Alan.

That was extremely helpful. I hope the OP didn't think I was hijacking his/her thread but at least my questions and your (and Westy) answers remained extremely relevant to the subject at hand.

Thanks again for the explantion. Each and every bit helps me (and others) to have a deeper and more comprehensive understanding of the inner workings of these amazing little uControllers.
 

westaust55

Moderator
What i have done on some projects where no permanent programming circuit is included is to use a 100 kOhm pull down resistor.
That is sufficient to enable the PICAXE to start and operate correctly.
If a programming circuit (e.g. AXE029) is added the 100 kOhm does not cause a problem to programming.
Then I can use a switch between the positive supply and the input (open at power-up) or other digital logic(low at power-up) to drive the "SerialIn" pin.
 

ok1if

New Member
Dear Friends. Thank you for helping. Now my project using input C.5 without problem.
Milan Stejskal
 

zorgloub

Member
Good evening at the Forum,
Having needed to use the TX input of the small Picaxe 08M2 as a "normal input" I came across this post among others, so I'll post it again.

In Post #7, AllyCat correctly answered that it was then necessary to keep the TX pin in the LOW state (to avoid going into re/programming mode) for a DELAY just necessary for the previously loaded programme to start normally.
After this delay, the TX pin can then be used as a "normal input".
He was then referring to the need to put a "logic gate" (of one form or another) in series with the programming input (TX).

This idea of a logic gate came into my mind and I obviously thought of an AND gate: one of its inputs would be kept LOW for the necessary delay (so that TX would be Low during this delay).
Then this input would go HIGH and so the other input of the AND gate can be used as the auxiliary input in normal digital mode.

And here, I immediately think of charging a capacitor through a resistor on one input of the AND gate.
At start up, the voltage is at zero, and rises gradually to reach the HIGH level which then allows the other input of the AND gate to be used as the « normal digital input » desired.

However, a problem remained to be solved: in the event of a micro power cut (and therefore a reset of the MCU) it is absolutely necessary to instantly discharge the capacitor so that the delay will be the same on restarting.

So I thought about it and I propose you the attached diagram.
There may be simpler... to be discussed...

The AND logic gate consists of diodes D1 and D2.
The delay is a function of the R and C values.

The immediate discharge of C in the event of a micro-break is ensured by the BS170, itself controlled by the inverter gate constituted by the 2N2222.
This gate will remain powered during power failure by the 470µF capacitor.
D3 prevents the voltage present in C from acting on the BS170.
D4 prevents the voltage present in the buffer energy reserve (C.470µF) from keeping the RC circuit charged.
The input of the inverter gate (2N2222) scans the value of the supply voltage.

We look forward to hearing from you to continue the discussion, if you wish...

Happy New Year to all.
 

Attachments

AllyCat

Senior Member
Hi,

Thanks for your interest. Yes I am a great "fan" of the 08M2 which can be very capable for even quite complex applications. However, a 14M2 only "covers" another 12 "holes" of a standard (0.1 inch) matrix circuit board , i.e. an extra area of 0.12 square inch (about 75 square mm). That extra circuit needs at least 28 "holes" even if the resistors and diodes are mounted vertically. Also, the 14M2 has twice as many I/O pins, four times more RAM, TABLE memory, RF commands, etc. and many other potentially useful features for quite a modest increased price. ;)

Sorry about my "ASCII Art" (which used to look better with the "old" forum software) but here is what I proposed in post #7. Provided that the "Gate" input is High at the time, the PICaxe can be programmed normally. Also, the PICaxe boots up normally (when power is applied) because the diode is reverse-biassed so the serial input pin must remain low. Then, the program Disconnects the Programming capability and Enables the internal Weak Pullup resistor on the pin. This brings the diode into conduction and the (serial) input pin then "follows" the Gate Logical input. The WPU is of course disabled when the Power (Vdd) rail is cycled, or with a PULLUP OFF.

Code:
                           _______
                          |o  U   |  
    Vdd ------------------0----+  0-----@---Vss
                          |    |  |    _|_ 
             100k         |  on%  |    ///
 SI -->--@---/\/\---@-----0--+ |  0--------->SO
         |          |     |  | |  |
         |    |/|   |     | W/ |  |
GATE -->-|----< |---+   --0 P\ |  0-<>-SCL )
         |    |\|         | U/ |  |        }-I2C
         /                |  | |  |        ) 
      10k\          IO ->-0  +-+  0-<>-SDA )
         /                |_______|
        _|_                  08M2   
        ///   

CODE:
#picaxe 08M2
init:
   disconnect		 ; Disable scanning for a new Program
   b0 = %100000		 ; "Weight" of Pin c.5 (Leg2)
   pullup b0         ; Enable pullup on pin c.5
; ......
My original idea used a POKESFR WPU,32 command to Enable the Pullup resistor, but somebody on the forum recently showed that the PE can be "tricked" to Enable the WPU (and/or Interrupts) on that pin, by using a variable (b0) with the 08M2 (but not the 14M2 or 20M2). In practice, this circuit may work with the original 22k programming resistor (which is why the PE won't directly enable the WPU on that pin) particularly when the programming adapter is removed (i.e. with a 32k pull-down resistance). But to "guarantee" that it always works, I prefer a resistor of around 47k - 220k. Sometimes I connect the cathode of the diode (i.e. the "gate" input) to pin C.2 (Leg 5) which is the PWM (and Comparator, etc.) output. This allows a "timed interrupt" or an external analogue level, etc. to generate an interrupt.

Cheers, Alan.
 

zorgloub

Member
Hi,
Thank you for the follow-up and the small diagram that sets the ideas well.

In your Post #7 you wrote: "Unfortunately there's one more twist: the PE won't accept a PULLUP command for the programming input pin So it's necessary to use a POKESFR command, which for 08, 14 and 20 pin M2s is: POKESFR WPUA,%00100000 or simply POKESFR $8C,32. »;
The 08M2 is therefore affected by this impossibility to connect an internal pullUp.
(PS: What does PE mean?)

In your last intervention you then specify a method allowing you to do without the POKESFR $8C,32 command by the particular use of the variable b0 ( b0 = %100000)
_Q1 How can this variable b0 act on a PullUp resistor that seems not to physically exist in 08M2/C.5?
_Q2 Especially since b0 could well be worth %100000 in other common "normal" circuits using an 08M2.
What would happen in this case?
 
Last edited:

zorgloub

Member
Continuing my research, I have reviewed the Pic12F1840 data sheet (platform of the 08M2 Picaxe) and I see that indeed, there is the possibility to configure six Pull-Up, distinctly, on each of the ports (WPUA register).

This register must have a value of %xx100000 to activate the only Pull-Up of C.5.

So, I'm still just wondering how writing b0 = %00100000 (and then Pullup b0) allows direct access to this WPUA register (and why not an another register?) ??
If you have an explanation, I'll take it ;)

And according to note1 (see attached picture) the OPTION register seems to have to be configured as well ?
 

Attachments

Last edited:

AllyCat

Senior Member
Hi,
a PullUp resistor that seems not to physically exist in 08M2/C.5?
The pullup resistor DOES exist on pin c.5 of the "base PIC" but the Program Editor "refuses" to set it because it might cause a "confusing" Reset if a novice accidentally set it. The PULLUP command is rather "confusing" anyway because it uses a single "mask" to set all the (legitimate) resistors in a single instruction.

Actually ALL the pins in the base PICs of the 08M2, 14M2 and 20M2 have Pullup resistors (but only portB in the 18M2) but the PE (Program Editor PE5 or PE6) chooses not to Enable them on the Serial Input and Output pins. The "trick" for the 08M2 (and probably 18M2) is that the PE does not check the contents of a variable (because in most case it cannot "know" its value at the time of compilation). Unfortunately, you can't use the trick with the 14M2 and 20M2 because the PE will say "Error: 'pullup' command only uses constants, not variables!". The reason is because these PICaxe chips use different Port.Pin names for the pins compared with the base PIC (and presumably there wasn't enough program space to do the conversion).

To answer your subsequent question; The PULLUP command is basically just a POKESFR command, as are some other of the PICaxe "Setup" type commands. It happens that the "top" 8 pins (i.e. Legs 1 - 4 and those on the other side) are called "PORT A" in the base PICs of the 08, 14 and 20 pin M2s. That is why we use the POKESFR WPUA , <bitmask> command. To control the WPUs of the 14M2 and 20M2 chips by POKESFR commands, you need to look at the base PIC data sheets to see the internal Port A , B or C pin numbers (i.e. WPUA, WPUB and WPUC) compared with the PICaxe Port.pin names.

Cheers, Alan.
 
Last edited:

zorgloub

Member
Alan,
Ah, our messages have crossed ;)

As I was saying, I did indeed see that the 6 Pull-Up were configurable by the WPUA register.
So I was wondering how the simple command b0=%00100000, followed by pullup b0, allowed a direct access to this register (and why not another one).
And if I understood correctly, these two simple lines of code allow to do without PokeSFR commands?

And last (?) question: do the "usual" programming resistors of 10K and 22K have to be placed on your circuit for the system to work properly?
Indeed, if I program the picaxe on a free support, outside the circuit, these two resistors will not be placed on my circuit.
 

Attachments

Last edited:

inglewoodpete

Senior Member
The input pin needs to be pulled low during bootup. Bootup in this situation is best described as between the first opcode contained in the PICAXE's firmware and when the "Disconnect" command is commenced. It is only when the "Disconnect" command is being executed that the firmware takes it eye off the state of the SerIn pin with respect to detecting a perceived pending download. Lots of words: I hope it makes sense.
 

zorgloub

Member
Alan,
In your post #7, you write:
<<It's necessary to use a POKESFR command, which for 08, 14 and 20 pin M2s is: POKESFR WPUA,%00100000 or simply POKESFR $8C,32. >>

It seems to me that according to the Pic 12F1840 (08M2) Data Sheet, the register $8C is for TRISA (configure DIR i/O), but the WPUA register (pull-up R) is at address $20C!

Shouldn't the SFR Command therefore be POKESFR $20C,32?
Am I wrong?
 

Attachments

AllyCat

Senior Member
Hi,
And last (?) question: do the "usual" programming resistors of 10K and 22K have to be placed on your circuit for the system to work properly?
No, the 22k + 10k resistors are not needed, but programming should still be satisfactory if they ARE used, in addition to the 100k + 10k shown in my diagram. However, my intention was that the 100k + 10k would be used to replace the 22k + 10k (i.e. basically the 22k is changed to 100k).

As IWP says, the Serial (Programming) Input needs to be "Pulled Low" to allow the PICaxe to boot up correctly. However, there is "nothing" pulling the input High, except perhaps "static electricity" and a tiny leakage current (uA or nA), so a very High resistance value should be adequate. The normal programming circuit gives 32k (22k + 10k) Pull-Down, and mine gives 110k (100k + 10k), but even 1 Mohm (i.e. 1000k) is probably sufficient. For ANY "custom PCB" design I ALWAYS recommend arranging a (typically) 100k resistor between the Serial Input (Leg2) and Ground (or of course the normal programming circuit). Then it is always easy to Re-Program or Reset the PICaxe.

"Stop Press": Yes the PIC SFR address is $20C but the PICaxe Basic Interpreter converts it (and all SFR values) to a BYTE value ($8C) as explained in the POKESFR Command Syntax ("M2 Parts"). ;)

Cheers, Alan.
 

zorgloub

Member
Thank you Alan,
I must confess that I did not fully understand the final explanation, in the manual, of this POKE SFR command as regards its value divided into two groups of bits (3 bits + 5 bits).

According to the table in the attached drawing, WPUA has the address 20Ch in BANK 4. (OK?)

So, OK for the first three bits (BANK 4) = %100 = $4 = 4

But I have only 5 bits, effectively insufficient to contain the however exact value 20C which is enormous and would then be equal to %10 0000 1100 !

I see however that the address 00Ch (%1100) is taken from the first column, BUT that I consider (badly?) to be an address belonging to BANK 1 (=PORTA) and not to BANK 4 (=WPUA)!?
 

Attachments

AllyCat

Senior Member
Hi,

From the PIC data sheet the address of WPUA is 20Ch , which in PICaxe nomenclature is $20C , or splitting the "Hex" characters into 4 bit groups gives % 0010 0000 1100 . However, if you look lower down in each Bank, the data from $20 (decimal 32) is not "useful" (i.e. repeated RAM or "Unimplemented"). Therefore, the PICaxe SFR-byte conversion "ignores" the bits associated with these higher "registers" and multiplies the Bank Number by 32 (or $20). So "Bank 1" starts at 32 and "Bank 4" starts at 128 ($80).

Thus the PICaxe Editor/Compiler calculates M2 SFR addresses from : $80 (i.e. % 1000 000) added to $0C (i.e. % 0000 1100) = $8C (i.e. % 1000 1100). Or another way to consider it is that the PE just "ignores" the middle bits, i.e. the full address %10 0000 1100 becomes the byte : %1000 1100.

Cheers, Alan.
 

zorgloub

Member
Thank you Alan.
You are a well of knowledge!

Thank you for your enriching contributions!
I will now test and implement all of this.

It's very handy to "earn" an extra entry on this little 08M2.

@+++
 
Top