diff --git a/src/adc.c b/src/adc.c
index 597c4c5..da8a8e9 100644
--- a/src/adc.c
+++ b/src/adc.c
@@ -1,163 +1,164 @@
 #include "p33Fxxxx.h"
 #include <sbcp.h>
 #include "adc.h"
 #include "pindefs.h"
 #include "timer.h"
 #include "power_sbcp.h"
 #include "buttons.h"
 #include "spi_led.h"
 
 eadc_mode adc_mode;
 
 // These parameters are set in buttons.c at power up
 unsigned int last_measurement_voltage;
 unsigned int last_measurement_current;
 
 /** \brief SPI initialization function
 
 	This function is used to initialize the ADC inputs. It should be called in 
 	the main initialization function.
 
 	\param 	no parameters
 	\return	no returns
 */
 
 void init_adc(void) {
 	AD1CON1bits.FORM   = 0b00;	// Data Output Format: integer
 //	AD1CON1bits.SSRC   = 0b111;	// Internal Counter (SAMC) ends sampling and starts conversion
 //	AD1CON1bits.SSRC   = 2;		// Sample Clock Source: GP Timer starts conversion
 	AD1CON1bits.SSRC   = 0b000; // Manual triggering the conversion
 	AD1CON1bits.ASAM   = 1;		// ADC Sample Control: Sampling begins immediately after conversion
 	AD1CON1bits.AD12B  = 1;		// 12-bit ADC operation
 
         AD1CON1bits.SIMSAM  = 1;		// 12-bit ADC operation
 
 //	AD1CON1bits.SAMP   = 0;		// for manually starting conversion
         AD1CON2bits.ALTS = 0;		// Alternate Input Sample Mode Select bit
 
 	AD1CON2bits.CSCNA = 1;		// Scan Input Selections for CH0+ during Sample A bit
 	
 	AD1CON2bits.VCFG  = 0b00;	// VREFH = AVdd, VREFL = AVss
      
 	AD1CON3bits.ADRC = 0;		// ADC Clock is derived from Systems Clock
 	AD1CON3bits.SAMC = 3; 		// Auto Sample Time = minimum 3*Tad for 12 bits
 //	AD1CON3bits.SAMC = 12; 		// Auto Sample Time = 12*Tad	
 	
 //	AD1CON3bits.ADCS = 63;		// ADC Conversion Clock Tad=Tcy*(ADCS+1)= (1/40M)*64 = 1.6us
 								// ADC Conversion Time for 12-bit Tc=14*Tad = 22.4us 
 	AD1CON3bits.ADCS = 5;		// ADC Conversion Clock Tad=Tcy*(ADCS+1)= (1/40M)*6 = 150ns (minimum is 120ns for 12-bit)
 								// ADC Conversion Time for 12-bit Tc=14*Tad = 2.1us 
 	AD1CON2bits.SMPI = 0x0001;
 	AD1CSSL = 0x0000;
 	AD1CSSLbits.CSS0 = 1;		// Enable AN0 for channel scan
 	AD1CSSLbits.CSS1 = 1;		// Enable AN1 for channel scan
 
 	//AD1CON2bits.BUFM = 0;           // Always starts filling buffer at address 0x0
 
   	// AD1CHS0: A/D Input Select Register
 	AD1CHS0bits.CH0SA=0;		// MUXA +ve input selection (AIN0) for CH0
 	AD1CHS0bits.CH0NA=0;		// MUXA -ve input selection (Vref-) for CH0
 
 	//AD1PCFGH/AD1PCFGL: Port Configuration Register
 	AD1PCFGLbits.PCFG0 = 0;		// AN0 as Analog Input
 	AD1PCFGLbits.PCFG1 = 0;		// AN1 as Analog Input
 
 	// set offsets to zero
 	last_measurement_voltage = 0;
 	last_measurement_current = 0;
 	// first channel to convert is AN0
         adc_mode = READ_BATTERY_VOLTAGE;
 
 	IFS0bits.AD1IF = 0;		// Clear the A/D interrupt flag bit
 	IEC0bits.AD1IE = 1;		// Do Not Enable A/D interrupt 
 	AD1CON1bits.ADON = 1;		// Turn on the A/D converter
-	
 }
 
 /**
  * \brief Update the ADC-registers
  * update the adc-registers to contain the value sampled the last time the T4-interrupt went off
  * also check if the voltage and current is within boundaries
  * This function contains too many calculations to be done in the interrupt itself
  * \ingroup adc_m
  */
 
 void adc_update(void) {
     unsigned int volt = ADC_TO_mV(last_measurement_voltage);
     unsigned int curr = ADC_TO_mA(last_measurement_current);
     sbcp_reg_int(ADDRESS_POWER_INPUT_VOLTAGE) = volt;
     sbcp_reg_int(ADDRESS_POWER_TOTAl_CURRENT) = curr;
 
     if ( (curr > (long) sbcp_reg_int(ADDRESS_MAXIMUM_CURRENT)) && (sbcp_reg_int(ADDRESS_POWER_MONITOR_MODE) & MONITOR_CURRENT)){
         sbcp_reg_int(ADDRESS_POWER_STATUS) |= POWERBOARD_CURRENT_OVER_MAXIMUM;
         emergency_shutdown(1, 1, 1);//never returns
     }else{
         sbcp_reg_int(ADDRESS_POWER_STATUS) &= ~POWERBOARD_CURRENT_OVER_MAXIMUM;
     }
     
     if( volt > sbcp_reg_int(ADDRESS_MAXIMUM_BATTERY_VOLTAGE)){
         sbcp_reg_int(ADDRESS_POWER_STATUS) |= POWERBOARD_VOLTAGE_ABOVE_MAX;
         emergency_shutdown(1, 0, 0);//never returns
     }else{
         sbcp_reg_int(ADDRESS_POWER_STATUS) &= ~POWERBOARD_VOLTAGE_ABOVE_MAX;
     }
 
     if( volt < sbcp_reg_int(ADDRESS_CRITICAL_BATTERY_VOLTAGE)){
         sbcp_reg_int(ADDRESS_POWER_STATUS) |= POWERBOARD_VOLTAGE_UNDER_CRITICAL;
         emergency_shutdown(0, 0, 1);//never returns
     }else{
         sbcp_reg_int(ADDRESS_POWER_STATUS) &= ~POWERBOARD_VOLTAGE_UNDER_CRITICAL;
     }
 
     if( volt > sbcp_reg_int(ADDRESS_MINIMUM_BATTERY_VOLTAGE)){
         sbcp_reg_int(ADDRESS_POWER_STATUS) |=  POWERBOARD_VOLTAGE_ABOVE_MIN;
         sbcp_reg_int(ADDRESS_POWER_STATUS) &= ~POWERBOARD_VOLTAGE_UNDER_MIN;
     }else{
         sbcp_reg_int(ADDRESS_POWER_STATUS) |= POWERBOARD_VOLTAGE_UNDER_MIN;
         sbcp_reg_int(ADDRESS_POWER_STATUS) &= ~POWERBOARD_VOLTAGE_ABOVE_MIN;
     }
 }
 
 /**
  * \brief Convert a ADC-registers to mV
  * \ingroup adc_m
  */
 
 int ADC_TO_mV(int _ADC_VALUE){
     long Max_Batt_mV = 3300L*(BATT_RES_LOW+BATT_RES_HIGH)/(BATT_RES_LOW);
     return (int)(Max_Batt_mV * _ADC_VALUE / 4096);
 }
 
 /**
  * \brief Convert a ADC-registers to mA
  * \ingroup adc_m
  */
 
 int ADC_TO_mA(int _ADC_VALUE){
-    return _ADC_VALUE/CURR_SENSITIVITY;//*(1023/CURR_SENSITIVITY); //1023=3300*1000*127/4096/100
+    setLEDOutput(_ADC_VALUE);
+    delay_ms(100);
+    return _ADC_VALUE*2/31;//*(1023/CURR_SENSITIVITY); //1023=3300*127/4096/100
 }
 
 /*=============================================================================  
 ADC INTERRUPT SERVICE ROUTINE
 =============================================================================*/
 
 void __attribute__((interrupt, no_auto_psv)) _ADC1Interrupt(void)
 {
 	switch (adc_mode)
 	{
 		case READ_BATTERY_VOLTAGE:
                         last_measurement_voltage = ADC1BUF0;
 			while (AD1CON1bits.SAMP == 0);
 			AD1CON1bits.SAMP   = 0; // continue with sampling the second channel
 			adc_mode = READ_BATTERY_CURRENT;
                         break;
 		case READ_BATTERY_CURRENT:
                         last_measurement_current = ADC1BUF0;
 			adc_mode = READ_BATTERY_VOLTAGE;
 			// we now wait until the timer0 interrupt routine (1kHz system clock) initiates a new conversion cycle
 			break;
 		default:
 			break;						
 	}
     IFS0bits.AD1IF = 0;		// Clear the ADC1 Interrupt Flag
 }
