RTX_Template

所属分类:处理器开发
开发工具:C++
文件大小:2745KB
下载次数:14
上传日期:2014-07-07 21:25:59
上 传 者zise
说明:  MDK自带RTX的简单例程,可以当做入门资料!
(MDK simple routine that comes with RTX System)

文件列表:
RTX_Template\CMSIS\CM3\CoreSupport\core_cm3.c (17273, 2010-06-07)
RTX_Template\CMSIS\CM3\CoreSupport\core_cm3.h (85714, 2011-02-09)
RTX_Template\CMSIS\CM3\DeviceSupport\ST\STM32F10x\Release_Notes.html (26297, 2011-03-14)
RTX_Template\CMSIS\CM3\DeviceSupport\ST\STM32F10x\stm32f10x.h (633961, 2014-02-17)
RTX_Template\CMSIS\CM3\DeviceSupport\ST\STM32F10x\system_stm32f10x.c (36630, 2014-02-20)
RTX_Template\CMSIS\CM3\DeviceSupport\ST\STM32F10x\system_stm32f10x.h (2085, 2011-03-10)
RTX_Template\CMSIS\CMSIS debug support.htm (9310, 2010-06-07)
RTX_Template\CMSIS\CMSIS_changes.htm (12531, 2010-10-26)
RTX_Template\CMSIS\Documentation\CMSIS_Core.htm (57004, 2010-06-07)
RTX_Template\CMSIS\License.doc (39936, 2010-06-07)
RTX_Template\Libraries\inc\misc.h (8982, 2011-03-10)
RTX_Template\Libraries\inc\stm32f10x_adc.h (21690, 2011-03-10)
RTX_Template\Libraries\inc\stm32f10x_bkp.h (7555, 2011-03-10)
RTX_Template\Libraries\inc\stm32f10x_can.h (27559, 2011-03-10)
RTX_Template\Libraries\inc\stm32f10x_cec.h (6573, 2011-03-10)
RTX_Template\Libraries\inc\stm32f10x_crc.h (2162, 2011-03-10)
RTX_Template\Libraries\inc\stm32f10x_dac.h (15233, 2011-03-10)
RTX_Template\Libraries\inc\stm32f10x_dbgmcu.h (3818, 2011-03-10)
RTX_Template\Libraries\inc\stm32f10x_dma.h (20754, 2011-03-10)
RTX_Template\Libraries\inc\stm32f10x_exti.h (6824, 2011-03-10)
RTX_Template\Libraries\inc\stm32f10x_flash.h (25445, 2011-03-10)
RTX_Template\Libraries\inc\stm32f10x_fsmc.h (27016, 2011-03-10)
RTX_Template\Libraries\inc\stm32f10x_gpio.h (20233, 2014-02-24)
RTX_Template\Libraries\inc\stm32f10x_i2c.h (30029, 2011-03-10)
RTX_Template\Libraries\inc\stm32f10x_iwdg.h (3828, 2011-03-10)
RTX_Template\Libraries\inc\stm32f10x_pwr.h (4383, 2011-03-10)
RTX_Template\Libraries\inc\stm32f10x_rcc.h (30452, 2011-03-10)
RTX_Template\Libraries\inc\stm32f10x_rtc.h (3857, 2011-03-10)
RTX_Template\Libraries\inc\stm32f10x_sdio.h (21863, 2011-03-10)
RTX_Template\Libraries\inc\stm32f10x_spi.h (17725, 2011-03-10)
RTX_Template\Libraries\inc\stm32f10x_tim.h (52427, 2011-03-10)
RTX_Template\Libraries\inc\stm32f10x_usart.h (16548, 2011-03-10)
RTX_Template\Libraries\inc\stm32f10x_wwdg.h (2966, 2011-03-10)
RTX_Template\Libraries\src\misc.c (7046, 2011-03-10)
RTX_Template\Libraries\src\stm32f10x_adc.c (47201, 2011-03-10)
RTX_Template\Libraries\src\stm32f10x_bkp.c (8463, 2011-03-10)
RTX_Template\Libraries\src\stm32f10x_can.c (45103, 2011-03-10)
RTX_Template\Libraries\src\stm32f10x_cec.c (11656, 2011-03-10)
RTX_Template\Libraries\src\stm32f10x_crc.c (3347, 2011-03-10)
... ...

