BIOS Interface
The BIOS interface functions are listed below. Using those interface functions, you can easily access the hardware resource of Pico-2. (Note that uchar below stands for unsigned char; ushort for unsigned short; uint for unsigned int.)
- Download: BIOS source program
-
PWM: DC motors (PWM, DIR)
- void PWM_init (void)
Initializes PWM module. Motors 0~3 become PWM=0 and DIR=0. You must call this function before using PWM module. - void PWM_set (uchar numB2, short valW)
Apply voltage (Vmp × valW ⁄ 32768) to motor numB2. When valW is plus, the motor turns CW; otherwise, CCW.
- void PWM_init (void)
-
ENC: encoders (A・B)
- void ENC_init (void)
Initializes ENC module. For motors 0~3, the encoder values become 0 (therefore, POS=0). You must call this function before using ENC module. - int ENC_get (uchar numB2)
Reads the encoder of motor numB2. The encoders are 24bit counters, but this function returns it the value as a 32bit signed interger. - void ENC_set (uchar numB2, int count)
Forces the current value of the encoder of motor numB2 to be count. The value of count should be in 32bit signed integer but the value should be with in 24bit signed integer range.
- void ENC_init (void)
-
SEN: current sensors (SEN)
- void SEN_init (void)
Initializes SEN module, starting periodical cycles of A/D conversion on the four analog input channels (SEN0~3). You must call this function before using SEN module. - ushort SEN_get (uchar numB2)
Reads analog value of SEN input of the motor numB2. The return value is in unsigned short, so 0xffff stands for 5V and 0x0000 for 0V, from which you can estimate the current going through the motor. - void SEN_gets (ushort *sen0W, *sen1W, *sen2W, *sen3W)
Reads analog values of SEN0~3 and stores them into *sen0W~*sen3W, respectively.
- void SEN_init (void)
-
SWT: on-board switches (SW5−1)
- void SWT_init (void)
Initializes SWT module. You must call this function before using SWT module. - ushort SWT_get (void)
Reads the ON/OFF state of SW1~SW5 and returns the state as a bit pattern (SW5, SW4, SW3, SW2, SW1).
- void SWT_init (void)
-
SCI: serial communication interface (PORTX・PORTY)
- void SCI_init (uchar addr, uchar pack_len,
void *callback())
Initializes SCI module. Address (5bits) of this Pico-2 is set as addr; the length (1~8) of packet is set to pack_len, and callback is a function that will be called when Pico-2 received a packet (of length pack_len). The callback function should look like void callback(uchar *packet), where the received packet is given as packet (an array of unsigned char). The serial communication should be in 38400bps, 1 start-bit, 8 data-bits, 1 stop-bits, and no-parity. - void SCI_transmit (uchar *packet)
Transmit packet (an array of byte, length pack_len). This function usually returns immediately, and the transmission proceeds automatically. When previous transmission is still in progress, the function blocks until the transmitter becomes available.
- void SCI_init (uchar addr, uchar pack_len,
void *callback())
-
CMT: timer
- void CMT0_init (uchar cselB2, ushort periodW,
void *callback());
Initializes CMT0 module, starting periodical calls of the callback. The calling cycle is determined by combination of cselB2 (0~3: clock select) and period (counter period). By cselB2, clock is selected as 0: C=P/8, 1: C=P/32, 2: C=P/128, 3: C=P/512; P=24.576MHz; then the cyncle will be (period+1)/C [second]. The callback should look like void callback(void). - void CMT1_init (uchar cselB2, ushort periodW,
void *callback());
Initializes CMT1 module, same as CMT0_init() described above.
- void CMT0_init (uchar cselB2, ushort periodW,
void *callback());
-
RCS: RC-servos (RCS)
- void RCS_init (void)
Initializes RCS module, staring producing four PWM signals whose width is 1.5ms (approximately, at center) and cycle is 10.667ms. You must call this function first before using RCS module. - void RCS_set (uchar numB2, ushort valW)
Sets PWM width for RCS numB2. When valW is 0xffff, duty ratio becomes 100%; when valW is 0x0000, duty ratio becomes 0%. For most RC-servos, 0x1400 to 0x3400 (and 0x2400 at center) would be the appropriate range for valW.
- void RCS_init (void)
-
LED: LED display (LED)
- void LED_init (void)
Initializes LED module. You must call this function before using LED module. - void LED_set (ushort dataW5)
Sets five LEDs according to the bit pattern of dataW5 (LED5, LED4, LED3, LED2, LED1). - ushort LED_get (void)
Gets the current state of five LED as a bit pattern of dataW5 (LED5, LED4, LED3, LED2, LED1). - ushort LED_op (ushort locW5, ushort dataW5)
Changes specified LEDs in specified manner. The location locW5 specifies the target of operation by the 5bit pattern. The state dataW5 specifies the goal state of the target LEDs.
- void LED_init (void)
-
LIO: digital input/output ports (LIO)
- void LIO_init (uchar dirB4)
Initializes LIO module. There are four digital I/O pins, whose direction (I or O) is specified by the bit pattern of dirB4 (LIO3, LIO2, LIO1, LIO0; 0 for input and 1 for output). You must call this function before using LIO module. - void LIO_set (uchar valB4)
Outputs the bit pattern of valB4 to the output pins of LIO3~0. - ushort LIO_get (void)
Reads the input pins of LIO3~0, and returns as a bit pattern of LIO3~0.
- void LIO_init (uchar dirB4)
-
LIN: digital input ports (ALINX・ALINY)
- void LIN_init (void)
Initializes LIN module, configuring ALINX and ALINY pins as digital inputs. You must call this function before using LIN module. - ushort LIN_get (void)
Reads ALINY3~0 and ALINX3~0 and return as a 8bit pattern.
- void LIN_init (void)
-
AIX・AIY: analog input ports (ALINX・ALINY)
- void AIX_init (void)
Initializes AIX module, configureing ALINX pins as analog inputs. You must call this function call this function before using AIX module. - void AIX_gets (ushort *val0W, *val1W, *val2W, *val3W)
Reads four analog values of ALINX0~3, and stores them into *val0W~*val3W, respectivelly. - void AIY_init (void)
Initializes AIY module, configureing ALINY pins as analog inputs. You must call this function call this function before using AIY module. - void AIY_gets (ushort *val0W, *val1W, *val2W, *val3W)
Reads four analog values of ALINY0~3, and stores them into *val0W~*val3W, respectivelly.
- void AIX_init (void)
-
WDT: watchdog timer
- void WDT_init (uchar cselB3)
Initializes WDT module, that could reset Pico-2 when the counter TCNT overflows. The time to overflow will be set as 0.0104ms for cselB3=0, 0.3333ms for cselB3=1, 0.6666ms for cselB3=2, 1.3333ms for cselB3=3, 2.6667ms for cselB3=4, 5.3333ms for cselB3=5, 21.3333ms for cselB3=6, and 42.6667ms for cselB3=7. - void WDT_reset (void)
Not to get Pico-2 reset, the user program has to call WDT_reset() before the overflow. - int WDT_check (void)
Checks if Pico-2 has been reset because of WDT overflow. If Pico-2 has encountered WDT overflow, this function returns a non-zero value.
- void WDT_init (uchar cselB3)