diff --git a/src/spi_led.c b/src/spi_led.c
index bc56f96..6c829e2 100644
--- a/src/spi_led.c
+++ b/src/spi_led.c
@@ -1,270 +1,270 @@
 /*
 	spi_led.c	
 	
 	Copyright (C) 2011 Michiel D'Haene <michiel.dhaene at gmail dot com>
 
 	UGent Reservoir lab (http://reslab.elis.ugent.be/michiel)
 	Ghent University (http://www.ugent.be)
 	
 	This program is free software: you can redistribute it and/or modify
 	it under the terms of the GNU General Public License as published by
 	the Free Software Foundation, either version 3 of the License, or
 	(at your option) any later version.
 	
 	This program is distributed in the hope that it will be useful,
 	but WITHOUT ANY WARRANTY; without even the implied warranty of
 	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 	GNU General Public License for more details.
 	
 	You should have received a copy of the GNU General Public License
 	along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
 
 /**
 	\defgroup spi_led COMMAND
 	\brief 	LED driver handling.
 	
 	This module is responsible for handling and execution of led driver commands
 	using the SPI bus. 
 
 	\author 	Michiel D'Haene
 	\version 	2.0
 	\date		2011-08-10
 */
 /*@{*/
 
 /** \file 	spi_led.c
 	\brief 	SPI commands handling.
 */
 
 #include "spi_led.h"
 
 #include <xc.h>
 #include "timer.h"
 #include "pindefs.h"
 
 /*************************************************************************
 *
 *		VARIABLES
 *
 *************************************************************************/
 
 uint16 led_outputs;
 uint8 spi_busy;
 
 /*************************************************************************
 *
 *		INTERRUPT ROUTINES
 *
 *************************************************************************/
 /** \brief SPI1 receiver interrupt routine
 
 	This interrupt routine is called after bytes/words are sent/received 
 	by the SPI receiver.
 	
 	\param 	no parameters
 	\return	no returns
 */
 
 void __attribute__((__interrupt__, no_auto_psv)) _SPI1Interrupt(void)
 {
 	// spi has finished sending
 	// latch the data to the outputs
 	Nop();
 	LED_LE = 1;
 	Nop();
 	LED_LE = 0;
 
 	SPI1STATbits.SPIROV = 0; 	// Clear SPI overflow bit
 	IFS0bits.SPI1EIF = 0;		// Clear SPI error interrupt flag
 	IFS0bits.SPI1IF = 0; 		// Clear the interrupt Flag
 
 	spi_busy = 0;				// indicate that next spi transfer may start
 }
 
 
 
 /*************************************************************************
 *
 *		FUNCTIONS
 *
 *************************************************************************/
 
 /** \brief output an int to the LEDs
 
         This function encodes an integer onto the LED's
 
 	\param 	int value
 	\return	no returns
 */
 
 
