[C.CC USERS] The operation of "digital.input" and Plumbing debugging
Steve Pretty
steve.g.pretty at btinternet.com
Thu Jan 20 16:32:19 GMT 2011
I am interested in trying to write some extra "functional blocks" to use
with plumbing - things like timing elements and counters. I am thinking
of simulating the link of blocks you would have in an IEC 61131
Programmable Logic Controller. I was looking at using the digital.input
process (in the digital.module) as a part of this idea. In the
documentation comments, it states:
This procedure will output a LEVEL (either LOW or HIGH) whenever
the**pin changes value.
I am not convinced the process works as described. I tried the code:
PAR
digital.input(2, v!)
digital.output(13, v?)
If digital.input works as described, I would expect the LED to follow
the button - i.e. come on when the button is pressed, and go off when it
is released - but it does not. What happens is the LED comes on the
first time the button is pressed, but stays on thereafter, whatever you
do with the button.
I then created a PROC using the very low level digital.read to get the
value of pin 2 - this version of code works as expected.
I think what is happening here is that digital.input process is
interrupt driven. It is designed to work with the external interrupt
pins of the microcontroller (arduino uno pins 2 and 3). The interrupt
mode can be set to LOW, CHANGE, RISING or FALLING. I have not yet
figured out where (or if) you set the mode - but it looks to me that you
are using RISING mode, rather than CHANGE. If that is the case,
digital.input will always read the pin after the rising edge, so can
only ever send a HIGH, never a low.
This is consistent with the behaviour of the button programme in the
Plumbing book:
button.press --> pin.toggle
Which expands to
digital.input --> debounce --> level.to.signal --> pin.toggle
With this programme, the LED comes on when the button is pressed the
first time - stays on when button is released (showing there is no
message from digital.input on button release). The second time the
button is pressed the LED goes off.
I am guessing you will want to change the comment rather than having to
rework the book examples. It would, however, be useful to have a
digital.input that would send a HIGH and a LOW.
While I was wrestling with this issue, I became aware of how tricky it
is to debug code in this environment (wish I had an in circuit emulator
to hand!) My instinct was to add serial.write statements to the code to
show what was coming out of Digital.input - but alas, I have not been
able to get the Printing.module to work. Something is sent - I do get
some random characters appearing in occplug. I am guessing that the
serial port in not correctly configured. Do I have to use the
serial.start proc to initialise things - if so, which pin(s) to I have
to configure, and how do I know what Baud rate is required? (The serial
link is obviously working OK for the code loading phase).
Final thought for the day - I have read about a tool that you were once
working on called POPExplorer - basically a visual programing
environment for occam. Is there any ongoing work on that - it would make
an interesting front end for plumbing.
Regards
Steve
More information about the users
mailing list