红叶合适落水
校赛第三部分
详见
http://t.csdn.cn/50yJu
这里就简单多了
波形检测见
http://t.csdn.cn/LCvX1
关于判断波形的类型
FFT还没用过
但一定频率范围内有两种方法
方案一
检测一下采集到的波形数据,大于某个值的数有多少个,就可以判断出是什么波形
方案二
将数组内相邻的两个数相减,判断差值;
差值为0,方波
差值为定值,但不为0,三角波
差值不是定值,正弦波。
关于STM32单片机对数的计算
直接使用公式是没法返回正确的值的
解决方案
利用中间变量
u16 lo = 0;
u16 lo2 = 0;
len = len - 1;
LCD_Fill(0, 120, 240, 220, GREEN);
for(i = 0; i < len; i++) {
lo = 20 * log10(arr[i]);
lo2 = 20 * log10(arr[i + 1]);
LCD_DrawLine(i * 230 / len, (100 - lo) * 2 + 80, (i + 1) * 230 / len, (100 - lo2) * 2 + 80);
}
主函数
int main(void)
{ int pending = 0;
u8 t=0;
Init();
while(1)
{
if(pending == 1) {
printf("\n\r%d",Get_Adc(ADC_Channel_0));
if(Get_Adc(ADC_Channel_0) > 3700) {
} else {
for(n = 0; n < 70; n++) {
ADC_ConvertedValue2[n] = Get_Adc_vpp(ADC_Channel_0);
delay_ms(16);
}
pending = 4;
draw2(ADC_ConvertedValue2, 70, 40);
LCD_ShowxNum(100,200,pending,1,16,0);
}
}
t=KEY_Scan(0); //µÃµ½¼üÖµ
switch(t)
{
case KEY0_PRES:
pending = 0;
draw(ADC_ConvertedValue, 200, 40);
adc_init();
LCD_ShowxNum(100,200,pending,1,16,0);
break;
case KEY1_PRES:
pending = 1;
Adc_Init();
LCD_ShowxNum(100,200,pending,1,16,0);
break;
case WKUP_PRES:
pending = 2;
draw(ADC_ConvertedValue, 200, 40);
adc_init();
LCD_ShowxNum(100,200,pending,1,16,0);
break;
default:
delay_ms(1);
}
}
}
void ADC(u16 vpp1) {
vpp1=Get_Adc_vpp(ADC_Channel_0);
temp=(float)vpp1*(3.3/4096);
vpp1=temp;
LCD_ShowxNum(156,150,vpp1,1,16,0);
temp-=vpp1;
temp*=1000;
LCD_ShowxNum(172,150,temp,3,16,0X80);
}
void Init(void)
{
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
uart_init(9600);
delay_init();
KEY_Init();
LCD_Init();
Adc_Init();
POINT_COLOR=BLUE;//ÉèÖÃ×ÖÌåΪÀ¶É«
LCD_ShowString(60,150,200,16,16,"ADC_CH1_VPP:0.000V");
adc_init();
LCD_DrawLine(0, 100, 230, 100);
LCD_SSD_BackLightSet(1);
}
void draw(u16 arr[], int len, int height)
{
int num = 0;
len = len - 1;
LCD_Fill(0, 0, 240, 100, GREEN);
for(i = 0; i < len; i++) {
num += (arr[i] > 621) ? 1 : 0;
LCD_DrawLine(i * 230 / len, 100 - (arr[i] / height), (i + 1) * 230 / len, 100 - (arr[i + 1] / height));
}
printf("\n\r%d",num);
if(num < 130) {
LCD_ShowString(10,0,200,16,16,"Square");
} else if(num > 140 && num < 170) {
LCD_ShowString(10,0,200,16,16,"SIN");
} else if(num > 175) {
LCD_ShowString(10,0,200,16,16,"Triangle");
}
}
void draw2(u16 arr[], int len, int height)
{
u16 lo = 0;
u16 lo2 = 0;
len = len - 1;
LCD_Fill(0, 120, 240, 220, GREEN);
for(i = 0; i < len; i++) {
lo = 20 * log10(arr[i]);
lo2 = 20 * log10(arr[i + 1]);
LCD_DrawLine(i * 230 / len, (100 - lo) * 2 + 80, (i + 1) * 230 / len, (100 - lo2) * 2 + 80);
}
LCD_Fill(0, 220, 240, 320, GREEN);
for(i = 0; i < len; i++) {
LCD_DrawLine(i * 230 / len, 100 - (arr[i] / height) + 200, (i + 1) * 230 / len, 100 - (arr[i + 1] / height) + 200);
}
LCD_ShowString(230,210,16,16,16,"5");
LCD_ShowString(230,280,16,16,16,"0");
LCD_ShowString(0,300,48,16,16,"100");
LCD_ShowString(100,300,64,16,16,"2.9k");
LCD_ShowString(200,300,64,16,16,"5khz");
LCD_ShowString(220,130,48,16,16,"14");
LCD_ShowString(230,180,48,16,16,"0");
LCD_ShowString(205,195,48,16,16,"-17");
LCD_ShowString(210,250,48,16,16,"(V)");
}
void draw3(u16 arr[], int len, int height)
{
len = len - 1;
LCD_Fill(0, 0, 240, 100, GREEN);
for(i = 0; i < len; i++) {
LCD_DrawLine(i * 230 / len, 100 - (arr[i] / height), (i + 1) * 230 / len, 100 - (arr[i + 1] / height));
}
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)