OpenEdv-开源电子网

 找回密码
 立即注册
正点原子全套STM32/Linux/FPGA开发资料,上千讲STM32视频教程免费下载...
查看: 1409|回复: 3

求助四路舵机的调试问题。

[复制链接]

4

主题

8

帖子

0

精华

初级会员

Rank: 2

积分
72
金钱
72
注册时间
2015-8-4
在线时间
10 小时
发表于 2015-9-22 13:16:36 | 显示全部楼层 |阅读模式
5金钱
求助四路舵机的调试问题。
#include "timer.h"
#include "led.h"
//////////////////////////////////////////////////////////////////////////////////  
//±????ò???©?§?°??????????×÷???í???????????????ü????????
//Mini STM32??·?°?
//?¨???¨?±?÷ ?????ú??   
//??????×?@ALIENTEK
//????????:www.openedv.com
//????????:2010/12/03
//°?±???V1.0
//°??¨?ù??????°?±?????
//Copyright(C) ??????×? 2009-2019
//All rights reserved
//////////////////////////////////////////////////////////////////////////////////  
unsigned char order=0;        //???????¤ ????
unsigned int PWM_value[6]={1000,1500,1000,1000,1500,2000};  //???úPWM ?????? ??±??ü????±??????í?? 
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;         //?¨?±??????  ?á????
#define PWM0_output_high  GPIO_SetBits(GPIOB,GPIO_Pin_6)         //?ê?¨?? ·?±???×÷
#define PWM0_output_low          GPIO_ResetBits(GPIOB,GPIO_Pin_6)

#define PWM1_output_high  GPIO_SetBits(GPIOB,GPIO_Pin_7)
#define PWM1_output_low          GPIO_ResetBits(GPIOB,GPIO_Pin_7)

#define PWM2_output_high  GPIO_SetBits(GPIOB,GPIO_Pin_8)
#define PWM2_output_low          GPIO_ResetBits(GPIOB,GPIO_Pin_8)

#define PWM3_output_high  GPIO_SetBits(GPIOB,GPIO_Pin_9)
#define PWM3_output_low          GPIO_ResetBits(GPIOB,GPIO_Pin_9)

//#define PWM4_output_high  GPIO_SetBits(GPIOC,GPIO_Pin_4)
//#define PWM4_output_low          GPIO_ResetBits(GPIOC,GPIO_Pin_4)

//#define PWM5_output_high  GPIO_SetBits(GPIOC,GPIO_Pin_5)
//#define PWM5_output_low          GPIO_ResetBits(GPIOC,GPIO_Pin_5)
#define PWM_OUR_TIME 20000/6   //????  20000US=20MS ???·PWM :6     
//???????· ???????¨??·????? ?????????????? ?????????????±???¨PWM_value?© ?????????? ???·PWM ????????????
//?????????ü???·??


//?¨???¨?±?÷??????????
//?????±????????APB1??2±?????APB1??36M
//arr??×?????×°????
//psc???±???¤·?????
//?????????????¨?±?÷4!
void TIM4_Int_Init(u16 arr,u16 psc)
{
    TIM_TimeBaseInitTypeDef  TIM_TimeBaseStructure;
NVIC_InitTypeDef NVIC_InitStructure;

RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM4, ENABLE); //?±??????

TIM_TimeBaseStructure.TIM_Period = arr; //?è???????????ü??????×°????????×?????×°???????÷???????? ??????5000??500ms
TIM_TimeBaseStructure.TIM_Prescaler =psc; //?è??????×÷??TIMx?±?????????????¤·?????  10Khz??????????  
TIM_TimeBaseStructure.TIM_ClockDivision = 0; //?è???±??·???:TDTS = Tck_tim
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;  //TIM?ò??????????
TIM_TimeBaseInit(TIM4, &TIM_TimeBaseStructure); //?ù??TIM_TimeBaseInitStruct?????¨????????????TIMx???±???ù??????
 
TIM_ITConfig( TIM4,TIM_IT_Update , ENABLE );//?????ò???§?????¨??TIM????
//TIM2

//????

NVIC_InitStructure.NVIC_IRQChannel = TIM4_IRQn;  //TIM3????
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;  //??????????0??
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 3;  //????????3??
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //IRQ?¨??±?????
NVIC_Init(&NVIC_InitStructure);  //?ù??NVIC_InitStruct?????¨???????????????èNVIC?????÷

TIM_Cmd(TIM4, ENABLE);  //????TIMx???è
 
}
//???ú????????
void SERVO_GPIO_Config(void)
{
        GPIO_InitTypeDef GPIO_InitStructure;  
  

        RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOB, ENABLE);       

          GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_7 | GPIO_Pin_8| GPIO_Pin_9;        
          GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;    
          GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;  
          GPIO_Init(GPIOB, &GPIO_InitStructure);                 

        GPIO_ResetBits(GPIOB, GPIO_Pin_6 | GPIO_Pin_7 | GPIO_Pin_8| GPIO_Pin_9);   
}

