Having trouble using 08M2 Pin C.5 as an input...

FlashnSmoke

New member
My program, used with an 08M2, is supposed to branch to one of 16 different addresses as determined by the pre-set position of a gang of 4 DIP switches on start up. Each branched address instructs pin C.2 as an output pin. The input pins connected to the DIP switches are C.4,C.3,C.5, and C.1. Each pin has an external 10k ohm pull down resistor and each goes high with its associated switch. I am aware of some of the complications with using pin C.5 as an input pin. The program begins with a DISCONNECT command and has a 1 second pause before it checks the position of the switches. The program is flashed to the 08M2 using a separate development board. I I have mastered the hard reset procedure.

My program branches to the eight addresses just fine when pin C.5 is low, but just quits whenever C.5 is held high by its associated DIP switch. What am I doing wrong? Is there another way to do this branching without using pin C.5?

Thanks
 

PhilHornby

Senior Member
C.5 needs to be low until the disconnect statement is issued - else it goes into Program Download mode immediately on power-up.

Does that fit the symptom you're getting?

(Otherwise we need to see the code and schematic :unsure: )
 

AllyCat

Senior Member
Hi,
but just quits whenever C.5 is held high by its associated DIP switch.
Welcome to the forum. Yes, as Phil says, the program doesn't "quit", it never starts (so can't execute the DISCONNECT) if C.5 is High when power is applied. BTW, it's not good practice to connect any (output-capable) pin directly to the supply rail (e.g. via a switch) without a series resistor, because the PICaxe or its pin-driver could be destroyed if the Program accidentally sets the pin as an output. Using a pull-down switch is marginally safer because the "short-circuit" pull-up current is lower than the pull-down. Also, a pull-down switch can use the (optional) internal "Weak Pullup" resistor without needing an external (pull-up) resistor.

There are several ways to use fewer pins, as described in posts #11 and #21, etc. of this very recent thread. In particular, by creating an analogue voltage level and using an ADC input, or by using "tri-state" input levels to select 27 options with 3 pins (3 * 3 * 3).

Cheers, Alan.
 

FlashnSmoke

New member
"the program doesn't "quit", it never starts (so can't execute the DISCONNECT) if C.5 is High when power is applied."

Do you think it might be possible to use a capacitor (In parallel with the pullup resistor) on the C.5 pin to delay the high state on that pin long enough for the DISCONNECT command to execute?
 
Last edited:

AllyCat

Senior Member
Hi,

Yes in principle you could use a (quite large) capacitor to delay the voltage rise, but you would need a selector switch or configuration links to prevent the capacitor shorting out the programming signal, so there are probably better solutions.

The method I normally use is to connect the additional switch via a diode to the programming pin, such that it (or an external pull-down resistor) can only pull the pin down (i.e. anode to PICaxe) so that it cannot directly activate the Programming sequence. The procedure is to execute the DISCONNECT and then activate the PICaxe's internal Weak Pullup Resistor on the programming pin. If the cathode of the diode is Low, then the C.5 will remain low and read as zero, but if it is High then the WPU resistor pulls the pin High and it reads as a 1. An advantage is that at any time the Program can disable the WPU resistor and execute a RECONNECT, so the PICaxe is ready to receive a new program download, without the need for the Hardware Reset procedure.

However, a few tricks may be needed: The WPU resistor is typically 30k ohms (and might be significantly higher) so it may be necessary to increase the 10k programming resistor to around 100k, which should still work fine. Other changes may be needed to allow both Programming and the new Switch to be read independently, without interfering with each other. Another issue is that the PICaxe Programming Editor will not accept a direct PULLUP 32 (or %100000) command for the Programming pin (because it might unintentionally crash or Reset the Program). However, the PE can be fooled by using a variable, for example: b1 = 32 : PULLUP b1 , or by writing directly to the chip hardware with a POKESFR $8C , $20 command for the 08M2.

Cheers, Alan.
 

FlashnSmoke

New member
Thanks again. The 08M2 used for this device (Calibration pulser for analog Geiger counters) is to be programmed on a separate board, so this simplifies the situation a bit.
 

hippy

Ex-Staff (retired)
Another option if you have a spare pin is to use that to control what effect the switch has on the Serial In pin -
Code:
                            \
                   .------O  O------.
                   |                |
            ___    |   .--------.   |
RX >---.---|___|---^-->| SI     |   |
      .|.              |     IO |---'
      |_|              `--------'
       | 
0V ----^-----------------------------
So long as the "IO" pin becomes an input when powered-up a closed switch won't affect any download which might be received before the PICAXE starts executing previously downloaded code. Once the downloaded program is running it can issue a DISCONNECT and then make the "IO" pin an output high. The Serial In (C.5) will then read high if the switch is closed, will be pulled low by the 22K+10K if not.
 
Top