dirsC mystery

Aries

New Member
#1
I am baffled ...

The following is a very much cut-down version of a multi-slot program on a 28x2, where the LED combinations indicate which slot is active. For some reason, the yellow LED (on pin C.1) never lights when the real program runs. The code below lights all three LEDs, but when the "let dirsC" is executed, the yellow one goes out. The print of the status of C.0 - C.2 shows 111 before the dirsC and 101 afterwards. The simulator shows 111 both times (which is what I would expect). Any thoughts?

Roger

Code:
#picaxe 28x2
#no_table
#no_data

symbol LC_RED 	= C.0
symbol LC_YELLOW = C.1
symbol LC_BLUE = C.2

pause 1000

high LC_RED
high LC_YELLOW
high LC_BLUE

pause 1000

sertxd(#pinC.0,#pinc.1,#pinC.2,CR,LF)

let dirsC = %11100111

pause 2000

sertxd(#pinC.0,#pinc.1,#pinC.2)

end
 

Buzby

Senior Member
#2
Are you sure C.1 is wired correctly ?

Try writing a simple code to turn each LED on/off individually, like :

high lc_red
pause 1000
low lc_red
pause 1000
high lc_yellow
pause 1000
etc ...

Cheers,

Buzby
 

Aries

New Member
#3
Absolutely sure. For a start, the yellow one comes on at the beginning of the program, and only goes off when the dirsC statement is executed. However, I have done as you suggested and ...

the first set of high/low lights each LED in turn. After the dirsC, red and blue light up in their correct turn, but yellow does not.
 

Buzby

Senior Member
#4
Hi Roger,

I've run your code exactly as written, on a real 28X2, and all three LEDs stay lit.

My suspicion is still some difference in the wiring of C.1 compared to the others.

Why exactly do you need the 'dirs' instruction ?. It's unusual to need to alter the direction registers.

Cheers,

Buzby

EDIT : What result do you get if you change the dirs to let dirsC = %00000111 ?
 
Last edited:

Aries

New Member
#5
Thanks, Buzby for giving me the clue. There was a tiny sliver of uncut copper between C.6 and C.1. Now working as intended.

Roger
 

Buzby

Senior Member
#6
Glad you got it working !.

I was heading in that direction when I suggested removing the three upper bits from the dirsC instruction.

With those bits set pins C.7, C.6, and C.5 would change to outputs when dirs executed, thus putting '0's out where before they were inputs.

The '0' from C.6 would then short circuit the '1' from C.1, so the LED would not light.

Connecting '0' and '1' pins like this usually leads to a dead pin due to overcurrent, but PICAXE chips are quite hardy and can survive abuse like this, as long as it's only for a short time.

It is worth checking that C.6 is still working properly.

Cheers,

Buzby
 

Aries

New Member
#7
Hi Bizby,

Following your suggestion, I have checked C.6 and it still appears to be working. I'm rather surprised, because I would have had C.1 on for a long time while I was trying to find the fault. As it happens, C.6 is "reserved for future use", so the short had no impact on the rest of the program.

As far as using the dirsC instruction is concerned ...
I am nearly always short of code space in my projects, and a dirsX instruction uses less space than three or more "output" instructions. I do realise that "high" and "low" instructions make a pin into an output, but some of my code is of the form "pinX.n = xxx" and so would need an "output" as well. It may only be a byte or two, but every little counts.

Roger
 

AllyCat

Senior Member
#8
Hi,

C.6 .. still appears to be working. I'm rather surprised, because I would have had C.1 on [low] for a long time
I'm not surprised for the case of two output pins shorted together, because the pullup (P-channel) FETs are not particularly "strong", so you'd be very unlucky for a "damaging" current to flow. It might be a different story if the pin were shorted directly to the supply rail (and driven low). The more recent data sheets from Microchip for the M2 base PICs show the I/V characteristics of the output devices at 5, 3 and 1.8 volts, in graphs towards the end of section 31. The 1.8 volt curves might give you quite a fright if you believe that "a PICaxe pin will supply 20 mA".

But I am surprised that it's "necessary" to use the DIRs command to save program memory space. However, there are a few "greedy" commands such as BINTOASCII, PWMDUTY and READINTERNALTEMP (if anybody ever bothers to use it) where the use of a subroutine can reduce the program size considerably. ;)

Cheers, Alan.
 
Top