14m problem reconfiguring inputs

fojinpic

New Member
hi all !

My project involves a picaxe 14m which spends a sedentary life waking up from a sleep loop roughly every 10 seconds to check if there is any input voltage/high on input2[portc 5 or fifth pin down from + or leg 5 ref manual]. This input comes from a timing capacitor[2mohm/10mf;; normal state discharged] connected to input 2 so that whenever pic wakes up there will be a high recorded if an externally operated switch has charged the timing capacitor while pic was asleep.

main:
sleep 3
if input2 = 1 then goto dothis
goto main

dothis:
etc etc ' just few commands, very little time involved
goto main

All works okay if I initially leave the pic in its default input\output state[ie inputs on the left outputs on the right]. My problem is when I start reconfiguring the inputs/ using the "let dirsc =" or "input" commands. There appears no problem reconfiguring and using the reconfigurable/portc pins as outputs. I need portc 3 and 4 as outputs[these remain as outputs]. However after the initial waking up and checking input2 high I also need capacitor to be rapidly discharged which I do by making this reconfigurable mentioned above [low portc 5] low. I then need this pin changed to an input again, to recognize further operation of the switch\charge of capacitor... which is the ultimate problem!

main:
sleep 3
if input2 = 1 then goto dothis ' capacitor has been charged
goto main

dothis:
low portc 5 ' to discharge the capacitor through it
pause 100
let dirsc = %00011111 ' set pin back to input[ dream on!]
pause 5000 ' just for testing;; time to operate switch and charge capacitor again
goto main

[ code has been simplified eg in reality I know when pause and sleep begins so that the capacitor is not discharging for too long before it wakes up]

With the coding above, and with the capacitor charged, the first time I switch on the pic the input2 command is recognized ie as high and triggers dothis .the low portc 5 command also discharges the capacitor. However the moment the let command is triggered to make this an input again, going back to main[ and with the capacitor now charged again during the pause command], the "if input2 = 1" will not be recognized again. It just loops indefinitely back to sleep. And the moment I released the switch the capacitor is immediately discharged[ I assume because the pin is remaining an output\low??] Exactly the same thing happens if I use "if portc5 = 1;; will be recognized on the first pass even before any dirsc command is mentioned in the coding, but not when it goes back to main after the first pass.

I have also tried just setting it individually without any use of dirsc eg leaving it out completely and after the low portc 5 command inserting "input 2" [ as it says in the basic commands section of the manual] or even trying " input portc 5 " and pretty well any other combination I can think of. the program simply will not accept the input command [ message box saying input is not available in this mode]. The manual says these inputs can be manipulated, the type of chip selected in the options box is correctly set at 14m, I try a similar thing with an 08m and everything is accepted and works fine. I must be doing something wrong?? Because everything goes pear shaped the moment I use dirsc with picaxe 14m, or the moment I use these configurable pins as an output I cannot set them back to an input again

Any comments or suggestions ?? Just tell me it is a known fault and you will hear me scream from there!
 

Technical

Technical Support
Staff member
Try this program, which looks at the the portc direction register TRISC directly after the two commands questioned.

Code:
main:
low portc 5 
peek $87,b1
pause 100
 
let dirsc = %00011111 
peek $87,b2
 
debug
pause 1000 
goto main
You will see that bit5 of the PIC TRISC register ($87) does change correctly from input to output as expected (NB 1=input, 0=output in TRISC, which is the inverse of dirsc). So the issue must be elsewhere, what is your circuit diagram?
 

hippy

Ex-Staff (retired)
let dirsc = %00011111
peek $87,b2

You will see that bit5 of the PIC TRISC register ($87) does change correctly from input to output as expected
Could this be a mapping issue because of the way the 14M pins are numbered which is different to the PORTC outputs -

RC0 : Out 3
RC1 : Out 4
RC2 : Out 5
RC3 : In 0
RC4 : In 1
RC5 : In 2

If so, a workround could be -

dothis:
low portc 5
pause 100
Peek $87,b0
let dirsc = b0 ^ %11111011
pause 5000
goto main
 

Technical

Technical Support
Staff member
Don't think so Hippy, our understanding is that this is all about normal input2, RC5.
Your code alters RC2. The command 'if input2 = 1 then...' always reads RC5.

this code works as expected
Code:
main:
if input2 = 1 then
b4 = 1
else
b4 = 0
end if

low portc 5 
peek $87,b1
pause 100
let dirsc = %00011111 
peek $87,b2
debug
pause 1000 
goto main
 
Last edited:

hippy

Ex-Staff (retired)
D'Oh ! I'm looking at the wrong side of the chip !!! Got my RC2/Out5, RC5/In2 swapped over :)
 

fojinpic

New Member
Thanks for responses. At least I know everything SHOULD work. I think I'll strip everything away and just do a test simply on the input and send the circuit diagram if I still have the same problem.
 
Top