Fix sample rate and offset correction

This commit is contained in:
Markus Koch 2021-03-01 19:11:56 +01:00
parent cac80f1c65
commit 03abf17edc
4 changed files with 11 additions and 13 deletions

View File

@ -139,21 +139,23 @@ void DMA2_Stream0_IRQHandler()
{
int sample;
DMA_ClearFlag(ADC_RX_DMA_STREAM, DMA_FLAG_TCIF0);
//printf("[DMA-IRQ] %d, %d\r\n", adc_buffer[0], adc_buffer[1]);
sample = 2048 - ((adc_buffer[0] + adc_buffer[1]) / 2);
sample = ((adc_buffer[0] + adc_buffer[1]) / 2) - 2048;
GotSample(sample);
}
// Not used:
// Only for debugging. Currently disabled.
void ADC_IRQHandler()
{
ADC_ClearFlag(ADC1, ADC_FLAG_EOC);
//printf("[ADC-IRQ] %d, %d\r\n", adc_buffer[0], adc_buffer[1]);
// printf("[ADC-IRQ] %d, %d\r\n", adc_buffer[0], adc_buffer[1]);
}
void TIM5_IRQHandler()
{
TIM_ClearFlag(TIM5, TIM_FLAG_CC1);
// I would really like to this in HW via events, but somehow it's broken...
ADC_SoftwareStartConv(ADC1);
}

View File

@ -2,7 +2,7 @@
#define _ADC_H
#define ADC_F_TIM 50000000
#define ADC_SAMPLE_RATE 44130
#define ADC_SAMPLE_RATE (40000)
#define ADC_RX_DMA_CHANNEL DMA_Channel_0

View File

@ -4,7 +4,7 @@
#define CCEMBEDDED
#define NUM_LIN_LEDS 60
#define USE_NUM_LIN_LEDS 60
#define DFREQ 44130
#define DFREQ (40000)
#endif

View File

@ -40,8 +40,8 @@ void NewFrame()
int i;
HandleFrameInfo();
// UpdateLinearLEDs();
UpdateAllSameLEDs();
UpdateLinearLEDs();
//UpdateAllSameLEDs();
SendSPI2812( ledOut, NUM_LIN_LEDS );
}
@ -116,14 +116,10 @@ int main(void)
SysTick_Config( RCC_Clocks.HCLK_Frequency / 100);
float fv = RCC_Clocks.HCLK_Frequency / 1000000.0f;
// We can use printf to print back through the debugging interface, but that's slow and
// it also takes up a bunch of space. No printf = no space wasted in printf.
// printf( "Operating at %.3fMHz\n", fv );
ConfigureUART();
InitColorChord();
Configure_PA0();
//InitMP45DT02();
InitSPI2812();
adc_init();
@ -158,7 +154,7 @@ int main(void)
{
LED_OFF; //Use led on the board to show us how much CPU we're using. (You can also probe PB15)
PushSample32( sampbuff[this_samp]/2 ); //Can't put in full volume.
PushSample32( sampbuff[this_samp] ); //Can't put in full volume. (here was /2)
this_samp = (this_samp+1)%CIRCBUFSIZE;