Submitted by:
Glenn Clark
VersaTech Electronics
The programs and drawings shown below are taken from the examples section of the manual.
A common problem encountered when designing controller applications based on single chip controllers is the lack of I/O or other controller resources. To meet this demand for additional capabilities, a trend has developed toward serially connected peripheral ICs. One example of this is Protean's I2C Xtender IC. This device is a specially programmed IC that responds to commands over its Inter-Integrated Circuit (IIC or I2C) bus. This bus connects to a host processor using only two wires. If a TICkit is the host, the connection can use the EEprom bus wires leaving all 16 of the TICkits general purpose I/O lines available. Up to 8 or more Xtenders can be connected to a single host via these two lines.
A single Xtender IC gives the system the following hardware resources: 2 CCP I/O pins, a 32 bit real-time seconds counter, 3 time bases, a unipolar stepper motor controller, 128 bytes of RAM, a buffered RS232 port, a 16 bit counter, 4 100-Hz PWM outputs, and 5 8-bit A/D channels.
A sample connection to an Xtender is shown below. The I2Cclk and I2Cdata lines form the logical connection. In addition to these lines, the /IRQ line, and /RES of the Xtender are connected to the /IRQ, and EEpwr of TICkit respectively. A sampling of I/O components are connected to the Xtender in the diagram to demonstrate the A/D, PWM1 (CCP1), button input, general purpose output, 100 Hz PWM and time base outputs.
In the program that follows, every press of SW1 causes a read from the RTC seconds count and a read of A/D channel 1. You can vary the input to the A/D channel by changing the position of R1. To make the operation of the A/D clearer, you can use a multi-turn version of resistor R1. LED D3 follows the status of SW1 except that it inverted to demonstrate TICkit processing. LED D2 shows the effects of the 100 Hz PWM. LED D1 shows the effects of the PWM1 output which is a hardware generated, higher frequency pwm. LED D1 and D2 bright and dim out of phase with each other so that while one gets brighter, the other gets dimmer.
There are many more things that the Xtender can do and programming the Xtender is a subject in and of itself, but this example shows how simple register write and reads accomplish control of the Xtender. Communication with the Xtender takes place at the same speed as communication with the EEprom on the TICkit (400 Kbps) so it takes commands very quickly.
Commands for the Xtender are formed from constants contained in the Xtender's library. Use the '|' vertical bar character to combine the device number with the specific command. This method keeps the code very clean and readable.
DEF tic62_c LIB fbasic.lib LIB constrin.lib LIB xtn73h.lib GLOBAL byte duty_temp 0b ; duty cycle for D1 and D2 GLOBAL byte button_last 0b ; last status of button GLOBAL long time_temp ; used to build up the seconds count GLOBAL byte temp_val ; temporary value for reading/writing FUNC none main BEGIN delay( 500 ) ; let Xtender get out of power up reset ; initialize the Xtender IF ==( i2c_read( xtn_dev0 | xtn_reset ), 8b ) ; this is a version H Xtender ENDIF i2c_write( xtn_dev0 | xtn_pins_out, 0y00000011b ) i2c_write( xtn_dev0 | xtn_pins_in, 0y00000100b ) i2c_write( xtn_dev0 | xtn_gp_cont, xtn_pwme_0 ) i2c_write( xtn_dev0 | xtn_ad_con, xtn_ad_pwr | xtn_ad_chan1 ) i2c_write( xtn_dev0 | xtn_tmr2_con, xtn_tmr2_en ) i2c_write( xtn_dev0 | xtn_tmr2_per, 255b ) i2c_write( xtn_dev0 | xtn_ccp1_con, xtn_ccp1_pwm ) REP IF b_and( i2c_read( xtn_dev0 | xtn_pins ), 0y00000100b ) =( button_last, 0b ) ; button is not pressed i2c_write( xtn_dev0 | xtn_pins_low, 0y00000010b ) ELSE ; button is pressed i2c_write( xtn_dev0 | xtn_pins_high, 0y00000010b ) IF button_last ; get real time seconds count and A/D value =( temp_val, i2c_read( xtn_dev0 | xtn_clk_tic )) ; above captures 32 bit count =( temp_val, i2c_read( xtn_dev0 | xtn_clk_cnt3 )) =( time_temp, to_long( temp_val )) =( temp_val, i2c_read( xtn_dev0 | xtn_clk_cnt2 )) =( time_temp, +( *( time_temp, 256w ), temp_val )) =( temp_val, i2c_read( xtn_dev0 | xtn_clk_cnt1 )) =( time_temp, +( *( time_temp, 256w ), temp_val )) =( temp_val, i2c_read( xtn_dev0 | xtn_clk_cnt0 )) =( time_temp, +( *( time_temp, 256w ), temp_val )) =( temp_val, i2c_read( xtn_dev0 | xtn_ad_reg )) con_string( "Time at press: " ) con_out( time_temp ) con_string( " Analog Level: " ) con_out( temp_val ) con_string( "\r\l" ) ENDIF =( button_last, 255b ) ENDIF delay( 10 ) ; deal with the PWMs i2c_write( xtn_dev0 | xtn_ccp1_low, duty_temp ) i2c_write( xtn_dev0 | xtn_ccp1_high, 0b ) i2c_write( xtn_dev0 | xtn_pwm_0, b_not( duty_temp )) ++( duty_temp ) LOOP ENDFUN
Protean Logic Inc. Copyright 05/06/04 Top of Page