淘了一块便宜的函数发生器回来,通过电阻分压后测算电压。通过液晶屏显示。
本来弄了个前置放大电路板子,可我模电水平实在不行,弄来弄去弄不好,只能直接分压了。
此时使用的是PA4引脚,ADC0通道4
1-使用计时器每100ms进行一次连续转换
timer_initpara.prescaler = 9999;
timer_initpara.period = 999;
timer_init(TIMER2,&timer_initpara);
timer_interrupt_enable(TIMER2, TIMER_INT_UP);
timer_interrupt_flag_clear(TIMER2, TIMER_INT_FLAG_UP);
// timer_interrupt_flag_clear(TIMER2, TIMER_INT_FLAG_CH1);
// dbg_periph_enable(DBG_TIMER2_HOLD);
nvic_irq_enable(TIMER2_IRQn, 1U, 0U);
/* enable TIMER2 */
timer_enable(TIMER2);
2-定时器中断服务函数
void TIMER2_IRQHandler(void)
{
if(timer_interrupt_flag_get(TIMER2, TIMER_INT_FLAG_UP)==SET)
{
adc_special_function_config(ADC0, ADC_CONTINUOUS_MODE, ENABLE);
adc_software_trigger_enable(ADC0, ADC_REGULAR_CHANNEL);
timer_interrupt_flag_clear(TIMER2, TIMER_INT_FLAG_UP);
}
}
3-ADC每次测试完480个点(刚好屏幕跨度像素)停止转换
void ADC_IRQHandler(void)
{
uint16_t i=0;
char t_char[30] = "";
static int s_counter=0;
static uint16_t s_recorder[480];
uint16_t *t_displaySize;
if(adc_interrupt_flag_get(ADC0, ADC_INT_FLAG_EOC)==SET)
{
s_recorder[s_counter] = adc_regular_data_read(ADC0);
adc_counter++;
s_counter++;
if(s_counter>=480){
s_counter = 0;
adc_special_function_config(ADC0, ADC_CONTINUOUS_MODE, DISABLE);
t_displaySize = EXT_BUFFER0_ADDR;
memset((void *)EXT_BUFFER0_ADDR, 0, LCD_WIDTH * LCD_HEIGHT * LCD_FB_BYTE_PER_PIXEL * 2);
for (i = 0; i < 480; i++)
t_displaySize[s_recorder[i]*272/0xFFF*480 + i] = 0xAAAA;
}
adc_interrupt_flag_clear(ADC0, ADC_INT_FLAG_EOC);
}
}
4-其中,停止转换的时候将点写入到显示缓存
for (i = 0; i < 480; i++)
t_displaySize[s_recorder[i]*272/0xFFF*480 + i] = 0xAAAA;
调整频率时的显示效果:
|