Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.
DaveC166 Regular Member Joined: 13/09/2012 Location: New ZealandPosts: 44
Posted: 06:07pm 31 Aug 2014
Copy link to clipboard
Print this post
Hullo
My Umite HRV controller is making progress. however I am having trouble checking the status of digital output pins 9 and 10.
The statement IF PIN(9)=1 or Pin(10)=1 Then pulse 24,50 causes the error not an input pin and the Umite resets.
Is there correct syntax for using the state of an output pin in an IF statement
jman Guru Joined: 12/06/2011 Location: New ZealandPosts: 711
Posted: 07:09pm 31 Aug 2014
Copy link to clipboard
Print this post
Hi
The reason you get the error is because your pins are set as outputs and to use the
If PIN(x)=x the pins MUST be set as inputs.
If you are setting the outputs can you not keep track of the state that you set the pin to.
If you post your code here I am sure the smart people here will have a solution
Regards
Jman
Grogster Admin Group Joined: 31/12/2012 Location: New ZealandPosts: 9501
Posted: 07:36pm 31 Aug 2014
Copy link to clipboard
Print this post
As jman says - pin needs to be told it is an input first. This is NORMALLY done at the top of the code, before the main loop or loops.
SETPIN 9,DIN:SETPIN 10,DIN will set pins 9 and 10 to be inputs.
Note that you also have to declare the pin you are using for pulse, as an output first, for exactly the same reasons as the inputs.
SETPIN 24,DOUT
If you make those two changes to your code, the rest of your code should work.
Smoke makes things work. When the smoke gets out, it stops!
DaveC166 Regular Member Joined: 13/09/2012 Location: New ZealandPosts: 44
Posted: 08:41pm 31 Aug 2014
Copy link to clipboard
Print this post
Thanks for the replies. Pins 9,10,24 are set to DOUT. Pin 24 pulses a led, Pins 9 and 10 are connected to MOC3021 triac optocouplers . I was trying to port as much code from a PICAXE 28x2 as I could. PICaxe basic allows the state of an output to be tested in IF statements.I guess I will have to set up variables to track the state of output pins in MM Basic.
Grogster Admin Group Joined: 31/12/2012 Location: New ZealandPosts: 9501
Posted: 09:00pm 31 Aug 2014
Copy link to clipboard
Print this post
You only need the first of my lines in bold then.
I don't normally need to change the pin state in my applications, but that is just me - I tend to assign pins a certain task from the outset, and not double-up on pins by making one pin an input in one loop, and an output somewhere else kind of thing.
Not to say you can't/shouldn't do that - it's up to you, but as you have discovered, you will need to track the pin's state.
You could do this as simply as with a flag:
flag_pin24=1, then just check that flag if you need to change it from output to input kind of thing at the time. Logic 1 could mean output or input, depending on how you assign the flag, but the opposite would be the other.(if 1 was output, then 0 would be input)
Smoke makes things work. When the smoke gets out, it stops!
WhiteWizzard Guru Joined: 05/04/2013 Location: United KingdomPosts: 2927
Posted: 09:04pm 31 Aug 2014
Copy link to clipboard
Print this post
Hi Dave,
Another possible solution (if you have two spare I/Os) is to keep pins 9 & 10 as outputs and then connect each of them to the two 'spare' pins which are both set as inputs. Then you can use the IF statement on the Input pins then everything will work ok.
This is not necessary the 'best' solution - but it is a solution that works quickly (but only if you have two spare pins) that you may not have thought about.
Let us know how you resolve your IF statement . . .
WW
DaveC166 Regular Member Joined: 13/09/2012 Location: New ZealandPosts: 44
Posted: 09:27pm 31 Aug 2014
Copy link to clipboard
Print this post
I have altered my code so that if I set a DOUT pin to 1, I set a flag variable to 1. This gets around not being able to use the state of a DOUT pin in a IF statement.
ajkw Senior Member Joined: 29/06/2011 Location: AustraliaPosts: 290
Posted: 10:12pm 31 Aug 2014
Copy link to clipboard
Print this post
If you had a suitable pull up resistor on the pin then this may be a solution.
x = {valid digital pin number}
setpin x,oout
pin(x) = 1
print pin(x)
pin(x) = 0
print pin(x)
paceman Guru Joined: 07/10/2011 Location: AustraliaPosts: 1329
Posted: 04:43am 01 Sep 2014
Copy link to clipboard
Print this post
Dave,
watch the 15mA (max) trigger current requirement for the 3021. The MicroMite 150 chip spec quotes a source/sink max of 10mA. It might be OK but you could also use MOC3022's (max 10mA trigger) or MOC 3023's (max 5mA trigger).
Greg
DaveC166 Regular Member Joined: 13/09/2012 Location: New ZealandPosts: 44
Posted: 09:45am 01 Sep 2014
Copy link to clipboard
Print this post
thanks
Ive got 220 ohm resistors between the Umite output and the MOC3021 input.