Index by Themes Glossary of System Commands Glossary of 'Avise 4.3' I/O Commands(updated 11 December 2005)
For every command, a "stack comment" added: Note: in the following text, "argument" or "operand" means TOS for postscript operations, "first argument" or "left argument" means NOS, "second argument" or "right argument" means TOS, the same order Forth stack comments are written. The phrases "returned" and "pushed" mean as much as "put on the stack" whereas "popped" means "taken from the stack". AIN( b -- X )(only for CPU models with built-in ADC) Start one single measurement of the ATmega internal ADC converter. The multiplexer input is selected by the argument <b>.
Resolution of the analog inputs is 10 bit, i.e. lower 10 bits of the result (at some inputs of the ATmega8 bits 0 and 1 are uncertain). CØZ( -- )Resets CNTØ and ENCØ to zero. No arguments, no return value. C1Z( -- )Resets CNT1 and ENC1 to zero. No arguments, no return value. CNTØ( -- X )The negative pulses on the INT0 input (PortD,3) are permanently counted in a background process. CNTØ reports the present value of this counter. Circular overflow behaviour. Counter is reset with CØZ See also ENCØ CNT1( -- X )The negative pulses on the INT1 input (PortD,3) (with ATmega32) --- or ICP input (PortB,0) (with ATmega8 or ATmega168) are permanently counted in a background process. CNTØ reports the present value of this counter. Circular overflow behaviour. Counter is reset with CØZ See also ENCØ ENCØ( -- X )Similar function as CNTØ, but the counter is incremented or decremented depending on the present level of a second input: PortB,8 (with ATmega32) --- or PortD,7 (with ATmega8 or ATmega168). Circular overflow and underflow behaviour. Counter is reset with CØZ This function is useful together with 2-phase rotary encoders. When used with mechanical encoders, these must be debounced with appropriate external hardware! ENC1( -- X )Similar function as CNT1, but the counter is incremented or decremented depending on the present level of a second input: PortD,4 (with ATmega32) --- or PortD,3 (with ATmega8 or ATmega168). Circular overflow and underflow behaviour. Counter is reset with C1Z This function is useful together with 2-phase rotary encoders. When used with mechanical encoders, these must be debounced with appropriate external hardware! IACK( -- T|F )Sends the I2C ACKNOWLEDGE command on the I2C interface. TRUE=1 is returned, if slave does acknowledge. FALSE=0 is returnded, when acknowledgement fails. User has to decide how to handle FALSE answer. IMACK( -- )Sends the I2C ACKNOWLEDGE command on the I2C interface. TRUE=1 is returned, if slave does acknowledge. FALSE=0 is returnded, when acknowledgement fails. User has to decide how to handle FALSE answer. IP( portbit -- )Sets one bit at the specified microcontroller I/O port (PORTx register, DDRx register) as INPUT with PullUp resistor ("SOFT HIGH"). This kind of configuration is appropriate to connect simple switches to the microcontroller and as a short-safe output for loads with very low current consumption (up to 100uA) Example: $D5 IP the same with decimal argument & 208 5 + IP In contrast to WPORT and WDDR, this is a single line write operation. Comment on port bit coding see RIO. IRECV( -- b )Receives one byte through the I2C interface performing the "current read" method without ACK. Note that this is a receive primitive. According to the I2C protocol, further commands have to be executed previously to ensure correct read address; and further commands may have to be hooked after to close the interface correctly. Refer to the I2C protocol of the specific device to be read. ISEND( b -- )Sends one byte via the I2C interface without ACK. Note that this is a send primitive. To perform a real write operation to the I2C interface, a sequence of further commands is necessary. Refer to the I2C protocol of the specific device to be written. ISTART( -- )Sends the I2C START command on the I2C interface. The I2C interface is shared with the program EEPROM, which is not necessarily used with Avise4. Because I2C chips have individual device addresses, normally this will not cause conflicts. The I2C bus of 'Avise' operates with 100 kHz clock speed. So it can be used together with all standard I2C equipment, sometimes not at the highest possible speed. ISTOP( -- )Sends the I2C STOP command on the I2C interface. IZ( portbit -- )Sets one bit at the specified microcontroller I/O port (PORTx register, DDRx register) as INPUT with high impedance ("HiZ"). In contrast to WPORT and WDDR, this is a single line write operation. Comment on port bit coding see RIO. OH( portbit -- )Sets one bit at the specified microcontroller I/O port (PORTx register, DDRx register) as OUTPUT HIGH. In contrast to WPORT and WDDR, this is a single line write operation. Comment on port bit coding see RIO. OL( portbit -- )Sets one bit at the specified microcontroller I/O port (PORTx register, DDRx register) as OUTPUT LOW. Example: $D0 OL the same with decimal argument & 208 OL In contrast to WPORT and WDDR, this is a single line write operation. Comment on port bit coding see RIO. PWM1( X -- )Start the AVR Timer1, OC1A in 8 or 10 bit PWM mode. PWM1 generation is stopped when any of the commands IP,IZ,OH,IL is applied to the corresponding OC1A output of the microcontroller or when the WAVE command is executed.
Example:
Resolution, setting of base frequency and output waveform are contained in one single argument:
The respective PWM output (CPU dependent) is set as output by 'Avise' firmware.
The argument has to be composed as follows:
PWM2( X -- )Start AVR Timer2 in 8 bit PWM mode. PWM2 generation is stopped when any of the commands IP,IZ,OH,IL is applied to the corresponding OC2 output of the microcontroller.
Example:
Setting of base frequency and output waveform are contained in one single argument:
The respective PWM output (CPU dependent) is set as output by 'Avise' firmware.
The argument has to be composed as follows:
RIO( portbit -- T|F )Reads one byte from the specified microcontroller I/O port (PINx register) tests the questionned bit and returns the result conditionned as a boolean flag TRUE=1 or FALSE=0. Example: $B3 RIO the same with decimal argument & 176 3 + RIO ;
Port and bit are coded in byte b as follows using hexadecimal numbers: the upper nibble describes the port and may have the hex values B,C,D. (A is allowed for kernel versions with ATmega32 only). The lower nibble describes the I/O number of this port (0 ... 7). This scheme is attractive, because the hex numbers are synonymous with the Atmel data sheet enumeration. RPIN( ABCD -- b )Reads one byte from the specified microcontroller I/O port (PINx register) and puts the result on the data stack. Example: $B RPIN the same with decimal argument & 11 RPIN The addressed port is specially coded in byte "ABCD": it describes the port name and may have the hex values A,B,C,D. (0x0A is allowed for kernel versions with ATmega32 only). The PINx register readout is returned without further filtering. Note that not all port lines are physically available and some of the available ones may have special functions, which do not represent user I/O.In contrast to RIO, this is a multiple line reading byte operation. WAVE( X -- )Sets the total period duration and starts the AVR Timer1 as frequency generator with a high phase period defined by WAVEHI. WAVE generation is stopped when any of the commands IP,IZ,OH,IL is applied to the corresponding OC1A output of the microcontroller or when the PWM1 command is executed.
Example:
Before starting WAVE, the high phase MUST be set with WAVEHI. When WAVE is already busy, every part can be changed independently. The high phase, however, must not be greater or equal than the total period.
Frequency range is about:
The WAVE period can be changed in units of time (per increment/decrement of argument):
Port OC1A (CPU depdendent) is set as output by 'Avise' firmware. WAVEHI( X -- )Sets the duration of the high phase of WAVE: in units of about 32 microseconds (@ 8MHz clock) in units of about 16 microseconds (@ 16MHz clock) in units of about 13.89 microseconds (@ 18,432MHz clock) WDDR( b ABCD -- )Writes one byte into the data direction register of the specified microcontroller I/O port. Example: $ FF D WDDR the same with decimal argument & 255 13 WDDR In contrast to IP,IZ,OP and OL, this is a multiple line write operation. The addressed port is specially coded in byte "ABCD": it describes the port name and may have the hex values A,B,C,D. (A is allowed for kernel versions with ATmega32 only). Note that not all port lines are physically available, and some are locked against user access as there are: serial interface and I2C control lines. WPORT( b ABCD -- )Writes one byte into the port register of the specified microcontroller I/O port. Example: $ 36 C WPORT the same with decimal argument & 54 12 WPORT Comment see at WDDR |