新手上路
- 积分
- 35
- 金钱
- 35
- 注册时间
- 2017-7-21
- 在线时间
- 25 小时
|
这是我的主函数,我想要通过ad采样反馈来改变pwm波,键盘是拿来控制与ad的比较值
ad和pwm波单独都能实现,但是两者结合到一起,ad无法输出,pwm的波形也很奇怪
求大佬之教
#include "led.h"
#include "delay.h"
#include "sys.h"
#include "pwm.h"
#include "key.h"
#include "lcd.h"
#include "adc.h"
#include "usart.h"
u16 uo=30;
int main(void)
{
u8 t=0;
u16 uo=30,adcx,pulse=50;
float temp;
u8 key;
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
delay_init();
uart_init(9600);
LED_Init();
LCD_Init();
KEY_Init();
Adc_Init();
POINT_COLOR=RED;
LCD_ShowString(90,50,200,16,16,"TEST RESULT");
POINT_COLOR=BLUE;
LCD_ShowString(92,70,200,16,16,"Uo:00.0V");
LCD_ShowString(92,90,200,16,16,"Uoad:0.000V");
TIM1_PWM_Init(1439,0,50);//2»·ÖÆμ¡£PWMÆμÂê=72000/(899+1)=80Khz
while(1)
{
t++;
key=KEY_Scan(0);
if(key==WKUP_PRES)
{
if(uo<36)uo++;
else uo=30;
}else if(key==KEY0_PRES)
{
if(uo>30)uo--;
else uo=36;
}
if(t==10||key==KEY0_PRES||key==WKUP_PRES) //WKUP/KEY1°′ÏÂáË,»òÕ߶¨ê±ê±¼äμ½áË
{
//′Ë′|óDuo×a»»1ØÏμê½
temp=uo;
LCD_ShowxNum(116,70,temp,2,16,0);
adcx=Get_Adc_Average(ADC_Channel_1,10);
temp=(float)adcx*(3.3/4096);
adcx=temp;
LCD_ShowxNum(132,90,adcx,2,16,0);//ÏÔê¾μçÑ1Öμ1
temp-=adcx;
temp*=1000;
LCD_ShowxNum(148,90,temp,3,16,0X80);
if(adcx>uo)
pulse--;
else if(adcx<uo)
pulse++;
TIM1_PWM_Init(1439,0,pulse);
t=0;
}
delay_ms(10);
}
}
|
|