-void setLedOutput(int value){
+void setLEDOutput(int value){
     led_outputs = value;
 }
 
 /** \brief LED bar
 
 	This function shows a bar of leds with a resolution of 8 values 
 	The output shows the fraction value/max in 8 equally spaced
 	intervals from 0 to max. 
 
 	\param 	int value, int max
 	\return	no returns
 */
 
 void ledbar(int value, int max) {
 	int output_value;
 	uint16 tmp_led_outputs;
 	
 	tmp_led_outputs = led_outputs & 0xF000;
 	if (value < max)
 		output_value = (((long)value*16)/((long)max)+1)/2;
 	else 
 		output_value = 8;
 
 	if (output_value > 1) tmp_led_outputs |= (0x0001 << (LD1+1));
 	else if (output_value > 0) tmp_led_outputs |= (0x0001 << (LD1+2));
 	if (output_value > 3) tmp_led_outputs |= (0x0001 << (LD2+1));
 	else if (output_value > 2) tmp_led_outputs |= (0x0001 << (LD2+2));
 	if (output_value > 5) tmp_led_outputs |= (0x0001 << (LD3+1));
 	else if (output_value > 4) tmp_led_outputs |= (0x0001 << (LD3+2));
 	if (output_value > 7) tmp_led_outputs |= (0x0001 << (LD4+1));
 	else if (output_value > 6) tmp_led_outputs |= (0x0001 << (LD4+2));
 
 	// outputs are automatically updated on timer interrupt
 //	write_spi(led_outputs);
 	led_outputs = tmp_led_outputs;
 }
 
 
 /** \brief LED bar
 
 	This function is just a quick test of the 4 RGB leds. 
 
 	\param 	no parameters
 	\return	no returns
 */
 
 void RGB_led_test(void) {
 	// clear RGB leds
 	clear_RGB_leds();
 	delay_ms(100);
 	// generate a rainbow test pattern
         set_RGB_led(LD4, 0, 0, 0);delay_ms(50);
         set_RGB_led(LD4, 1, 0, 0);
         set_RGB_led(LD3, 0, 0, 0);delay_ms(50);
         set_RGB_led(LD4, 1, 1, 0);
         set_RGB_led(LD3, 1, 0, 0);
         set_RGB_led(LD2, 0, 0, 0);delay_ms(50);
         set_RGB_led(LD4, 0, 1, 0);
         set_RGB_led(LD3, 1, 1, 0);
         set_RGB_led(LD2, 1, 0, 0);
         set_RGB_led(LD1, 0, 0, 0);delay_ms(50);
         set_RGB_led(LD4, 0, 1, 1);
         set_RGB_led(LD3, 0, 1, 0);
         set_RGB_led(LD2, 1, 1, 0);
         set_RGB_led(LD1, 1, 0, 0);delay_ms(50);
         set_RGB_led(LD4, 0, 0, 1);
         set_RGB_led(LD3, 0, 1, 1);
         set_RGB_led(LD2, 0, 1, 0);
         set_RGB_led(LD1, 1, 1, 0);delay_ms(50);
         set_RGB_led(LD4, 1, 0, 1);
         set_RGB_led(LD3, 0, 0, 1);
         set_RGB_led(LD2, 0, 1, 1);
         set_RGB_led(LD1, 0, 1, 0);delay_ms(50);
         set_RGB_led(LD4, 0, 0, 0);
         set_RGB_led(LD3, 1, 0, 1);
         set_RGB_led(LD2, 0, 0, 1);
         set_RGB_led(LD1, 0, 1, 1);delay_ms(50);
         set_RGB_led(LD3, 0, 0, 0);
         set_RGB_led(LD2, 1, 0, 1);
         set_RGB_led(LD1, 0, 0, 1);delay_ms(50);
         set_RGB_led(LD2, 0, 0, 0);
         set_RGB_led(LD1, 1, 0, 1);delay_ms(50);
         set_RGB_led(LD1, 0, 0, 0);delay_ms(50);
         clear_leds();
 }
 
 
 /** \brief SPI initialization function
 
 	This function is used to initialize all SPIs. It should be called in 
 	the main initialization function.
 
 	\param 	no parameters
 	\return	no returns
 */
 
 void init_spi_led(void) {
 	IFS0bits.SPI1IF = 0; 		// Clear the Interrupt Flag
 	IEC0bits.SPI1IE = 0; 		// Disable the Interrupt
 
 	// SPI1CON1 Register Settings
 	SPI1CON1bits.DISSCK = 0; 	// Internal SPI clock is enabled
 	SPI1CON1bits.DISSDO = 0; 	// SDOx pin is controlled by the module
 	SPI1CON1bits.MODE16 = 1; 	// Communication is word-wide (8 bits)
 	SPI1CON1bits.SMP = 0; 		// Input data is sampled at the middle of data output time
 
 	SPI1CON1bits.CKE = 0; 		// Serial output data changes on transition
 								// from Idle clock state to active clock state
 	SPI1CON1bits.CKP = 1; 		// Idle state for clock is a high level;
 								// active state is a low level
 	SPI1CON1bits.MSTEN = 1; 	// Master mode enabled
 	SPI1CON1bits.PPRE = 0b10;	// Primary prescale bit for SPI clock; 0b10 = 4:1; 0b01 = 16:1; 0b00 = 64:1
 	SPI1CON1bits.SPRE = 0b110;	// Secondary prescale bit for SPI clock; 0b111 = 1:1; 0b110 = 1:2 ... 0b000 = 1:8
 	SPI1CON1bits.SSEN = 0;		// Slave select pin disabled
 
 	SPI1CON2bits.FRMEN = 0; 	// Frame mode disabled
 
 	// SPISTAT Register Settings
 	SPI1STATbits.SPIEN = 1; 	// Enable SPI module
 	SPI1STATbits.SPISIDL = 1;	// Discontinue module operation when device enters Idle mode
 
 	// Interrupt Controller Settings
 	SPI1STATbits.SPIROV = 0; 	// Clear SPI overflow bit
 	IFS0bits.SPI1EIF = 0;		// Clear SPI error interrupt flag
 	IPC2bits.SPI1IP = 0x01; 	// Set SPI1 Interrupt Priority Level to 1 = low priority
 	IFS0bits.SPI1IF = 0; 		// Clear the Interrupt Flag
 	IEC0bits.SPI1IE = 1; 		// Enable the Interrupt
 	LED_OE = 0; 				// Enable outputs
 	LED_LE = 0;					// latching enabled
 	led_outputs = 0x0000;
 	spi_busy = 0;				// currently no SPI transfer
 	write_spi(led_outputs);
 }
 
 void clear_leds(void) {
 	led_outputs = 0x0000;
 	// outputs are automatically updated on timer interrupt
 }
 
 void clear_RGB_leds(void) {
 	led_outputs &= 0xF000;
 	// outputs are automatically updated on timer interrupt
 }
 
 void set_led(int nb, int status) {
 	if (status == 0) led_outputs &= ~(0x01 << (nb)); else led_outputs |= (0x0001 << (nb));
 	// outputs are automatically updated on timer interrupt
 }
 
 void set_RGB_led(int nb, int R, int G, int B) {
 	uint16 tmp_led_outputs = led_outputs;
 	if (R == 0) tmp_led_outputs &= ~(0x0001 << (nb+2)); else tmp_led_outputs |= (0x0001 << (nb+2));
 	if (G == 0) tmp_led_outputs &= ~(0x0001 << (nb+1)); else tmp_led_outputs |= (0x0001 << (nb+1));
 	if (B == 0) tmp_led_outputs &= ~(0x0001 << (nb+0)); else tmp_led_outputs |= (0x0001 << (nb+0));
 	led_outputs = tmp_led_outputs;
 	// outputs are automatically updated on timer interrupt
 }
 
 
 void write_spi(uint16 values) {
 	// wait until previous spi command is finished
 	while (spi_busy) ;;
 	spi_busy = 1; // new spi transfer is starting
 	// write content into the transmit buffer
 	SPI1BUF = values;
 }
 
 /*@}*/
diff --git a/src/spi_led.h b/src/spi_led.h
index 29d692c..8a87e9a 100644
--- a/src/spi_led.h
+++ b/src/spi_led.h
@@ -1,90 +1,90 @@
 /*
 	spi_led.h	
 	
 	Copyright (C) 2011 Michiel D'Haene <michiel.dhaene at gmail dot com>
 
 	UGent Reservoir lab (http://reslab.elis.ugent.be/michiel)
 	Ghent University (http://www.ugent.be)
 	
 	This program is free software: you can redistribute it and/or modify
 	it under the terms of the GNU General Public License as published by
 	the Free Software Foundation, either version 3 of the License, or
 	(at your option) any later version.
 	
 	This program is distributed in the hope that it will be useful,
 	but WITHOUT ANY WARRANTY; without even the implied warranty of
 	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 	GNU General Public License for more details.
 	
 	You should have received a copy of the GNU General Public License
 	along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
 
 /** \addtogroup spi_led */
 /*@{*/
 
 /** \file 	spi_led.h
 	\brief  LED driver with SPI interface.
 	
 	This file contains the declarations of the led driver functions, which is interfaced
 	through a SPI interface. 
 
 	\author 	Michiel D'Haene
 	\version 	2.0
 	\date		2011-08-10
 */
 
 
 #ifndef __SPI_LED_H__
 #define __SPI_LED_H__
 
 #include "misc.h"
 
 // Led driver output numbering
 typedef enum {
     LD1 = 0,
     LD2 = 3,
     LD3 = 6,
     LD4 = 9,
     POWER_LED = 12,
 } LEDAddress;
 
 // PWM value from 0 (off) to 8 (max)
 enum { RGB_PWM_VALUE = 1};
 
 // PWM feature: only switch on the RGB-leds part of the time, 
 // otherwise they are too powerfull.
 // Supports 8 possible PWM values.
 // we don't need to use the (safer) write_spi function, since
 // refreshing is much slower than the spi write time
 #define UPDATE_RGB_LED(systime) do {\
 	if (((systime)&0x0007) >= RGB_PWM_VALUE)\
 		SPI1BUF = led_outputs&0xF000;\
 	else\
 		SPI1BUF = led_outputs;\
 }while(0)
 
 #define BLINK   (systime & 0x0200)
 #define BLINK_FAST   (systime & 0x0080)
 
 /*************************************************************************
 *
 *		PUBLIC FUNCTIONS
 *
 *************************************************************************/
 
-void setLedOutput(int value);
+void setLEDOutput(int value);
 void ledbar(int value, int max);
 void RGB_led_test(void);
 
 void init_spi_led(void);
 void clear_leds(void);
 void clear_RGB_leds(void);
 void set_led(int nb, int status);
 void set_RGB_led(int nb, int R, int G, int B);
 
 void write_spi(uint16 values);
 
 #endif /* __SPI_LED_H__ */
 
 /*@}*/