diff --git a/DSTAT-temp/DSTAT-temp.cproj b/DSTAT-temp/DSTAT-temp.cproj
index f608949fc4dab5da7bab4aaaf57ab22569c2feb3..73411be6c0a7e94892384a30fec038c44c15b129 100644
--- a/DSTAT-temp/DSTAT-temp.cproj
+++ b/DSTAT-temp/DSTAT-temp.cproj
@@ -10,101 +10,101 @@
3.4.1
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
ATxmega256A3U
xmegaau
@@ -124,88 +124,88 @@
- True
- True
- True
-
-
- BOARD=USER_BOARD
- IOPORT_XMEGA_COMPAT
-
-
-
-
- ../src
- ../src/asf/common/applications/user_application/user_board
- ../src/asf/common/boards
- ../src/asf/common/boards/user_board
- ../src/asf/common/utils
- ../src/asf/xmega/utils
- ../src/asf/xmega/utils/preprocessor
- ../src/config
- ../src/asf/xmega/drivers/cpu
- ../src/asf/xmega/drivers/nvm
- ../src/asf/xmega/drivers/pmic
- ../src/asf/xmega/drivers/rtc
- ../src/asf/xmega/drivers/sleep
- ../src/asf/xmega/drivers/tc
- ../src/asf/xmega/drivers/usart
- ../src/asf/common/services/clock
- ../src/asf/common/services/delay
- ../src/asf/common/services/ioport
- ../src/asf/common/services/sleepmgr
- ../src/asf/common/services/spi
- ../src/asf/common/services/usb
- ../src/asf/common/services/usb/class/cdc
- ../src/asf/common/services/usb/class/cdc/device
- ../src/asf/common/services/usb/udc
- ../src/asf/common/utils/stdio/stdio_usb
- ../src/asf/xmega/drivers/usb
-
-
- Optimize for size (-Os)
- -fdata-sections
- True
- True
- -Werror-implicit-function-declaration -Wmissing-prototypes -Wpointer-arith -Wstrict-prototypes -mrelax -std=gnu99
-
-
-
- True
- True
- -Wl,--relax
- -DBOARD=USER_BOARD -mrelax
-
-
- ../src
- ../src/asf/common/applications/user_application/user_board
- ../src/asf/common/boards
- ../src/asf/common/boards/user_board
- ../src/asf/common/utils
- ../src/asf/xmega/utils
- ../src/asf/xmega/utils/preprocessor
- ../src/config
- ../src/asf/xmega/drivers/cpu
- ../src/asf/xmega/drivers/nvm
- ../src/asf/xmega/drivers/pmic
- ../src/asf/xmega/drivers/rtc
- ../src/asf/xmega/drivers/sleep
- ../src/asf/xmega/drivers/tc
- ../src/asf/xmega/drivers/usart
- ../src/asf/common/services/clock
- ../src/asf/common/services/delay
- ../src/asf/common/services/ioport
- ../src/asf/common/services/sleepmgr
- ../src/asf/common/services/spi
- ../src/asf/common/services/usb
- ../src/asf/common/services/usb/class/cdc
- ../src/asf/common/services/usb/class/cdc/device
- ../src/asf/common/services/usb/udc
- ../src/asf/common/utils/stdio/stdio_usb
- ../src/asf/xmega/drivers/usb
-
-
-
+ True
+ True
+ True
+
+
+ BOARD=USER_BOARD
+ IOPORT_XMEGA_COMPAT
+
+
+
+
+ ../src
+ ../src/asf/common/applications/user_application/user_board
+ ../src/asf/common/boards
+ ../src/asf/common/boards/user_board
+ ../src/asf/common/utils
+ ../src/asf/xmega/utils
+ ../src/asf/xmega/utils/preprocessor
+ ../src/config
+ ../src/asf/xmega/drivers/cpu
+ ../src/asf/xmega/drivers/nvm
+ ../src/asf/xmega/drivers/pmic
+ ../src/asf/xmega/drivers/rtc
+ ../src/asf/xmega/drivers/sleep
+ ../src/asf/xmega/drivers/tc
+ ../src/asf/xmega/drivers/usart
+ ../src/asf/common/services/clock
+ ../src/asf/common/services/delay
+ ../src/asf/common/services/ioport
+ ../src/asf/common/services/sleepmgr
+ ../src/asf/common/services/spi
+ ../src/asf/common/services/usb
+ ../src/asf/common/services/usb/class/cdc
+ ../src/asf/common/services/usb/class/cdc/device
+ ../src/asf/common/services/usb/udc
+ ../src/asf/common/utils/stdio/stdio_usb
+ ../src/asf/xmega/drivers/usb
+
+
+ Optimize for size (-Os)
+ -fdata-sections
+ True
+ True
+ -Werror-implicit-function-declaration -Wmissing-prototypes -Wpointer-arith -Wstrict-prototypes -mrelax -std=gnu99
+
+
+
+ True
+ True
+ -Wl,--relax
+ -DBOARD=USER_BOARD -mrelax
+
+
+ ../src
+ ../src/asf/common/applications/user_application/user_board
+ ../src/asf/common/boards
+ ../src/asf/common/boards/user_board
+ ../src/asf/common/utils
+ ../src/asf/xmega/utils
+ ../src/asf/xmega/utils/preprocessor
+ ../src/config
+ ../src/asf/xmega/drivers/cpu
+ ../src/asf/xmega/drivers/nvm
+ ../src/asf/xmega/drivers/pmic
+ ../src/asf/xmega/drivers/rtc
+ ../src/asf/xmega/drivers/sleep
+ ../src/asf/xmega/drivers/tc
+ ../src/asf/xmega/drivers/usart
+ ../src/asf/common/services/clock
+ ../src/asf/common/services/delay
+ ../src/asf/common/services/ioport
+ ../src/asf/common/services/sleepmgr
+ ../src/asf/common/services/spi
+ ../src/asf/common/services/usb
+ ../src/asf/common/services/usb/class/cdc
+ ../src/asf/common/services/usb/class/cdc/device
+ ../src/asf/common/services/usb/udc
+ ../src/asf/common/utils/stdio/stdio_usb
+ ../src/asf/xmega/drivers/usb
+
+
+
True
@@ -216,89 +216,89 @@
- True
- True
- True
-
-
- BOARD=USER_BOARD
- IOPORT_XMEGA_COMPAT
-
-
-
-
- ../src
- ../src/asf/common/applications/user_application/user_board
- ../src/asf/common/boards
- ../src/asf/common/boards/user_board
- ../src/asf/common/utils
- ../src/asf/xmega/utils
- ../src/asf/xmega/utils/preprocessor
- ../src/config
- ../src/asf/xmega/drivers/cpu
- ../src/asf/xmega/drivers/nvm
- ../src/asf/xmega/drivers/pmic
- ../src/asf/xmega/drivers/rtc
- ../src/asf/xmega/drivers/sleep
- ../src/asf/xmega/drivers/tc
- ../src/asf/xmega/drivers/usart
- ../src/asf/common/services/clock
- ../src/asf/common/services/delay
- ../src/asf/common/services/ioport
- ../src/asf/common/services/sleepmgr
- ../src/asf/common/services/spi
- ../src/asf/common/services/usb
- ../src/asf/common/services/usb/class/cdc
- ../src/asf/common/services/usb/class/cdc/device
- ../src/asf/common/services/usb/udc
- ../src/asf/common/utils/stdio/stdio_usb
- ../src/asf/xmega/drivers/usb
-
-
- Optimize (-O1)
- -fdata-sections
- True
- Maximum (-g3)
- True
- -Werror-implicit-function-declaration -Wmissing-prototypes -Wpointer-arith -Wstrict-prototypes -mrelax -std=gnu99
-
-
-
- True
- True
- -Wl,--relax
- -DBOARD=USER_BOARD -mrelax
-
-
- ../src
- ../src/asf/common/applications/user_application/user_board
- ../src/asf/common/boards
- ../src/asf/common/boards/user_board
- ../src/asf/common/utils
- ../src/asf/xmega/utils
- ../src/asf/xmega/utils/preprocessor
- ../src/config
- ../src/asf/xmega/drivers/cpu
- ../src/asf/xmega/drivers/nvm
- ../src/asf/xmega/drivers/pmic
- ../src/asf/xmega/drivers/rtc
- ../src/asf/xmega/drivers/sleep
- ../src/asf/xmega/drivers/tc
- ../src/asf/xmega/drivers/usart
- ../src/asf/common/services/clock
- ../src/asf/common/services/delay
- ../src/asf/common/services/ioport
- ../src/asf/common/services/sleepmgr
- ../src/asf/common/services/spi
- ../src/asf/common/services/usb
- ../src/asf/common/services/usb/class/cdc
- ../src/asf/common/services/usb/class/cdc/device
- ../src/asf/common/services/usb/udc
- ../src/asf/common/utils/stdio/stdio_usb
- ../src/asf/xmega/drivers/usb
-
-
-
+ True
+ True
+ True
+
+
+ BOARD=USER_BOARD
+ IOPORT_XMEGA_COMPAT
+
+
+
+
+ ../src
+ ../src/asf/common/applications/user_application/user_board
+ ../src/asf/common/boards
+ ../src/asf/common/boards/user_board
+ ../src/asf/common/utils
+ ../src/asf/xmega/utils
+ ../src/asf/xmega/utils/preprocessor
+ ../src/config
+ ../src/asf/xmega/drivers/cpu
+ ../src/asf/xmega/drivers/nvm
+ ../src/asf/xmega/drivers/pmic
+ ../src/asf/xmega/drivers/rtc
+ ../src/asf/xmega/drivers/sleep
+ ../src/asf/xmega/drivers/tc
+ ../src/asf/xmega/drivers/usart
+ ../src/asf/common/services/clock
+ ../src/asf/common/services/delay
+ ../src/asf/common/services/ioport
+ ../src/asf/common/services/sleepmgr
+ ../src/asf/common/services/spi
+ ../src/asf/common/services/usb
+ ../src/asf/common/services/usb/class/cdc
+ ../src/asf/common/services/usb/class/cdc/device
+ ../src/asf/common/services/usb/udc
+ ../src/asf/common/utils/stdio/stdio_usb
+ ../src/asf/xmega/drivers/usb
+
+
+ Optimize (-O1)
+ -fdata-sections
+ True
+ Maximum (-g3)
+ True
+ -Werror-implicit-function-declaration -Wmissing-prototypes -Wpointer-arith -Wstrict-prototypes -mrelax -std=gnu99
+
+
+
+ True
+ True
+ -Wl,--relax
+ -DBOARD=USER_BOARD -mrelax
+
+
+ ../src
+ ../src/asf/common/applications/user_application/user_board
+ ../src/asf/common/boards
+ ../src/asf/common/boards/user_board
+ ../src/asf/common/utils
+ ../src/asf/xmega/utils
+ ../src/asf/xmega/utils/preprocessor
+ ../src/config
+ ../src/asf/xmega/drivers/cpu
+ ../src/asf/xmega/drivers/nvm
+ ../src/asf/xmega/drivers/pmic
+ ../src/asf/xmega/drivers/rtc
+ ../src/asf/xmega/drivers/sleep
+ ../src/asf/xmega/drivers/tc
+ ../src/asf/xmega/drivers/usart
+ ../src/asf/common/services/clock
+ ../src/asf/common/services/delay
+ ../src/asf/common/services/ioport
+ ../src/asf/common/services/sleepmgr
+ ../src/asf/common/services/spi
+ ../src/asf/common/services/usb
+ ../src/asf/common/services/usb/class/cdc
+ ../src/asf/common/services/usb/class/cdc/device
+ ../src/asf/common/services/usb/udc
+ ../src/asf/common/utils/stdio/stdio_usb
+ ../src/asf/xmega/drivers/usb
+
+
+
True
@@ -316,6 +316,15 @@
compile
+
+ compile
+
+
+ compile
+
+
+ compile
+
compile
diff --git a/DSTAT-temp/src/ads1255.c b/DSTAT-temp/src/ads1255.c
index 8a4dffbb8661c65b345e16833d8fcaf81f81ae86..11e87710aa3885cd7a3114765860bcedf67021e1 100644
--- a/DSTAT-temp/src/ads1255.c
+++ b/DSTAT-temp/src/ads1255.c
@@ -7,53 +7,38 @@
#include
-//#include
uint8_t buffer_iter = 0;
struct usart_spi_device spi_device_conf = {
.id = IOPORT_CREATE_PIN(PORTE, 4)
};
-
-// struct spi_device spi_device_conf = {
-// .id = IOPORT_CREATE_PIN(PORTE, 4)
-// };
-
void ads1255_init_pins(void)
{
- ioport_configure_port_pin(&PORTE, PIN4_bm, IOPORT_INIT_HIGH | IOPORT_DIR_OUTPUT);
- ioport_configure_port_pin(&PORTE, PIN5_bm, IOPORT_INIT_LOW | IOPORT_DIR_OUTPUT);
- ioport_configure_port_pin(&PORTE, PIN6_bm, IOPORT_DIR_INPUT);
- ioport_configure_port_pin(&PORTE, PIN7_bm, IOPORT_INIT_HIGH | IOPORT_DIR_OUTPUT);
+ arch_ioport_set_pin_dir(IOPORT_CREATE_PIN(PORTE,6), IOPORT_DIR_INPUT);
+ arch_ioport_set_port_dir(IOPORT_PORTE, PIN4_bm|PIN5_bm|PIN7_bm, IOPORT_DIR_OUTPUT);
+ arch_ioport_set_port_level(IOPORT_PORTE, PIN4_bm|PIN5_bm|PIN7_bm, PIN4_bm|PIN7_bm);
+ arch_ioport_set_pin_dir(IOPORT_CREATE_PIN(PORTD,5), IOPORT_DIR_INPUT);
+ arch_ioport_set_pin_sense_mode(IOPORT_CREATE_PIN(PORTD,5), IOPORT_SENSE_FALLING);
+
+// ioport_configure_port_pin(&PORTE, PIN4_bm, IOPORT_INIT_HIGH | IOPORT_DIR_OUTPUT);
+// ioport_configure_port_pin(&PORTE, PIN5_bm, IOPORT_INIT_LOW | IOPORT_DIR_OUTPUT);
+// ioport_configure_port_pin(&PORTE, PIN6_bm, IOPORT_DIR_INPUT);
+// ioport_configure_port_pin(&PORTE, PIN7_bm, IOPORT_INIT_HIGH | IOPORT_DIR_OUTPUT);
//DRDY
// ioport_configure_port_pin(&PORTE, PIN3_bm, IOPORT_DIR_INPUT | IOPORT_FALLING); v1 Board
- ioport_configure_port_pin(&PORTD, PIN5_bm, IOPORT_DIR_INPUT | IOPORT_FALLING);
+// ioport_configure_port_pin(&PORTD, PIN5_bm, IOPORT_DIR_INPUT | IOPORT_FALLING);
}
void ads1255_init_module(void)
{
-// spi_master_init(&SPIE);
-// spi_master_setup_device(&SPIE, &spi_device_conf, SPI_MODE_1, 2300000UL, 0);
-// spi_enable(&SPIE);
-
usart_spi_init(&USARTE1);
usart_spi_setup_device(&USARTE1, &spi_device_conf, SPI_MODE_1, 2300000UL, 0);
-// USARTE1.BAUDCTRLB = 0;
-// USARTE1.BAUDCTRLA = 0b10;
-// delay_s(1);
-
-// usart_spi_enable(&USARTE1);
}
void ads1255_sync(void){
-// uint8_t ctrlbuffer = ADS_SYNC;
-
-// spi_select_device(&SPIE, &spi_device_conf);
-// spi_write_packet(&SPIE, &ctrlbuffer, 1);
-// spi_deselect_device(&SPIE, &spi_device_conf);
-
usart_spi_select_device(&USARTE1, &spi_device_conf);
usart_spi_transmit(&USARTE1, ADS_SYNC);
usart_spi_deselect_device(&USARTE1, &spi_device_conf);
@@ -63,31 +48,14 @@ void ads1255_sync(void){
int32_t ads1255_single_read(void){
-
union{
uint8_t uint[4];
int32_t int32;
} input_buffer;
-
-// spi_select_device(&SPIE, &spi_device_conf);
-// while (ioport_pin_is_high(IOPORT_CREATE_PIN(PORTE, 3)));
-// spi_write_single(&SPIE, ADS_RDATA);
-// delay_us(6.5);
-// spi_write_single(&SPIE, CONFIG_SPI_MASTER_DUMMY);
-// while(!spi_is_rx_full(&SPIE));
-// input_buffer.uint[2] = spi_get(&SPIE);
-// spi_write_single(&SPIE, CONFIG_SPI_MASTER_DUMMY);
-// while(!spi_is_rx_full(&SPIE));
-// input_buffer.uint[1] = spi_get(&SPIE);
-// spi_write_single(&SPIE, CONFIG_SPI_MASTER_DUMMY);
-// while(!spi_is_rx_full(&SPIE));
-// input_buffer.uint[0] = spi_get(&SPIE);
-// spi_write_single(&SPIE, ADS_STANDBY);
-//
-// spi_deselect_device(&SPIE, &spi_device_conf);
usart_spi_select_device(&USARTE1, &spi_device_conf);
- while (ioport_pin_is_high(IOPORT_CREATE_PIN(PORTD, 5)));
+// while (ioport_pin_is_high(IOPORT_CREATE_PIN(PORTD, 5)));
+ while (arch_ioport_get_pin_level(IOPORT_CREATE_PIN(PORTD, 5)));
usart_spi_transmit(&USARTE1, ADS_RDATA);
delay_us(6.5);
for (int i = 2; i >= 0; --i)
@@ -102,7 +70,6 @@ int32_t ads1255_single_read(void){
usart_spi_deselect_device(&USARTE1, &spi_device_conf);
-
ads1255_standby();
if (input_buffer.uint[2] > 0x7F)
@@ -138,27 +105,15 @@ int32_t ads1255_single_read(void){
else
buffer_iter++;
}
-
return input_buffer.int32;
}
-int16_t ads1255_read_fast(void){
-
+int16_t ads1255_read_fast(void){
union{
uint8_t uint[2];
int16_t int16;
} input_buffer;
-// spi_select_device(&SPIE, &spi_device_conf);
-// spi_write_single(&SPIE, CONFIG_SPI_MASTER_DUMMY);
-// while(!spi_is_rx_full(&SPIE));
-// input_buffer.uint[1] = spi_get(&SPIE);
-// spi_write_single(&SPIE, CONFIG_SPI_MASTER_DUMMY);
-// while(!spi_is_rx_full(&SPIE));
-// input_buffer.uint[0] = spi_get(&SPIE);
-// spi_deselect_device(&SPIE, &spi_device_conf);
-
-
usart_spi_select_device(&USARTE1, &spi_device_conf);
for (int i = 1; i >= 0; --i){
@@ -172,8 +127,6 @@ int16_t ads1255_read_fast(void){
usart_spi_deselect_device(&USARTE1, &spi_device_conf);
-// printf("ADS1255 result=%x\n\r", input_buffer.int16);
-
return input_buffer.int16;
}
@@ -184,19 +137,6 @@ int16_t ads1255_read_fast_single(void){
uint8_t uint[2];
int16_t int16;
} input_buffer;
-
-// uint8_t commandbuffer = ADS_RDATA;
-
-// spi_select_device(&SPIE, &spi_device_conf);
-// spi_write_packet(&SPIE, &commandbuffer,1);
-// delay_us(6.5);
-// spi_write_single(&SPIE, CONFIG_SPI_MASTER_DUMMY);
-// while(!spi_is_rx_full(&SPIE));
-// input_buffer.uint[1] = spi_get(&SPIE);
-// spi_write_single(&SPIE, CONFIG_SPI_MASTER_DUMMY);
-// while(!spi_is_rx_full(&SPIE));
-// input_buffer.uint[0] = spi_get(&SPIE);
-// spi_deselect_device(&SPIE, &spi_device_conf);
usart_spi_select_device(&USARTE1, &spi_device_conf);
usart_spi_transmit(&USARTE1, ADS_RDATA);
@@ -222,32 +162,11 @@ int16_t ads1255_read_fast_single(void){
int32_t ads1255_read(void){
-/* irqflags_t flags;*/
union{
uint8_t uint[4];
int32_t int32;
} input_buffer;
-
- //int32_t returnvalue = 0;
-/* while (ioport_pin_is_high(IOPORT_CREATE_PIN(PORTE, 3)));*/
-
-/* flags = cpu_irq_save();*/
-
-// spi_select_device(&SPIE, &spi_device_conf);
-// spi_write_single(&SPIE, CONFIG_SPI_MASTER_DUMMY);
-// while(!spi_is_rx_full(&SPIE));
-// input_buffer.uint[2] = spi_get(&SPIE);
-// spi_write_single(&SPIE, CONFIG_SPI_MASTER_DUMMY);
-// while(!spi_is_rx_full(&SPIE));
-// input_buffer.uint[1] = spi_get(&SPIE);
-// spi_write_single(&SPIE, CONFIG_SPI_MASTER_DUMMY);
-// while(!spi_is_rx_full(&SPIE));
-// input_buffer.uint[0] = spi_get(&SPIE);
-//
-// spi_deselect_device(&SPIE, &spi_device_conf);
-/* cpu_irq_restore(flags);*/
-
usart_spi_select_device(&USARTE1, &spi_device_conf);
for (int i = 2; i >= 0; --i)
{
@@ -256,16 +175,11 @@ int32_t ads1255_read(void){
while (usart_rx_is_complete(&USARTE1) == false);
input_buffer.uint[i] = usart_get(&USARTE1);
}
- while (!usart_tx_is_complete(&USARTE1));
- usart_clear_tx_complete(&USARTE1);
+ while (!usart_tx_is_complete(&USARTE1));
+ usart_clear_tx_complete(&USARTE1);
-// usart_spi_read_packet(&USARTE1, (uint8_t*)&(input_buffer.uint[2]),1);
-// usart_spi_read_packet(&USARTE1, (uint8_t*)&(input_buffer.uint[1]),1);
-// usart_spi_read_packet(&USARTE1, (uint8_t*)&(input_buffer.uint[0]),1);
usart_spi_deselect_device(&USARTE1, &spi_device_conf);
-// printf("%x, %x, %x\n\r", input_buffer.uint[2],input_buffer.uint[1], input_buffer.uint[0]);
-
if (input_buffer.uint[2] > 0x7F)
input_buffer.uint[3] = 0xFF;
else
@@ -299,7 +213,6 @@ int32_t ads1255_read(void){
else
buffer_iter++;
}
-
return input_buffer.int32;
}
@@ -311,19 +224,6 @@ int32_t ads1255_read_fast24(void){
} input_buffer;
input_buffer.int32 = 0;
-
-// spi_select_device(&SPIE, &spi_device_conf);
-// spi_write_single(&SPIE, CONFIG_SPI_MASTER_DUMMY);
-// while(!spi_is_rx_full(&SPIE));
-// input_buffer.uint[2] = spi_get(&SPIE);
-// spi_write_single(&SPIE, CONFIG_SPI_MASTER_DUMMY);
-// while(!spi_is_rx_full(&SPIE));
-// input_buffer.uint[1] = spi_get(&SPIE);
-// spi_write_single(&SPIE, CONFIG_SPI_MASTER_DUMMY);
-// while(!spi_is_rx_full(&SPIE));
-// input_buffer.uint[0] = spi_get(&SPIE);
-//
-// spi_deselect_device(&SPIE, &spi_device_conf);
usart_spi_select_device(&USARTE1, &spi_device_conf);
for (int i = 2; i >= 0; --i){
@@ -346,27 +246,17 @@ int32_t ads1255_read_fast24(void){
return input_buffer.int32;
}
-
void ads1255_reg_read(uint8_t address){
uint8_t command_buffer[2];
command_buffer[0] = address;
command_buffer[0] |= (1 << 4);
command_buffer[1] = 4;
uint8_t input_buffer[5];
-
-// spi_select_device(&SPIE, &spi_device_conf);
-// //delay_us(50);
-//
-// while (ioport_pin_is_high(IOPORT_CREATE_PIN(PORTE, 3)));
-//
-// spi_write_packet(&SPIE, &command_buffer[0], 2);
-// delay_us(6.5);
-// spi_read_packet(&SPIE, (uint8_t*) &input_buffer, 5);
-// spi_deselect_device(&SPIE, &spi_device_conf);
usart_spi_select_device(&USARTE1, &spi_device_conf);
- while (ioport_pin_is_high(IOPORT_CREATE_PIN(PORTD, 5)));
+// while (ioport_pin_is_high(IOPORT_CREATE_PIN(PORTD, 5)));
+ while (arch_ioport_get_pin_level(IOPORT_CREATE_PIN(PORTD, 5)))
usart_spi_write_packet(&USARTE1, &(command_buffer[0]), 2);
delay_us(6.5);
@@ -374,83 +264,45 @@ void ads1255_reg_read(uint8_t address){
usart_spi_deselect_device(&USARTE1, &spi_device_conf);
for (int i=0;i<5;i++)
- {
printf("ADS1255: Register %u=%.2x\n\r",i+1,input_buffer[i]);
- }
return;
}
void ads1255_reset(){
-// uint8_t command_buffer = ADS_RESET;
-//
-// spi_select_device(&SPIE, &spi_device_conf);
-// //delay_us(50);
-//
-// while (ioport_pin_is_high(IOPORT_CREATE_PIN(PORTE, 3)));
-// spi_write_packet(&SPIE, (uint8_t*) &command_buffer, 1);
-//
-
usart_spi_select_device(&USARTE1, &spi_device_conf);
- while (ioport_pin_is_high(IOPORT_CREATE_PIN(PORTD, 5)));
+// while (ioport_pin_is_high(IOPORT_CREATE_PIN(PORTD, 5)));
+ while (arch_ioport_get_pin_level(IOPORT_CREATE_PIN(PORTD, 5)));
usart_spi_transmit(&USARTE1, ADS_RESET);
#ifdef ADS1255_DBG
printf("ADS1255: Sending RESET\n\r");
printf("ADS1255: Waiting for calibration\n\r");
#endif
- while (ioport_pin_is_high(IOPORT_CREATE_PIN(PORTD, 5)));
- usart_spi_deselect_device(&USARTE1, &spi_device_conf);
-
-// while (ioport_pin_is_high(IOPORT_CREATE_PIN(PORTE, 3)));
-// spi_deselect_device(&SPIE, &spi_device_conf);
+// while (ioport_pin_is_high(IOPORT_CREATE_PIN(PORTD, 5)));
+ while (arch_ioport_get_pin_level(IOPORT_CREATE_PIN(PORTD, 5)));
+ usart_spi_deselect_device(&USARTE1, &spi_device_conf);
return;
}
void ads1255_setup(uint8_t buff, uint8_t rate, uint8_t pga){
-// uint8_t ctrlbuffer = ADS_SDATAC;
uint8_t command_buffer[6] = {0x50,0x03,buff,0x01,pga,rate};
-
-// spi_select_device(&SPIE, &spi_device_conf);
-// //delay_us(50);
-//
-// //while (ioport_pin_is_high(IOPORT_CREATE_PIN(PORTE, 3)));
-//
-// spi_write_packet(&SPIE, &ctrlbuffer, 1);
-// //while (ioport_pin_is_high(IOPORT_CREATE_PIN(PORTE, 3)));
-//
-// spi_write_packet(&SPIE, (uint8_t*)&command_buffer, 6);
-//
-// ctrlbuffer = ADS_SYNC;
-// spi_write_packet(&SPIE, &ctrlbuffer, 1);
-// ctrlbuffer = ADS_SELFCAL;
-// spi_write_packet(&SPIE, &ctrlbuffer, 1);
-// while (ioport_pin_is_high(IOPORT_CREATE_PIN(PORTE, 3)));
-//
-//
-// spi_deselect_device(&SPIE, &spi_device_conf);
-
+
usart_spi_select_device(&USARTE1, &spi_device_conf);
-// usart_spi_transmit(&USARTE1, ADS_SDATAC);
usart_spi_transmit(&USARTE1, ADS_SDATAC);
usart_spi_write_packet(&USARTE1, (uint8_t*)&command_buffer, 6);
usart_spi_transmit(&USARTE1, ADS_SYNC);
usart_spi_transmit(&USARTE1, ADS_SELFCAL);
- while (ioport_pin_is_high(IOPORT_CREATE_PIN(PORTD, 5)));
+// while (ioport_pin_is_high(IOPORT_CREATE_PIN(PORTD, 5)));
+ while (arch_ioport_get_pin_level(IOPORT_CREATE_PIN(PORTD, 5)));
usart_spi_deselect_device(&USARTE1, &spi_device_conf);
return;
}
void ads1255_standby(void){
-// uint8_t ctrlbuffer = ADS_STANDBY;
-//
-// spi_select_device(&SPIE, &spi_device_conf);
-// spi_write_packet(&SPIE, &ctrlbuffer, 1);
-// spi_deselect_device(&SPIE, &spi_device_conf);
-
usart_spi_select_device(&USARTE1, &spi_device_conf);
usart_spi_transmit(&USARTE1, ADS_STANDBY);
usart_spi_deselect_device(&USARTE1, &spi_device_conf);
@@ -459,12 +311,6 @@ void ads1255_standby(void){
}
void ads1255_wakeup(void){
-// uint8_t ctrlbuffer = ADS_WAKEUP;
-//
-// spi_select_device(&SPIE, &spi_device_conf);
-// spi_write_packet(&SPIE, &ctrlbuffer, 1);
-// spi_deselect_device(&SPIE, &spi_device_conf);
-
usart_spi_select_device(&USARTE1, &spi_device_conf);
usart_spi_transmit(&USARTE1, ADS_WAKEUP);
usart_spi_deselect_device(&USARTE1, &spi_device_conf);
@@ -473,20 +319,11 @@ void ads1255_wakeup(void){
}
void ads1255_rdatac(void){
-// uint8_t ctrlbuffer = ADS_RDATAC;
-//
-// spi_select_device(&SPIE, &spi_device_conf);
-// //delay_us(50);
-//
-// spi_write_packet(&SPIE, &ctrlbuffer, 1);
-// while (ioport_pin_is_high(IOPORT_CREATE_PIN(PORTE, 3)));
-//
-// spi_deselect_device(&SPIE, &spi_device_conf);
-
usart_spi_select_device(&USARTE1, &spi_device_conf);
usart_spi_transmit(&USARTE1, ADS_RDATAC);
-// while(!usart_spi_is_rx_full(&USARTE1));
- while (ioport_pin_is_high(IOPORT_CREATE_PIN(PORTD, 5)));
+
+// while (ioport_pin_is_high(IOPORT_CREATE_PIN(PORTD, 5)));
+ while (arch_ioport_get_pin_level(IOPORT_CREATE_PIN(PORTD, 5)));
usart_spi_deselect_device(&USARTE1, &spi_device_conf);
return;
diff --git a/DSTAT-temp/src/ads1255.h b/DSTAT-temp/src/ads1255.h
index f22bcaf5233f38c61fc3a23ea4c8c741dd3b6c8d..c59d13cab718c58e8a7b157ffb21ac74b7f124da 100644
--- a/DSTAT-temp/src/ads1255.h
+++ b/DSTAT-temp/src/ads1255.h
@@ -9,6 +9,13 @@
#ifndef ADS1255_H_
#define ADS1255_H_
+#include
+#include
+#include
+#include
+#include
+#include
+
//#define ADS1255_DBG
#define ADS_WAKEUP 0x0
@@ -56,8 +63,6 @@
#define ADS_UNDERCURRENT_THRESHOLD 200000L
#define ADS_OVER_UNDER_SAMPLES 3
- #include
- #include
int8_t over_under[ADS_OVER_UNDER_SAMPLES];
diff --git a/DSTAT-temp/src/config/conf_experiment.h b/DSTAT-temp/src/config/conf_experiment.h
new file mode 100644
index 0000000000000000000000000000000000000000..d9e101e36cc3980b9fc134126b747914fd202b4a
--- /dev/null
+++ b/DSTAT-temp/src/config/conf_experiment.h
@@ -0,0 +1,16 @@
+/*
+ * conf_experiment.h
+ *
+ * Created: 01/10/2012 11:27:17 PM
+ * Author: mdryden
+ */
+
+
+#ifndef CONF_EXPERIMENT_H_
+#define CONF_EXPERIMENT_H_
+
+
+
+
+
+#endif /* CONF_EXPERIMENT_H_ */
\ No newline at end of file
diff --git a/DSTAT-temp/src/experiment.c b/DSTAT-temp/src/experiment.c
new file mode 100644
index 0000000000000000000000000000000000000000..0ba61e6da323d99de180faa4d59c00b64d80794d
--- /dev/null
+++ b/DSTAT-temp/src/experiment.c
@@ -0,0 +1,395 @@
+/*
+ * experiment.c
+ *
+ * Created: 01/10/2012 10:59:48 PM
+ * Author: mdryden
+ */
+
+#include "experiment.h"
+
+//Private variables
+volatile int32_t voltage = 0;
+volatile uint16_t dacindex = 0;
+uint16_t dacindex_stop = 0;
+volatile int8_t up = 1;
+volatile uint16_t iter = 0;
+uint16_t* eis_ptr = 0;
+volatile uint16_t cycles = 0;
+volatile uint16_t samples = 0;
+volatile uint16_t tcf0period = 0;
+uint32_t skip_samples = 0;
+
+//Private function declarations
+static void porte_int0_lsv(void);
+static void tcf0_ovf_callback(void);
+static void tce1_ovf_callback_lsv(void);
+static void lsv_cca_callback(void);
+
+//interrupt callback setup
+typedef void (*port_callback_t) (void);
+
+static port_callback_t portd_int0_callback;
+static port_callback_t portd_int1_callback;
+
+void pot_init(void){
+ arch_ioport_set_port_dir(IOPORT_PORTB, PIN3_bm|PIN4_bm|PIN5_bm|PIN6_bm|PIN7_bm, IOPORT_DIR_OUTPUT);
+ arch_ioport_set_port_dir(IOPORT_PORTD, PIN4_bm, IOPORT_DIR_OUTPUT);
+ arch_ioport_set_port_level(IOPORT_PORTB, PIN3_bm|PIN4_bm|PIN5_bm|PIN6_bm|PIN7_bm, PIN6_bm|PIN7_bm);
+ arch_ioport_set_port_level(IOPORT_PORTD, PIN4_bm, PIN4_bm);
+}
+
+int8_t autogainswitch(void){
+ extern int8_t over_under[ADS_OVER_UNDER_SAMPLES]; //from ads1255.h
+ int8_t overcurrent = 0;
+ static uint8_t hysteresis = 0;
+ static uint8_t last_return = 0;
+
+ if (gain == POT_GAIN_500M)
+ return 0;
+
+ if (last_return==1)
+ {
+ last_return=0;
+ return 1;
+ }
+
+ if (hysteresis < ADS_OVER_UNDER_SAMPLES-1){
+ ++hysteresis;
+ return 0;
+ }
+
+ for (uint16_t i = 0; i < ADS_OVER_UNDER_SAMPLES; ++i)
+ overcurrent += over_under[i];
+
+ if (overcurrent == ADS_OVER_UNDER_SAMPLES && gain > POT_GAIN_300)
+ {
+ --gain;
+ pot_set_gain();
+ last_return=1;
+ hysteresis = 0;
+ for (uint16_t i = 0; i < ADS_OVER_UNDER_SAMPLES; ++i)
+ over_under[i]=0;
+
+ return 1;
+ }
+
+ if ((overcurrent*-1) == (ADS_OVER_UNDER_SAMPLES) && gain < POT_GAIN_30M)
+ {
+ if (hysteresis < ADS_OVER_UNDER_SAMPLES+3){
+ ++hysteresis;
+ return 0;
+ }
+
+ ++gain;
+ pot_set_gain();
+ last_return=1;
+ hysteresis = 0;
+ for (uint16_t i = 0; i < ADS_OVER_UNDER_SAMPLES; ++i)
+ over_under[i]=0;
+
+ return 1;
+ }
+ hysteresis = 0;
+ return 0;
+}
+
+void pot_set_gain(void){
+ switch (gain){
+ case POT_GAIN_500M:
+// ioport_configure_port_pin(&PORTB, PIN6_bm, IOPORT_INIT_LOW | IOPORT_DIR_OUTPUT); //A
+// ioport_configure_port_pin(&PORTB, PIN7_bm, IOPORT_INIT_LOW | IOPORT_DIR_OUTPUT); //B
+// ioport_configure_port_pin(&PORTD, PIN4_bm, IOPORT_INIT_LOW | IOPORT_DIR_OUTPUT); //C
+
+ arch_ioport_set_port_level(IOPORT_PORTB, PIN6_bm|PIN7_bm, 0);
+ arch_ioport_set_port_level(IOPORT_PORTD, PIN4_bm, 0);
+
+ printf("INFO: 500M\n\r");
+ break;
+
+ case POT_GAIN_30M:
+// ioport_configure_port_pin(&PORTB, PIN6_bm, IOPORT_INIT_HIGH | IOPORT_DIR_OUTPUT);
+// ioport_configure_port_pin(&PORTB, PIN7_bm, IOPORT_INIT_LOW | IOPORT_DIR_OUTPUT);
+// ioport_configure_port_pin(&PORTD, PIN4_bm, IOPORT_INIT_LOW | IOPORT_DIR_OUTPUT);
+
+ arch_ioport_set_port_level(IOPORT_PORTB, PIN6_bm|PIN7_bm, PIN6_bm);
+ arch_ioport_set_port_level(IOPORT_PORTD, PIN4_bm, 0);
+ printf("INFO: 30M\n\r");
+ break;
+
+ case POT_GAIN_3M:
+// ioport_configure_port_pin(&PORTB, PIN6_bm, IOPORT_INIT_LOW | IOPORT_DIR_OUTPUT);
+// ioport_configure_port_pin(&PORTB, PIN7_bm, IOPORT_INIT_HIGH | IOPORT_DIR_OUTPUT);
+// ioport_configure_port_pin(&PORTD, PIN4_bm, IOPORT_INIT_LOW | IOPORT_DIR_OUTPUT);
+
+ arch_ioport_set_port_level(IOPORT_PORTB, PIN6_bm|PIN7_bm, PIN7_bm);
+ arch_ioport_set_port_level(IOPORT_PORTD, PIN4_bm, 0);
+ printf("INFO: 3M\n\r");
+ break;
+
+ case POT_GAIN_300k:
+// ioport_configure_port_pin(&PORTB, PIN6_bm, IOPORT_INIT_HIGH | IOPORT_DIR_OUTPUT);
+// ioport_configure_port_pin(&PORTB, PIN7_bm, IOPORT_INIT_HIGH | IOPORT_DIR_OUTPUT);
+// ioport_configure_port_pin(&PORTD, PIN4_bm, IOPORT_INIT_LOW | IOPORT_DIR_OUTPUT);
+
+ arch_ioport_set_port_level(IOPORT_PORTB, PIN6_bm|PIN7_bm, PIN6_bm|PIN7_bm);
+ arch_ioport_set_port_level(IOPORT_PORTD, PIN4_bm, 0);
+ printf("INFO: 300k\n\r");
+ break;
+
+ case POT_GAIN_30k:
+// ioport_configure_port_pin(&PORTB, PIN6_bm, IOPORT_INIT_LOW | IOPORT_DIR_OUTPUT);
+// ioport_configure_port_pin(&PORTB, PIN7_bm, IOPORT_INIT_LOW | IOPORT_DIR_OUTPUT);
+// ioport_configure_port_pin(&PORTD, PIN4_bm, IOPORT_INIT_HIGH | IOPORT_DIR_OUTPUT);
+
+ arch_ioport_set_port_level(IOPORT_PORTB, PIN6_bm|PIN7_bm, 0);
+ arch_ioport_set_port_level(IOPORT_PORTD, PIN4_bm, PIN4_bm);
+ printf("INFO: 30k\n\r");
+ break;
+
+ case POT_GAIN_3k:
+// ioport_configure_port_pin(&PORTB, PIN6_bm, IOPORT_INIT_HIGH | IOPORT_DIR_OUTPUT);
+// ioport_configure_port_pin(&PORTB, PIN7_bm, IOPORT_INIT_LOW | IOPORT_DIR_OUTPUT);
+// ioport_configure_port_pin(&PORTD, PIN4_bm, IOPORT_INIT_HIGH | IOPORT_DIR_OUTPUT);
+
+ arch_ioport_set_port_level(IOPORT_PORTB, PIN6_bm|PIN7_bm, PIN6_bm);
+ arch_ioport_set_port_level(IOPORT_PORTD, PIN4_bm, PIN4_bm);
+ printf("INFO: 3k\n\r");
+ break;
+
+ case POT_GAIN_300:
+// ioport_configure_port_pin(&PORTB, PIN6_bm, IOPORT_INIT_LOW | IOPORT_DIR_OUTPUT);
+// ioport_configure_port_pin(&PORTB, PIN7_bm, IOPORT_INIT_HIGH | IOPORT_DIR_OUTPUT);
+// ioport_configure_port_pin(&PORTD, PIN4_bm, IOPORT_INIT_HIGH | IOPORT_DIR_OUTPUT);
+
+ arch_ioport_set_port_level(IOPORT_PORTB, PIN6_bm|PIN7_bm, PIN7_bm);
+ arch_ioport_set_port_level(IOPORT_PORTD, PIN4_bm, PIN4_bm);
+ printf("INFO: 300\n\r");
+ break;
+
+ case POT_GAIN_100:
+// ioport_configure_port_pin(&PORTB, PIN6_bm, IOPORT_INIT_HIGH | IOPORT_DIR_OUTPUT);
+// ioport_configure_port_pin(&PORTB, PIN7_bm, IOPORT_INIT_HIGH | IOPORT_DIR_OUTPUT);
+// ioport_configure_port_pin(&PORTD, PIN4_bm, IOPORT_INIT_HIGH | IOPORT_DIR_OUTPUT);
+
+ arch_ioport_set_port_level(IOPORT_PORTB, PIN6_bm|PIN7_bm, PIN6_bm|PIN7_bm);
+ arch_ioport_set_port_level(IOPORT_PORTD, PIN4_bm, PIN4_bm);
+ printf("INFO: 100\n\r");
+ break;
+
+ default:
+ printf("WAR: Invalid pot gain.\n\r");
+ break;
+
+ return;
+ }
+}
+
+void pot_exp_start(void){
+// ioport_configure_port_pin(&PORTB, PIN3_bm, IOPORT_INIT_HIGH | IOPORT_DIR_OUTPUT);
+// ioport_configure_port_pin(&PORTB, PIN4_bm, IOPORT_INIT_HIGH | IOPORT_DIR_OUTPUT);
+// ioport_configure_port_pin(&PORTB, PIN5_bm, IOPORT_INIT_HIGH | IOPORT_DIR_OUTPUT);
+
+ arch_ioport_set_port_level(IOPORT_PORTB, PIN3_bm|PIN4_bm|PIN5_bm, PIN3_bm|PIN4_bm|PIN5_bm);
+}
+
+void pot_exp_stop(void){
+// ioport_configure_port_pin(&PORTB, PIN3_bm, IOPORT_INIT_LOW | IOPORT_DIR_OUTPUT);
+// ioport_configure_port_pin(&PORTB, PIN4_bm, IOPORT_INIT_LOW | IOPORT_DIR_OUTPUT);
+// ioport_configure_port_pin(&PORTB, PIN5_bm, IOPORT_INIT_LOW | IOPORT_DIR_OUTPUT);
+
+ arch_ioport_set_port_level(IOPORT_PORTB, PIN3_bm|PIN4_bm|PIN5_bm, 0);
+}
+
+void cv_experiment(int16_t v1, int16_t v2, int16_t start, uint8_t scans, uint16_t slope){
+ // check if start is [v1,v2]
+ int8_t firstrun = 1;
+
+ if((start < v1 && start < v2) || (start > v1 && start > v2))
+ {
+ printf("ERR: Start must be within [v1, v2]\n\r");
+ return;
+ }
+
+ RTC.CTRL = RTC_PRESCALER_OFF_gc;
+ while (RTC.STATUS & RTC_SYNCBUSY_bm);
+ RTC.CNT = 0;
+ RTC.PER = 0xffff;
+ RTC.CTRL = RTC_PRESCALER_DIV1024_gc; // 1 s tick
+
+
+ while(scans > 0){
+ if (start != v1){
+ lsv_experiment(start,v1,slope,firstrun);
+ firstrun = 0;
+ }
+ if (start == v2 && scans == 1)
+ firstrun = -1;
+ lsv_experiment(v1,v2,slope,firstrun);
+ if (scans == 1)
+ firstrun = -1;
+ if (start != v2)
+ lsv_experiment(v2,start,slope,firstrun);
+ --scans;
+ firstrun = 0;
+ }
+
+ printf("Time: %lu s \n\r", rtc_get_time());
+
+ return;
+}
+
+void lsv_experiment(int16_t start, int16_t stop, uint16_t slope, int8_t first_run){
+ //check experiment limits
+ if(start<-1500 || start>1500 ||start==stop|| stop<-1500 || stop>1500 || slope>7000)
+ {
+ printf("ERR: Experiment parameters outside limits\n\r");
+ return;
+ }
+
+ uint16_t dacindex_start = ceil(start*(65535/(double)3000)+32767);
+ dacindex_stop = ceil(stop*(65535/(double)3000)+32767);
+ // uint16_t period;
+ uint32_t timer_period;
+ uint16_t temp_div;
+
+ max5443_set_voltage1(dacindex_start);
+
+ if (first_run == 1 || first_run == 2){
+ pot_exp_start();
+ ads1255_rdatac();
+ tc_enable(&TCC1);
+
+ ads1255_sync();
+
+ tc_enable(&TCC0);
+ tc_set_overflow_interrupt_callback(&TCC0, tcf0_ovf_callback);
+ tc_set_overflow_interrupt_callback(&TCC1, tce1_ovf_callback_lsv);
+ tc_set_cca_interrupt_callback(&TCC1, lsv_cca_callback);
+ portd_int0_callback = porte_int0_lsv;
+
+ //set EVCH0 event
+ EVSYS.CH0MUX = EVSYS_CHMUX_TCC0_OVF_gc;
+ EVSYS.CH0CTRL = 0;
+
+ timer_period = ceil(1/((double)slope/(3000./65535))*(F_CPU));
+ temp_div = ceil(timer_period/65535.);
+
+ if (temp_div <= 1)
+ tc_write_clock_source(&TCC0,TC_CLKSEL_DIV1_gc);
+ else if (temp_div == 2){
+ tc_write_clock_source(&TCC0,TC_CLKSEL_DIV2_gc);
+ timer_period /= 2;
+ }
+ else if (temp_div <= 4){
+ tc_write_clock_source(&TCC0,TC_CLKSEL_DIV4_gc);
+ timer_period /= 4;
+ }
+ else if (temp_div <= 8){
+ tc_write_clock_source(&TCC0,TC_CLKSEL_DIV8_gc);
+ timer_period /= 8;
+ }
+ else if (temp_div <= 64){
+ tc_write_clock_source(&TCC0,TC_CLKSEL_DIV64_gc);
+ timer_period /= 64;
+ }
+ else if (temp_div <= 256){
+ tc_write_clock_source(&TCC0,TC_CLKSEL_DIV256_gc);
+ timer_period /= 256;
+ }
+ else if (temp_div <= 1024){
+ tc_write_clock_source(&TCC0,TC_CLKSEL_DIV1024_gc);
+ timer_period /= 1024;
+ }
+ else{
+ printf("ERR: Frequency/ADC rate is too low\n\r");
+ return;
+ }
+
+ printf("Period:%lu\n\r", timer_period);
+ ads1255_wakeup();
+ tc_write_period(&TCC1, 0xffff);
+ tc_write_period(&TCC0, (uint16_t)timer_period);
+ }
+
+ TCC1.CNT = dacindex_start;
+
+ if (stop > start)
+ {
+ up = 1;
+ tc_set_direction(&TCC1, TC_UP);
+ }
+ else
+ {
+ up = -1;
+ tc_set_direction(&TCC1, TC_DOWN);
+ }
+
+ tc_write_cc(&TCC1, TC_CCA, dacindex_stop);
+ tc_enable_cc_channels(&TCC1, TC_CCAEN);
+ TCC0.CNT = 0;
+
+ tc_set_cca_interrupt_level(&TCC1, TC_INT_LVL_HI);
+ tc_set_overflow_interrupt_level(&TCC0, TC_OVFINTLVL_MED_gc);
+ PORTD.INTCTRL = PORT_INT0LVL_LO_gc;
+
+ tc_write_clock_source(&TCC1, TC_CLKSEL_EVCH0_gc);
+
+ while (up != 0); //Experiment run with interrupts
+
+ if (first_run == -1 || first_run == 2)
+ {
+ tc_disable(&TCC0);
+ TCC0.CNT = 0x0;
+ tc_disable(&TCC1);
+ pot_exp_stop();
+ ads1255_standby();
+ }
+
+ return;
+}
+
+static void porte_int0_lsv(void){
+ if (autogainswitch()==0){
+// while (ioport_pin_is_high(IOPORT_CREATE_PIN(PORTD, 5)));
+ while (arch_ioport_get_pin_level(IOPORT_CREATE_PIN(PORTD, 5)));
+ if (gain == POT_GAIN_300)
+ printf("%u, %ld00000\n\r", TCC1.CNT, ads1255_read());
+ else if (gain == POT_GAIN_3k)
+ printf("%u, %ld0000\n\r", TCC1.CNT, ads1255_read());
+ else if (gain == POT_GAIN_30k)
+ printf("%u, %ld000\n\r", TCC1.CNT, ads1255_read());
+ else if (gain == POT_GAIN_300k)
+ printf("%u, %ld00\n\r", TCC1.CNT, ads1255_read());
+ else if (gain == POT_GAIN_3M)
+ printf("%u, %ld0\n\r", TCC1.CNT, ads1255_read());
+ else if (gain == POT_GAIN_30M)
+ printf("%u, %ld\n\r", TCC1.CNT, ads1255_read());
+ else
+ printf("%u, %lu\n\r", TCC1.CNT, ads1255_read());
+ }
+ else{
+// while (ioport_pin_is_high(IOPORT_CREATE_PIN(PORTD, 5)));
+ while (arch_ioport_get_pin_level(IOPORT_CREATE_PIN(PORTD, 5)));
+ ads1255_read();
+ }
+}
+
+static void tcf0_ovf_callback(void){
+ max5443_set_voltage1(TCC1.CNT);
+}
+
+static void tce1_ovf_callback_lsv(void){
+ PORTD.INTCTRL = PORT_INT0LVL_OFF_gc;
+ tc_set_overflow_interrupt_level(&TCC0, TC_OVFINTLVL_OFF_gc);
+ tc_set_overflow_interrupt_level(&TCC1, TC_OVFINTLVL_OFF_gc);
+ up = 0;
+ return;
+}
+
+static void lsv_cca_callback(void){
+ PORTD.INTCTRL = PORT_INT0LVL_OFF_gc;
+ tc_set_overflow_interrupt_level(&TCC0, TC_OVFINTLVL_OFF_gc);
+ tc_set_cca_interrupt_level(&TCC1, TC_INT_LVL_OFF);
+ up = 0;
+ return;
+}
\ No newline at end of file
diff --git a/DSTAT-temp/src/experiment.h b/DSTAT-temp/src/experiment.h
new file mode 100644
index 0000000000000000000000000000000000000000..50c7672ba03ff1ff6b2d5a5bd4a43494aa00514e
--- /dev/null
+++ b/DSTAT-temp/src/experiment.h
@@ -0,0 +1,66 @@
+/*
+ * experiment.h
+ *
+ * Created: 01/10/2012 10:59:59 PM
+ * Author: mdryden
+ */
+
+
+#ifndef EXPERIMENT_H_
+#define EXPERIMENT_H_
+
+#include "conf_experiment.h"
+
+#include "ads1255.h"
+#include "max5443.h"
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+
+#define POT_GAIN_100 0
+#define POT_GAIN_300 1
+#define POT_GAIN_3k 2
+#define POT_GAIN_30k 3
+#define POT_GAIN_300k 4
+#define POT_GAIN_3M 5
+#define POT_GAIN_30M 6
+#define POT_GAIN_500M 7
+
+#define POT_LP_OFF 0
+#define POT_LP_ON 1
+
+#define ADS_F_2_5 0
+#define ADS_F_5 1
+#define ADS_F_10 2
+#define ADS_F_15 3
+#define ADS_F_25 4
+#define ADS_F_30 5
+#define ADS_F_50 6
+#define ADS_F_60 7
+#define ADS_F_100 8
+#define ADS_F_500 9
+#define ADS_F_1000 10
+#define ADS_F_2000 11
+#define ADS_F_3750 12
+#define ADS_F_7500 13
+#define ADS_F_15000 14
+#define ADS_F_30000 15
+
+#define SIN_IMP_CYCLEPTS 50
+
+uint8_t gain;
+
+void pot_init(void);
+int8_t autogainswitch(void);
+void pot_set_gain(void);
+void pot_exp_start(void);
+void pot_exp_stop(void);
+void cv_experiment(int16_t v1, int16_t v2, int16_t start, uint8_t scans, uint16_t slope);
+void lsv_experiment(int16_t start, int16_t stop, uint16_t slope, int8_t first_run);
+
+#endif /* EXPERIMENT_H_ */
\ No newline at end of file
diff --git a/DSTAT-temp/src/main.c b/DSTAT-temp/src/main.c
index abffdd9d2c44e33de248782f4ac3ef26b2dae6d9..5c1ebb333fe6a85a69a57404c73972f16a29e2e5 100644
--- a/DSTAT-temp/src/main.c
+++ b/DSTAT-temp/src/main.c
@@ -5,17 +5,12 @@
* Author: mdryden
*/
-#include
#include "main.h"
-#include
-#include
-#include
-#include "ads1255.h"
-#include "max5443.h"
-void main(void){
+int main(void){
board_init();
+ pot_init();
pmic_init();
irq_initialize_vectors();
@@ -29,15 +24,10 @@ void main(void){
stdio_usb_init();
stdio_usb_enable();
- // printf("DStat v1 25 Jun 2012\n\r");
ads1255_init_pins();
ads1255_init_module();
ads1255_setup(ADS_BUFF_ON,ADS_DR_60,ADS_PGA_2);
- // // PORTE.INT0MASK = PIN3_bm;
- // // PORTE.INT1MASK = PIN3_bm;
- // // PORTE.INTCTRL = PORT_INT0LVL_OFF_gc;
- // // PORTE.INTCTRL = PORT_INT1LVL_OFF_gc;
PORTD.INT0MASK = PIN5_bm;
PORTD.INT1MASK = PIN5_bm;
PORTD.INTCTRL = PORT_INT0LVL_OFF_gc | PORT_INT1LVL_OFF_gc;
@@ -56,7 +46,6 @@ void main(void){
ads1255_wakeup();
ads1255_rdatac();
- int32_t data1 = 0;
// max5443_set_voltage1(21845); //1V
// pot_exp_start();
diff --git a/DSTAT-temp/src/main.h b/DSTAT-temp/src/main.h
index 0c4c577339296221026f8f42a3e10e87398e2393..dfc827a905553f8b2300103d32b0645f25dc041f 100644
--- a/DSTAT-temp/src/main.h
+++ b/DSTAT-temp/src/main.h
@@ -4,7 +4,16 @@
* Created: 06/04/2012 1:19:58 AM
* Author: mdryden
*/
+#ifndef MAIN_H
+#define MAIN_H
+#include "asf.h"
+#include
+#include
+#include
+#include "ads1255.h"
+#include "max5443.h"
+#include "experiment.h"
int8_t autogainswitch(void);
void menu(uint8_t selection);
@@ -52,3 +61,5 @@ void eis_waveform(int16_t offset, int16_t amplitude, uint32_t freq, uint16_t cyc
#define ADS_F_30000 15
#define SIN_IMP_CYCLEPTS 50
+
+#endif
\ No newline at end of file
diff --git a/DSTAT-temp/src/max5443.c b/DSTAT-temp/src/max5443.c
index c08d7b6a6eba7554d3e1eb37778b10a55c2e2d54..e9755662f75a6d08e8a5c4f31f5e7a7b2778b4fc 100644
--- a/DSTAT-temp/src/max5443.c
+++ b/DSTAT-temp/src/max5443.c
@@ -6,40 +6,22 @@
*/
#include
-// #include
-// #include
-// #include
-
-// struct spi_device spi_device_conf_c = {
-// .id = IOPORT_CREATE_PIN(PORTC, 4)
-// };
struct usart_spi_device spi_device_conf_c = {
.id = IOPORT_CREATE_PIN(PORTC, 4)
};
void max5443_init_pins(void){
- ioport_configure_port_pin(&PORTC, PIN4_bm, IOPORT_INIT_HIGH | IOPORT_DIR_OUTPUT);
- ioport_configure_port_pin(&PORTC, PIN5_bm, IOPORT_INIT_HIGH | IOPORT_DIR_OUTPUT);
- ioport_configure_port_pin(&PORTC, PIN7_bm, IOPORT_INIT_HIGH | IOPORT_DIR_OUTPUT);
-// ioport_configure_port_pin(&PORTC, PIN3_bm, IOPORT_INIT_LOW | IOPORT_DIR_OUTPUT); //CLR
-// delay_us(1);
-// ioport_configure_port_pin(&PORTC, PIN3_bm, IOPORT_INIT_HIGH | IOPORT_DIR_OUTPUT);
+ arch_ioport_set_port_dir(IOPORT_PORTF, PIN4_bm|PIN5_bm|PIN7_bm, IOPORT_DIR_OUTPUT);
+ arch_ioport_set_port_level(IOPORT_PORTF, PIN4_bm|PIN5_bm|PIN7_bm, PIN4_bm|PIN5_bm|PIN7_bm);
}
void max5443_init_module(void){
-// spi_master_init(&SPIC);
-// spi_master_setup_device(&SPIC, &spi_device_conf_c, SPI_MODE_0, 24000000UL, 0);
-// spi_enable(&SPIC);
-
usart_spi_init(&USARTC1);
usart_spi_setup_device(&USARTC1, &spi_device_conf_c, SPI_MODE_0, 24000000UL, 0);
-// usart_spi_enable(&USARTC1);
}
void max5443_set_voltage1(uint16_t dacindex){
-/* char logstr[10];*/
-
static union{
uint8_t ui8[2];
uint16_t ui16;
@@ -52,12 +34,6 @@ void max5443_set_voltage1(uint16_t dacindex){
irqflags_t flags;
flags = cpu_irq_save();
-
-// spi_select_device(&SPIC, &spi_device_conf_c);
-// spi_write_single(&SPIC, buffer.ui8[1]);
-// delay_cycles(40);
-// spi_write_single(&SPIC, buffer.ui8[0]);
-// spi_deselect_device(&SPIC, &spi_device_conf_c);
usart_spi_select_device(&USARTC1, &spi_device_conf_c);
usart_spi_write_single(&USARTC1, buffer.ui8[1]);
diff --git a/DSTAT-temp/src/max5443.h b/DSTAT-temp/src/max5443.h
index 9f7bd996b6c52b1304b01145ac8f6d97820edcdd..1fae84254f023a2f803babfae055bcaf0ca7bcc1 100644
--- a/DSTAT-temp/src/max5443.h
+++ b/DSTAT-temp/src/max5443.h
@@ -8,7 +8,13 @@
#ifndef MAX5443_H_
#define MAX5443_H_
-#include
+
+#include
+#include
+#include
+#include
+#include
+#include
void max5443_init_pins(void);
void max5443_init_module(void);
diff --git a/DSTAT1.atsuo b/DSTAT1.atsuo
index 2be864bcd1e6350ff5fa72039d02fe60e2557156..52f584fcad855065b08fba32ff3ec9296d586451 100644
Binary files a/DSTAT1.atsuo and b/DSTAT1.atsuo differ