Commit d1aa8db5 authored by Ben Z Yuan's avatar Ben Z Yuan

firmware_v2 speed improvements

* Run the XMEGA at 48 MHz
* Read only 2 bytes instead of 4
* Other attempts at improving speed
parent f6f2e8f3
...@@ -129,6 +129,7 @@ int main(void) ...@@ -129,6 +129,7 @@ int main(void)
CDC_Device_USBTask(&VirtualSerial_CDC_Interface); CDC_Device_USBTask(&VirtualSerial_CDC_Interface);
USB_USBTask(); USB_USBTask();
doUSBTask = false; doUSBTask = false;
PORTC.OUT ^= (1 << 0);
} }
} }
...@@ -169,29 +170,27 @@ void ADC_Init() ...@@ -169,29 +170,27 @@ void ADC_Init()
static uint8_t spi_rx_buf[4]; 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))); while(!(PORTC.IN &= (1 << ADC_RVSPIN)));
PORTC.OUT &= ~(1 << 4); PORTC.OUT &= ~(1 << 4);
spi_rx_buf[3] = SPI_ReceiveByte(&SPIC); *(dest + 1) = SPI_ReceiveByte(&SPIC);
spi_rx_buf[2] = SPI_ReceiveByte(&SPIC); *dest = SPI_ReceiveByte(&SPIC);
spi_rx_buf[1] = SPI_ReceiveByte(&SPIC); //spi_rx_buf[1] = SPI_ReceiveByte(&SPIC);
spi_rx_buf[0] = SPI_ReceiveByte(&SPIC); //spi_rx_buf[0] = SPI_ReceiveByte(&SPIC);
PORTC.OUT |= (1 << 4); 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) void ADC_Read_Block(void)
{ {
TCC0.INTCTRLA = TC_OVFINTLVL_OFF_gc; TCC0.INTCTRLA = TC_OVFINTLVL_OFF_gc;
PORTC.OUT &= ~(1 << 0); // PORTC.OUT &= ~(1 << 0);
for(int i = 0; i < ADC_BUFSZ; i++)
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; TCC0.INTCTRLA = TC_OVFINTLVL_LO_gc;
} }
...@@ -227,7 +226,7 @@ void SetupHardware(void) ...@@ -227,7 +226,7 @@ void SetupHardware(void)
/* set up 25ms USB interrupt */ /* set up 25ms USB interrupt */
TCC0.CTRLA = TC_CLKSEL_DIV256_gc; TCC0.CTRLA = TC_CLKSEL_DIV256_gc;
TCC0.PER = 3125; TCC0.PER = F_CPU / 256 / 40;
TCC0.INTCTRLA = TC_OVFINTLVL_LO_gc; TCC0.INTCTRLA = TC_OVFINTLVL_LO_gc;
TCC0.INTFLAGS = 0x01; TCC0.INTFLAGS = 0x01;
TCC0.CTRLB = TC_WGMODE_NORMAL_gc; TCC0.CTRLB = TC_WGMODE_NORMAL_gc;
......
...@@ -53,7 +53,7 @@ ...@@ -53,7 +53,7 @@
uint8_t ReadSignatureByte(uint16_t); uint8_t ReadSignatureByte(uint16_t);
void ADC_Init(void); void ADC_Init(void);
uint16_t ADC_Read(void); void ADC_Read(uint8_t * dest);
void ADC_Read_Block(void); void ADC_Read_Block(void);
void SetupHardware(void); void SetupHardware(void);
......
...@@ -14,9 +14,9 @@ ...@@ -14,9 +14,9 @@
MCU = atxmega16a4u MCU = atxmega16a4u
ARCH = XMEGA ARCH = XMEGA
BOARD = USBKEY BOARD = USBKEY
F_CPU = 32000000 F_CPU = 48000000
F_USB = 48000000 F_USB = 48000000
OPTIMIZATION = s OPTIMIZATION = 3
TARGET = main TARGET = main
SRC = $(TARGET).c Descriptors.c $(LUFA_SRC_USB) $(LUFA_SRC_USBCLASS) SRC = $(TARGET).c Descriptors.c $(LUFA_SRC_USB) $(LUFA_SRC_USBCLASS)
LUFA_PATH = /home/atomicinf/src/lufa-LUFA-170418/LUFA LUFA_PATH = /home/atomicinf/src/lufa-LUFA-170418/LUFA
......
...@@ -46,6 +46,7 @@ def idle(parent, canvas): ...@@ -46,6 +46,7 @@ def idle(parent, canvas):
continue continue
buf = np.frombuffer(tmp, dtype=np.uint16, count=512) buf = np.frombuffer(tmp, dtype=np.uint16, count=512)
buf = buf >> 4
break break
ax.clear() ax.clear()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment