初级会员
- 积分
- 57
- 金钱
- 57
- 注册时间
- 2016-7-8
- 在线时间
- 19 小时
|
10金钱
求各位有经验的帮忙!
我用STM32 迷你版 输出PWM来控制步进电机。控制电机的代码基本上都已调好。
用定时器TIM3-CH1 输出PWM, 梯形加速。
现在相结合STemWIn做一个按钮来控制步进电机。但是我用代码结合已经移植好的工程之后,按钮按下就没啥反应,不知道哪里出错。
求各位大神帮忙给点建议,多谢。
代码如下:
[mw_shl_code=applescript,true]int main(void)
{
OS_ERR err;
CPU_SR_ALLOC();
delay_init(); //延时函数初始化
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2); //设置NVIC中断分组2:2位抢占优先级,2位响应优先级
uart_init(115200); //串口初始化为115200
SystemInit(); //系统时钟初始化
LED_Init(); //LED端口初始化
TFTLCD_Init(); //LCD初始化
KEY_Init(); //按键初始化
mem_init(); //初始化内部内存池
Motor_Init(); //TIM3 的各初始化函数
SLOPE(200,600); //设置启动频率为200,加速时间为600
// RCC_AHBPeriphClockCmd(RCC_AHBPeriph_CRC,ENABLE);//使能CRC时钟,否则STemWin不能使用
exfuns_init(); //为fatfs文件系统分配内存
f_mount(fs[0],"0:",1); //挂载SD卡
f_mount(fs[1],"1:",1); //挂载FLASH
TP_Init(); //触摸屏初始化
OSInit(&err); //初始化UCOSIII
OS_CRITICAL_ENTER(); //进入临界区
//创建开始任务
OSTaskCreate((OS_TCB * )&StartTaskTCB, //任务控制块
(CPU_CHAR * )"start task", //任务名字
(OS_TASK_PTR )start_task, //任务函数
(void * )0, //传递给任务函数的参数
(OS_PRIO )START_TASK_PRIO, //任务优先级
(CPU_STK * )&START_TASK_STK[0], //任务堆栈基地址
(CPU_STK_SIZE)START_STK_SIZE/10, //任务堆栈深度限位
(CPU_STK_SIZE)START_STK_SIZE, //任务堆栈大小
(OS_MSG_QTY )0, //任务内部消息队列能够接收的最大消息数目,为0时禁止接收消息
(OS_TICK )0, //当使能时间片轮转时的时间片长度,为0时为默认长度,
(void * )0, //用户补充的存储区
(OS_OPT )OS_OPT_TASK_STK_CHK|OS_OPT_TASK_STK_CLR, //任务选项
(OS_ERR * )&err); //存放该函数错误时的返回值
OS_CRITICAL_EXIT(); //退出临界区
OSStart(&err); //开启UCOSIII
//
while(1);
}
//开始任务函数
void start_task(void *p_arg)
{
OS_ERR err;
CPU_SR_ALLOC();
p_arg = p_arg;
CPU_Init();
#if OS_CFG_STAT_TASK_EN > 0u
OSStatTaskCPUUsageInit(&err); //统计任务
#endif
#ifdef CPU_CFG_INT_DIS_MEAS_EN //如果使能了测量中断关闭时间
CPU_IntDisMeasMaxCurReset();
#endif
#if OS_CFG_SCHED_ROUND_ROBIN_EN //当使用时间片轮转的时候
//使能时间片轮转调度功能,时间片长度为1个系统时钟节拍,既1*5=5ms
OSSchedRoundRobinCfg(DEF_ENABLED,1,&err);
#endif
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_CRC,ENABLE);//开启CRC时钟
GUI_Init(); //STemWin初始化
OS_CRITICAL_ENTER(); //进入临界区
//STemWin Demo任务
OSTaskCreate((OS_TCB* )&EmwindemoTaskTCB,
(CPU_CHAR* )"Emwindemo task",
(OS_TASK_PTR )emwindemo_task,
(void* )0,
(OS_PRIO )EMWINDEMO_TASK_PRIO,
(CPU_STK* )&EMWINDEMO_TASK_STK[0],
(CPU_STK_SIZE)EMWINDEMO_STK_SIZE/10,
(CPU_STK_SIZE)EMWINDEMO_STK_SIZE,
(OS_MSG_QTY )0,
(OS_TICK )0,
(void* )0,
(OS_OPT )OS_OPT_TASK_STK_CHK|OS_OPT_TASK_STK_CLR,
(OS_ERR* )&err);
//触摸屏任务
OSTaskCreate((OS_TCB* )&TouchTaskTCB,
(CPU_CHAR* )"Touch task",
(OS_TASK_PTR )touch_task,
(void* )0,
(OS_PRIO )TOUCH_TASK_PRIO,
(CPU_STK* )&TOUCH_TASK_STK[0],
(CPU_STK_SIZE)TOUCH_STK_SIZE/10,
(CPU_STK_SIZE)TOUCH_STK_SIZE,
(OS_MSG_QTY )0,
(OS_TICK )0,
(void* )0,
(OS_OPT )OS_OPT_TASK_STK_CHK|OS_OPT_TASK_STK_CLR,
(OS_ERR* )&err);
//LED0任务
OSTaskCreate((OS_TCB* )&Led0TaskTCB,
(CPU_CHAR* )"Led0 task",
(OS_TASK_PTR )led0_task,
(void* )0,
(OS_PRIO )LED0_TASK_PRIO,
(CPU_STK* )&LED0_TASK_STK[0],
(CPU_STK_SIZE)LED0_STK_SIZE/10,
(CPU_STK_SIZE)LED0_STK_SIZE,
(OS_MSG_QTY )0,
(OS_TICK )0,
(void* )0,
(OS_OPT )OS_OPT_TASK_STK_CHK|OS_OPT_TASK_STK_CLR,
(OS_ERR* )&err);
OS_TaskSuspend((OS_TCB*)&StartTaskTCB,&err); //挂起开始任务
OS_CRITICAL_EXIT(); //退出临界区
}
//EMWINDEMO任务
void emwindemo_task(void *pdata)
{
GUI_CURSOR_Show(); //显示鼠标
BUTTON_SetDefaultSkin(BUTTON_SKIN_FLEX);
CHECKBOX_SetDefaultSkin(CHECKBOX_SKIN_FLEX);
DROPDOWN_SetDefaultSkin(DROPDOWN_SKIN_FLEX);
FRAMEWIN_SetDefaultSkin(FRAMEWIN_SKIN_FLEX);
HEADER_SetDefaultSkin(HEADER_SKIN_FLEX);
MENU_SetDefaultSkin(MENU_SKIN_FLEX);
MULTIPAGE_SetDefaultSkin(MULTIPAGE_SKIN_FLEX);
PROGBAR_SetDefaultSkin(PROGBAR_SKIN_FLEX);
RADIO_SetDefaultSkin(RADIO_SKIN_FLEX);
SCROLLBAR_SetDefaultSkin(SCROLLBAR_SKIN_FLEX);
SLIDER_SetDefaultSkin(SLIDER_SKIN_FLEX);
SPINBOX_SetDefaultSkin(SPINBOX_SKIN_FLEX);
CreateFramewin();
while(1)
{
GUI_Delay(100);
}
}
//TOUCH任务
void touch_task(void *p_arg)
{
OS_ERR err;
while(1)
{
GUI_TOUCH_Exec();
OSTimeDlyHMSM(0,0,0,5,OS_OPT_TIME_PERIODIC,&err);//延时5ms
}
}
//LED0任务
void led0_task(void *p_arg)
{
OS_ERR err;
while(1)
{
LED0 = !LED0;
OSTimeDlyHMSM(0,0,0,500,OS_OPT_TIME_PERIODIC,&err);//延时500ms
}
}[/mw_shl_code]
STemWin的回调函数
[mw_shl_code=applescript,true]static void _cbDialog(WM_MESSAGE * pMsg) {
int NCode;
int Id;
// USER START (Optionally insert additional variables)
// USER END
switch (pMsg->MsgId) {
case WM_NOTIFY_PARENT:
Id = WM_GetId(pMsg->hWinSrc);
NCode = pMsg->Data.v;
switch(Id) {
case ID_BUTTON_0: // Notifications sent by 'Button'
switch(NCode) {
case WM_NOTIFICATION_CLICKED:
// USER START (Optionally insert code for reacting on notification message)
// USER END
break;
case WM_NOTIFICATION_RELEASED:
JUEDUI(12000,5000); //电机以5000Hz的频率正转12000个脉冲
// USER START (Optionally insert code for reacting on notification message)
// USER END
break;
// USER START (Optionally insert additional code for further notification handling)
// USER END
}
break;
// USER START (Optionally insert additional code for further Ids)
// USER END
}
break;
// USER START (Optionally insert additional message handling)
// USER END
default:
WM_DefaultProc(pMsg);
break;
}
}[/mw_shl_code]
|
|