diff --git a/firmware_v2/main.c b/firmware_v2/main.c index aeaa96441ae772829449156f6f091d106e4fb1bc..a64f83e920f66f257f26aa96bbc8c2bcdb54f2d2 100644 --- a/firmware_v2/main.c +++ b/firmware_v2/main.c @@ -129,6 +129,7 @@ int main(void) CDC_Device_USBTask(&VirtualSerial_CDC_Interface); USB_USBTask(); doUSBTask = false; + PORTC.OUT ^= (1 << 0); } } @@ -169,29 +170,27 @@ void ADC_Init() static uint8_t spi_rx_buf[4]; -inline uint16_t ADC_Read(void) +__attribute__((always_inline)) inline void ADC_Read(uint8_t * dest) { while(!(PORTC.IN &= (1 << ADC_RVSPIN))); PORTC.OUT &= ~(1 << 4); - spi_rx_buf[3] = SPI_ReceiveByte(&SPIC); - spi_rx_buf[2] = SPI_ReceiveByte(&SPIC); - spi_rx_buf[1] = SPI_ReceiveByte(&SPIC); - spi_rx_buf[0] = SPI_ReceiveByte(&SPIC); + *(dest + 1) = SPI_ReceiveByte(&SPIC); + *dest = SPI_ReceiveByte(&SPIC); + //spi_rx_buf[1] = SPI_ReceiveByte(&SPIC); + //spi_rx_buf[0] = SPI_ReceiveByte(&SPIC); PORTC.OUT |= (1 << 4); - - //return (uint32_t) *(uint32_t*)spi_rx_buf; - return (uint16_t) ((*(uint16_t*)(spi_rx_buf+2)) >> 4) ; } void ADC_Read_Block(void) { TCC0.INTCTRLA = TC_OVFINTLVL_OFF_gc; - PORTC.OUT &= ~(1 << 0); - for(int i = 0; i < ADC_BUFSZ; i++) + // PORTC.OUT &= ~(1 << 0); + + for(uint8_t * p = (uint8_t*)adc_buf; p < (uint8_t*)(adc_buf + ADC_BUFSZ); p += 2) { - adc_buf[i] = ADC_Read(); + ADC_Read(p); } - PORTC.OUT |= (1 << 0); + // PORTC.OUT |= (1 << 0); TCC0.INTCTRLA = TC_OVFINTLVL_LO_gc; } @@ -227,7 +226,7 @@ void SetupHardware(void) /* set up 25ms USB interrupt */ TCC0.CTRLA = TC_CLKSEL_DIV256_gc; - TCC0.PER = 3125; + TCC0.PER = F_CPU / 256 / 40; TCC0.INTCTRLA = TC_OVFINTLVL_LO_gc; TCC0.INTFLAGS = 0x01; TCC0.CTRLB = TC_WGMODE_NORMAL_gc; diff --git a/firmware_v2/main.h b/firmware_v2/main.h index f8cae590b09e5aa8126d0906513fcb86726a162a..030e473d97b9f3d0135d6ca72347db07d71cdbbd 100644 --- a/firmware_v2/main.h +++ b/firmware_v2/main.h @@ -53,7 +53,7 @@ uint8_t ReadSignatureByte(uint16_t); void ADC_Init(void); - uint16_t ADC_Read(void); + void ADC_Read(uint8_t * dest); void ADC_Read_Block(void); void SetupHardware(void); diff --git a/firmware_v2/makefile b/firmware_v2/makefile index b46a203fc65d39dbd55d06f281f024e49fe434c7..7ce42e26b99d5a3d13461c341a032cea75002b3b 100644 --- a/firmware_v2/makefile +++ b/firmware_v2/makefile @@ -14,9 +14,9 @@ MCU = atxmega16a4u ARCH = XMEGA BOARD = USBKEY -F_CPU = 32000000 +F_CPU = 48000000 F_USB = 48000000 -OPTIMIZATION = s +OPTIMIZATION = 3 TARGET = main SRC = $(TARGET).c Descriptors.c $(LUFA_SRC_USB) $(LUFA_SRC_USBCLASS) LUFA_PATH = /home/atomicinf/src/lufa-LUFA-170418/LUFA diff --git a/plotter/main.py b/plotter/main.py index be91ccee90c4c23c8d2f4b993a5149389a2d4738..b57eb628f27d7780c68e2bb1e5a1058161f47e33 100644 --- a/plotter/main.py +++ b/plotter/main.py @@ -46,6 +46,7 @@ def idle(parent, canvas): continue buf = np.frombuffer(tmp, dtype=np.uint16, count=512) + buf = buf >> 4 break ax.clear()