RTX_CONFIG.C RTX系统的初始化文件,主要用于定义 1. OS_TASKCNT //定义活动任务的个数,创建N个任务就是N+2。(有两个系统任务) 2. OS_PRIVCNT //标示带有用户提供堆栈任务数目。 3. OS_STKSIZE //分配给每个任务的堆栈数,X4才是字节数。 4. OS_STKCHECK //堆栈检查,1为激活,0为禁止。 5. OS_RUNPRI //在特权模式运行任务,1为有,0为无。 6. OS_CLOCK //输入系统的时钟频率。72000000(72M) 7. OS_TICK //时钟脉冲间隔。(us)10000(10ms) 8. OS_ROBIN //激活任务轮转,1为激活,0为禁止。 9. OS_ROBINTOUT//标识轮转时间,即每个任务的运行时间片。 10.OS_TIMERCNT //用户创建的定时器个数。 11.OS_FIFOSZ // 12.OS_MUTEXCNT // 13.OS_TRV //该宏定义了外围计时器的重装值。 RL-RTX(CM3)的任务中不能配置NVIC,否则进入HardFault的原因: 非特权模式――受保护的模式 特权模式――不受保护的模式 【译注:保护应该是指操作系统保护代码运行】 在特权模式,用户可以访问和配置系统寄存器和控制寄存器如NVIC中断控制器等。在非特权模式下,这些操作是不允许的。在非特权模式下访问NVIC寄存器将导致硬件错误(Hard Fault)。 typedef struct //结构体的定义例子,定义在H文件里 { u16 AA;//参数1 u16 BB;//参数2 } WWWWW; //结构体的名称。 void xxxx(WWWWW*SSSSS) //结构体使用示例 { u16 sum; SSSSS->AA = 0 ; //表示将0赋值给 WWWWW 结构体中的AA变量。 sum=SSSSS->BB ; //表示将结构体中的BB的值赋给变量sum。 (不可直接赋值给AA或BB,如WWWW->AA = 0 是错误的) GPIO需要用的结构体一般先在GPIO.H中定义好,然后在需要调用的函数文件中加以声明 如结构体 WWWWW XX 即表示可以用XX_AA来表示WWWW结构体中的变量AA了。 } //*/ /******************************************************************************* * Function Name : PID_Regulator * Description : Compute the PI(D) output for a PI(D) regulation. * Input : Pointer to the PID settings (*PID_Flux) Speed in s16 format * Output : s16 *******************************************************************************/ ///* 参考 反馈值(实际值) s16 PID_Regulator(s16 Reference, s16 PresentFeedback, PID_TypeDef *PID_Struct) { s32 Error, Proportional_Term, houtput_32, Differential_Term; s*** dwAux; Error= (s32)(Reference - PresentFeedback);//误差计算 Proportional_Term = PID_Struct->Kp_Gain * Error;//比例计算 if (PID_Struct->Ki_Gain == 0)//积分为0时的计算 PID_Struct->Integral = 0; else { dwAux = PID_Struct->Ki_Gain * Error + PID_Struct->Integral; //积分计算 if (dwAux > PID_Struct->Upper_Limit_Integral) { PID_Struct->Integral = PID_Struct->Upper_Limit_Integral; } //超过积分上限 else if (dwAux < PID_Struct->Lower_Limit_Integral) { PID_Struct->Integral = PID_Struct->Lower_Limit_Integral; } //低于积分下限 else { PID_Struct->Integral = (s32)(dwAux); } //保存积分值 } Differential_Term = PID_Struct->Kd_Gain * (Error - PID_Struct->PreviousError); //微分计算 PID_Struct->PreviousError = Error; //保存本次误差作为下次使用 houtput_32 = (Proportional_Term/PID_Struct->Kp_Divisor+ PID_Struct->Integral/PID_Struct->Ki_Divisor + Differential_Term/PID_Struct->Kd_Divisor); //PID输出值计算 if (houtput_32 >= PID_Struct->Upper_Limit_Output)//超过输出上限 return(PID_Struct->Upper_Limit_Output); else { if (houtput_32 < PID_Struct->Lower_Limit_Output)//低于输出下限 return(PID_Struct->Lower_Limit_Output); else return((s16)(houtput_32)); //返回值 } } /******************************************************************************* * Function Name : PID_Init * Description : 初始化 PID系数 (扭矩环、电流环、速度环) Kp_Gain: 比例系数 Ki_Gain: 积分系数 Kd_Gain: 微分系数 * Input : 指针PID结构 *******************************************************************************/ void PID_Init (PID_TypeDef *PID_Dat) { PID_Dat->Integral = 0; //重置积分值 PID_Dat->Kp_Gain = 0; //P PID_Dat->Kp_Divisor = 1;//P的除数 PID_Dat->Ki_Gain = 0; //I PID_Dat->Ki_Divisor = 1;//I的除数 PID_Dat->Kd_Gain = 0; //D PID_Dat->Kd_Divisor = 1;//D的除数 PID_Dat->PreviousError = 0;//上次的误差值 PID_Dat->Lower_Limit_Output= 0;//输出下限 PID_Dat->Upper_Limit_Output= 0;//输出上限 PID_Dat->Lower_Limit_Integral = 0;//积分项下限 PID_Dat->Upper_Limit_Integral = 0;//积分项上限 PID_Dat->Integral = 0;//上次的积分值 }

近期下载者

相关文件


收藏者