怎么根据需要使用工程模板啊??求助

admin 回复了问题 • 2 人关注 • 1 个回复 • 1511 次浏览 • 2015-02-11 09:00 • 来自相关话题

MDK5.1怎么用cube

日日夜夜 回复了问题 • 6 人关注 • 5 个回复 • 2777 次浏览 • 2015-02-06 13:08 • 来自相关话题

关于例程中用usb的hid模式和LIS302DL三轴加速度传感器用于joy的一些记录

回复

admin 回复了问题 • 1 人关注 • 12 个回复 • 3917 次浏览 • 2014-12-26 23:45 • 来自相关话题

祝贺版主,希望持续的关注,能给你继续努力的动力

admin 回复了问题 • 1 人关注 • 2 个回复 • 931 次浏览 • 2014-10-21 10:54 • 来自相关话题

(转载)温控器PID算法的实现(C语言),未实验

admin 发表了文章 • 0 个评论 • 3567 次浏览 • 2014-10-13 23:42 • 来自相关话题

硬件原理:加热电阻为400,电源为市电,固态继电器控制通断,并提取市电的过零信号,单片机采用mega48,继电器通断最小时间为10ms,通断PWM的周期为100个过零信号.

本程序采用绝对式PID算法,当温度相差很多时,采用P算法(比例算法),当到达设定温度时,采用PID算法,实际实用稳定性还可以,上下波动在0.5度以内.

#include <avr/io.h>
#include "PID.h"
//static PID sPID;
//static PID *sptr=&sPID;
TADD Tadd1;
TADD Tadd2;
void IncPIDInit(PID *sptr)
{
sptr->SumError=0;
sptr->LastError=0;
sptr->PrevError=0;

//sptr->Proportion = 900;
//sptr->Integral=20;
//sptr->Derivative = 2;

//sptr->SetPoint = 0;
}



typedef struct
{
int SetPoint; //设定目标值
int32_t SumError; //误差累计

//int Proportion;
//int Integral; //积分常数
//int Derivative; //微分常数

int LastError; //Error[-1]
int PrevError; //Error[-2]
}PID;
#define PID_Proportion 900 //比例常数
#define PID_Integral 20 //积分常数
#define PID_Derivative 2 //微分常数
#define PWM_T 100
#define MAX_T 80 //加热的最大温度
typedef struct
{
PID spid; //PID控制器
unsigned char pwm_H;//输出
unsigned char EnAdd;//加热使能
int real_T; //实际温度值
unsigned char Taddset[3]; //加热的设定温度
unsigned char set_NO; //加热的档数
unsigned char errorflg;
unsigned char addokflg;
}TADD;

void LocPIDCalc(TADD *sptr)
{
int iError,dError;
int32_t result;
iError = (sptr->spid.SetPoint*4) - (sptr->real_T/4);
//sptr->spid.LastError = iError;
if(iError>-2&&iError<4)
{
sptr->addokflg=1;
sptr->spid.SumError +=iError;
dError = iError-sptr->spid.LastError;
sptr->spid.LastError = iError;
result=(PID_Proportion * iError +
PID_Integral * sptr->spid.SumError +
PID_Derivative * dError)/20;
}
else
{
sptr->spid.SumError =0;
sptr->spid.LastError=0;
if(iError>0)
sptr->addokflg=0;
result=(PID_Proportion * iError)/20;
}
if(result>PWM_T)
result=PWM_T;
else if(result<0)
result=0;
if((sptr->real_T>>4)>MAX_T||sptr->errorflg==0)
result=0;
sptr->pwm_H=(unsigned char) result;
//return (unsigned char) result;
} 查看全部
硬件原理:加热电阻为400,电源为市电,固态继电器控制通断,并提取市电的过零信号,单片机采用mega48,继电器通断最小时间为10ms,通断PWM的周期为100个过零信号.

本程序采用绝对式PID算法,当温度相差很多时,采用P算法(比例算法),当到达设定温度时,采用PID算法,实际实用稳定性还可以,上下波动在0.5度以内.

#include <avr/io.h>
#include "PID.h"
//static PID sPID;
//static PID *sptr=&sPID;
TADD Tadd1;
TADD Tadd2;
void IncPIDInit(PID *sptr)
{
sptr->SumError=0;
sptr->LastError=0;
sptr->PrevError=0;

//sptr->Proportion = 900;
//sptr->Integral=20;
//sptr->Derivative = 2;

//sptr->SetPoint = 0;
}



typedef struct
{
int SetPoint; //设定目标值
int32_t SumError; //误差累计

//int Proportion;
//int Integral; //积分常数
//int Derivative; //微分常数

int LastError; //Error[-1]
int PrevError; //Error[-2]
}PID;
#define PID_Proportion 900 //比例常数
#define PID_Integral 20 //积分常数
#define PID_Derivative 2 //微分常数
#define PWM_T 100
#define MAX_T 80 //加热的最大温度
typedef struct
{
PID spid; //PID控制器
unsigned char pwm_H;//输出
unsigned char EnAdd;//加热使能
int real_T; //实际温度值
unsigned char Taddset[3]; //加热的设定温度
unsigned char set_NO; //加热的档数
unsigned char errorflg;
unsigned char addokflg;
}TADD;

void LocPIDCalc(TADD *sptr)
{
int iError,dError;
int32_t result;
iError = (sptr->spid.SetPoint*4) - (sptr->real_T/4);
//sptr->spid.LastError = iError;
if(iError>-2&&iError<4)
{
sptr->addokflg=1;
sptr->spid.SumError +=iError;
dError = iError-sptr->spid.LastError;
sptr->spid.LastError = iError;
result=(PID_Proportion * iError +
PID_Integral * sptr->spid.SumError +
PID_Derivative * dError)/20;
}
else
{
sptr->spid.SumError =0;
sptr->spid.LastError=0;
if(iError>0)
sptr->addokflg=0;
result=(PID_Proportion * iError)/20;
}
if(result>PWM_T)
result=PWM_T;
else if(result<0)
result=0;
if((sptr->real_T>>4)>MAX_T||sptr->errorflg==0)
result=0;
sptr->pwm_H=(unsigned char) result;
//return (unsigned char) result;
}