XMOS SliceKit GPIO Gpio Example Applications page 8

Table of Contents

Advertisement

SliceKit GPIO Example Applications
}
if ( but ton_pr ess_1 == BUTTON_PRESS_VALUE -1) // Button 2 is pressed
{
}
button =1;
break ;
}
After recognising the valid push then it checks if Button 1 is pressed or Button 2 is pressed. IF
Button 1 is pressed then, the application reads the status of LEDs and shift the position of the
LEDs to left by 1. If Button 2 is pressed, then the applciation reads the contents of ADC register
using I2C read instruction and input the ADC value to linear interpolation function as shown
below.
int l i n e a r _ i n t e r p o l a t i o n ( int adc_value )
{
int i =0 , x1 , y1 , x2 , y2 , temper ;
while ( adc_value < T EM P ER AT U RE _L U T [ i ][1])
{
i ++;
}
//:: Formula start
// Calculating Linear interpolation using the formula y = y1 +( x - x1 ) *( y2 - y1 ) /( x2 - x1 )
//:: Formula
x1 = TE MP E RA TU R E_ L UT [i -1][1];
y1 = TE MP E RA TU R E_ L UT [i -1][0];
x2 = TE MP E RA TU R E_ L UT [ i ][1];
y2 = TE MP E RA TU R E_ L UT [ i ][0];
temper = y1 +((( adc_value - x1 ) *( y2 - y1 ) ) /( x2 - x1 ) ) ;
return temper ;// Return Temperature value
}
The linear intepolation function calculates the linear interpolation value using the following
formula and returns the temperature value from temperature look up table.
// Calculating Linear interpolation using the formula y = y1 +( x - x1 ) *( y2 - y1 ) /( x2 - x1 )
int TEM PE R AT U RE _L U T [][2]= // Temperature Look up table
{
{ -10 ,845} ,{ -5 ,808} ,{0 ,765} ,{5 ,718} ,{10 ,668} ,{15 ,614} ,{20 ,559} ,{25 ,504} ,{30 ,450} ,{35 ,39
{40 ,352} ,{45 ,308} ,{50 ,269} ,{55 ,233} ,{60 ,202}
REV A
led_value = led_value & 0 x0F ;
if ( led_value == 15)
{
led_value =0 x0E ;
}
data1 [0]=0; data1 [1]=0;
i2c_master_rx (0 x28 , data1 , 2 , i2cOne ) ; // Read ADC value using I2C
read
printstrln ( " Reading Temperature value .... " ) ;
data1 [0]= data1 [0]&0 x0F ;
adc_value =( data1 [0] < <6) |( data1 [1] > >2) ;
printstr ( " Temperature is : " ) ;
printintln ( l i n e a r _ i n t e r p o l a t i o n ( adc_value ) ) ;
8/24

Advertisement

Table of Contents
loading

This manual is also suitable for:

Slicekit

Table of Contents