void TIM4_IRQHandler(void)   //TIM3????
{
if (TIM_GetITStatus(TIM4, TIM_IT_Update) != RESET) //?ì?é???¨??TIM????·??ú??·?:TIM ?????? 
{
TIM_ClearITPendingBit(TIM4, TIM_IT_Update  );  //????TIMx???????????í??:TIM ?????? 
               switch(order)
                {

                        case 1:
                                PWM0_output_high;
                          TIM_TimeBaseStructure.TIM_Period = PWM_value[0];//?????????±??????
                          TIM_TimeBaseInit(TIM4, & TIM_TimeBaseStructure);

                        break;
                        case 2:
                                PWM0_output_low;
                          TIM_TimeBaseStructure.TIM_Period = PWM_OUR_TIME-PWM_value[0];//?????????±??????
                          TIM_TimeBaseInit(TIM4, & TIM_TimeBaseStructure);        
                        break;

                        case 3:
                                PWM1_output_high;
                          TIM_TimeBaseStructure.TIM_Period = PWM_value[1];//?????????±??????
                          TIM_TimeBaseInit(TIM4, & TIM_TimeBaseStructure);

                        break;
                        case 4:
                                PWM1_output_low;
                          TIM_TimeBaseStructure.TIM_Period = PWM_OUR_TIME-PWM_value[1];//?????????±??????
                          TIM_TimeBaseInit(TIM4, & TIM_TimeBaseStructure);
        
                        break;

                        case 5:
                                PWM2_output_high;
                          TIM_TimeBaseStructure.TIM_Period = PWM_value[2];//?????????±??????
                          TIM_TimeBaseInit(TIM4, & TIM_TimeBaseStructure);

                        break;
                        case 6:
                                PWM2_output_low;
                          TIM_TimeBaseStructure.TIM_Period = PWM_OUR_TIME-PWM_value[2];//?????????±??????
                          TIM_TimeBaseInit(TIM4, & TIM_TimeBaseStructure);
        
                        break;

                        case 7:
                                PWM3_output_high;
                          TIM_TimeBaseStructure.TIM_Period = PWM_value[3];//?????????±??????
                          TIM_TimeBaseInit(TIM4, & TIM_TimeBaseStructure);

//                        break;
//                        case 8:
//                                WM3_output_low;
//                          TIM_TimeBaseStructure.TIM_Period = PWM_OUR_TIME-PWM_value[3];//?????????±??????
//                          TIM_TimeBaseInit(TIM2, & TIM_TimeBaseStructure);
//        
//                        break;

//                        case 9:
//                                WM4_output_high;
//                          TIM_TimeBaseStructure.TIM_Period = PWM_value[4];//?????????±??????
//                          TIM_TimeBaseInit(TIM2, & TIM_TimeBaseStructure);

//                        break;
//                        case 10:
//                                WM4_output_low;
//                          TIM_TimeBaseStructure.TIM_Period = PWM_OUR_TIME-PWM_value[4];//?????????±??????
//                          TIM_TimeBaseInit(TIM2, & TIM_TimeBaseStructure);
//        
//                        break;

//                        case 11:
//                                WM5_output_high;
//                          TIM_TimeBaseStructure.TIM_Period = PWM_value[5];//?????????±??????
//                          TIM_TimeBaseInit(TIM2, & TIM_TimeBaseStructure);

//                        break;
//                        case 12:
//                                WM5_output_low;
//                          TIM_TimeBaseStructure.TIM_Period = PWM_OUR_TIME-PWM_value[5];//?????????±??????
//                          TIM_TimeBaseInit(TIM2, & TIM_TimeBaseStructure);

                                order=0;  //×??ó???·????   ???????¤

                        break;


                        default: order=0;
                
                }

                order++;
}
}
#include "led.h"
#include "delay.h"
#include "sys.h"
#include "timer.h"
//ALIENTEK Mini STM32??·?°?·????ú??7
//?¨?±?÷???????é   
//?????§????www.openedv.com
//?????????í??×?????????????
 int main(void)
 {
delay_init();     //???±??????????
NVIC_Configuration();//?è??NVIC????·?×é2:2??????????????2???ì????????
LED_Init();   //????????LED??????????????
TIM4_Int_Init(1000,71);//10Khz??????????????????5000??500ms 
  SERVO_GPIO_Config(); 
   while(1);
 }














ALIENTEK MINISTM32 实验40 舵机实验.rar

1.66 MB, 下载次数: 53

正点原子逻辑分析仪DL16劲爆上市
回复

使用道具 举报

70

主题

6763

帖子

0

精华

论坛大神

Rank: 7Rank: 7Rank: 7

积分
13129
金钱
13129
注册时间
2012-11-26
在线时间
3814 小时
发表于 2015-9-22 13:17:35 | 显示全部楼层
学无止境
回复

使用道具 举报

530

主题

11万

帖子

34

精华

管理员

Rank: 12Rank: 12Rank: 12

积分
165540
金钱
165540
注册时间
2010-12-1
在线时间
2117 小时
发表于 2015-9-22 22:28:01 | 显示全部楼层
帮顶....
回复

使用道具 举报

18

主题

65

帖子

0

精华

高级会员

Rank: 4

积分
767
金钱
767
注册时间
2015-8-13
在线时间
84 小时
发表于 2015-9-23 09:08:27 | 显示全部楼层
呵呵呵。。。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则



关闭

原子哥极力推荐上一条 /2 下一条

正点原子公众号

QQ|手机版|OpenEdv-开源电子网 ( 粤ICP备12000418号-1 )

GMT+8, 2025-6-18 04:58

Powered by OpenEdv-开源电子网

© 2001-2030 OpenEdv-开源电子网

快速回复 返回顶部 返回列表