SETPIN

Compatible with:
DOS Maximite CMM MM150 MM170 MM+ MMX Picromite ArmiteL4 Armite F4 ArmiteH7 Picomite CMM2

Syntax:
SETPIN pin, cfg [, option]
SETPIN pin, cfg, target [, option]

Description:

SETPIN pin, cfg [, option]
Will configure an external I/O pin.
'pin' is the I/O pin to configure, 
‘cfg’ is the mode that the pin is to be set to and 
'option' is an optional parameter. 
'cfg' is a keyword and can be any one of the following:
OFF     Not configured or inactive
AIN     Analog input (ie, measure the voltage on the input). 'option' can be used to specify the number of bits in the conversion (only on the CMM2).
Valid values are 8, 10, 12, 14, and 16. The default (if not specified) is 16 bits. The more bits the longer the conversion will take. 
A single conversion takes between 0.2mSec (8-bit) to 0.9mSec (16-bit).
DIN     Digital input
If 'option' is omitted the input will be high impedance If 'option' is the keyword "PULLUP" a simulated resistor will be used to pull up the input pin to 3.3V 
If the keyword "PULLDOWN" is used the pin will be pulled down to zero volts. The pull up/down is a constant current of about 50uA
FIN     Frequency input
'option' can be used to specify the gate time (the length of time used to count the input cycles). It can be any number between 10 ms and 100000 ms. 
Note that the PIN() function will always return the frequency correctly scaled in Hz regardless of the gate time used. If 'option' is omitted the gate time will be 1 second.
PIN     Period input
'option' can be used to specify the number of input cycles to average the period measurement over. It can be any number between 1 and 10000. 
Note that the PIN() function will always return the average period of one cycle correctly scaled in ms regardless of the number of cycles used for the average.
If 'option' is omitted the period of just one cycle will be used.
CIN     Counting input 
On the CMM2, pin 18 is a 'fast count' pin. You can specify a Basic interrupt that will fire when the COUNT exceeds &HFFFFFFFF. 
This allows you to trigger an interrupt when a specific number of COUNTs have happened. See the example code for how this works
DOUT     Digital output
'option' can be "OC" in which case the output will be open collector (or more correctly open drain). 
The functions PIN() and PORT() can also be used to return the value on one or more output pins .


Previous versions of MMBasic used numbers for 'cfg' and the mode OOUT.
For backwards compatibility they will still be recognised.
See the function PIN() for reading inputs and the statement PIN()= for
setting an output. See the command below if an interrupt is configured.

SETPIN pin, cfg, target [, option]
Will configure ‘pin’ to generate an interrupt according to ‘cfg’. Any I/O pin capable of digital input can be configured to generate an interrupt with a maximum of ten interrupts configured at any one time.
'cfg' is a keyword and can be any one of the following:
OFF     Not configured or inactive
INTH    Interrupt on low to high input
INTL     Interrupt on high to low input
INTB     Interrupt on both (ie, any change to the input)
‘target' is a user defined subroutine which will be called when the event happens. Return from the interrupt is via the END SUB or EXIT SUB commands. 
'option' can be the keywords "PULLUP" or "PULLDOWN" as specified for a normal input pin (SETPIN pin DIN). If 'option' is omitted the input will be high impedance.
This mode also configures the pin as a digital input so the value of the pin can always be retrieved using the function PIN().

 

CMM2, fast count pin example:

'connect pins 18 and 36
PWM 2,1000,50
SETPIN 18,CIN,myint
PIN(18)=&HFFFFFFFF-2047
TIMER=0
PAUSE 1024
PRINT HEX$(PIN(18))
DO:LOOP

SUB myint
PRINT "done",TIMER
END SUB


 

Last edited: 25 February, 2021