From 357bc441b674087cc9a9efe6bb22cb12c413db31 Mon Sep 17 00:00:00 2001 From: Michael Dryden Date: Tue, 2 Oct 2012 00:41:18 -0400 Subject: [PATCH] Code cleanup. Conversion to new IOPORT service. Moving experiment code to own file. --- DSTAT-temp/DSTAT-temp.cproj | 529 ++++++++++++------------ DSTAT-temp/src/ads1255.c | 221 ++-------- DSTAT-temp/src/ads1255.h | 9 +- DSTAT-temp/src/config/conf_experiment.h | 16 + DSTAT-temp/src/experiment.c | 395 ++++++++++++++++++ DSTAT-temp/src/experiment.h | 66 +++ DSTAT-temp/src/main.c | 15 +- DSTAT-temp/src/main.h | 11 + DSTAT-temp/src/max5443.c | 28 +- DSTAT-temp/src/max5443.h | 8 +- DSTAT1.atsuo | Bin 34304 -> 42496 bytes 11 files changed, 804 insertions(+), 494 deletions(-) create mode 100644 DSTAT-temp/src/config/conf_experiment.h create mode 100644 DSTAT-temp/src/experiment.c create mode 100644 DSTAT-temp/src/experiment.h diff --git a/DSTAT-temp/DSTAT-temp.cproj b/DSTAT-temp/DSTAT-temp.cproj index f608949..73411be 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 8a4dffb..11e8771 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 f22bcaf..c59d13c 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 0000000..d9e101e --- /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 0000000..0ba61e6 --- /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 0000000..50c7672 --- /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 abffdd9..5c1ebb3 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 0c4c577..dfc827a 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 c08d7b6..e975566 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 9f7bd99..1fae842 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 GIT binary patch delta 3973 zcmcgve^k@g6@M=zfnvlcKg5a1uZd8N3812)20;w|B7h=dS_vUYY7#IBzZ4-Tw$ys8 z;m)q@j#g(^ds^4Era#pB1CL$jTCKYEtbc4;J##<0d2H)kTRjfyns$Bqv=!G#NtxMSUxZhC7ZryeY5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