关于STM32F103调直流电机正反转的问题!
就是这个问题 二楼附上代码,求各位大神指教我到底哪里出错了!
#include "bsp_breathing.h"
uint16_t indexWave[] = {400,600,800,1000,1500,1500,1000,800,400};
/**
* @brief ????TIM3?′ó?ê?3?PWMê±ó?μ?μ?I/O
* @param ?T
* @retval ?T
*/
static void TIMx_GPIO_Config(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
/* GPIOB clock enable */
// RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);
macTIM_GPIO_APBxClock_FUN ( macTIM_GPIO_CLK, ENABLE ); //?aGPIOBμ?ê?ê±?ó
/* ????PWMó?μ?μ?PB0òy?? */
GPIO_InitStructure.GPIO_Pin = macTIM_LED_PIN ; //PB0
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; // ?′ó?í?íìê?3?
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init( macTIM_LED_PORT, &GPIO_InitStructure );
}
static void NVIC_Config_PWM(void)
{
NVIC_InitTypeDef NVIC_InitStructure;
/* Configure one bit for preemption priority */
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);
/* ????TIM3_IRQ?D???a?D???′ */
NVIC_InitStructure.NVIC_IRQChannel = macTIMx_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 2;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
/*
* TIMxCLK/CK_PSC --> TIMxCNT --> TIMx_ARR --> ?D?? & TIMxCNT ??D???êy
* TIMx_CCR(μ???·¢éú±??ˉ)
*
* D?o??ü?ú=(TIMx_ARR +1 ) * ê±?ó?ü?ú
*
*/
static void TIMx_Mode_Config(void)
{
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
TIM_OCInitTypeDef TIM_OCInitStructure;
/* éè??TIM3CLK ê±?ó?a72MHZ */
// RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE); //ê1?üTIM3ê±?ó
macTIM_APBxClock_FUN ( macTIM_CLK, ENABLE );
/* ?ù±??¨ê±?÷???? */
TIM_TimeBaseStructure.TIM_Period = 2000-1; //μ±?¨ê±?÷′ó0??êy1999£??′?a2000′?£??aò????¨ê±?ü?ú
TIM_TimeBaseStructure.TIM_Prescaler = 72-1; //éè???¤·??μ£o
TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_div1 ; //éè??ê±?ó·??μ?μêy£o2?·??μ(?aà?ó?2?μ?)
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; //?òé???êy?£ê?
TIM_TimeBaseInit(macTIMx, &TIM_TimeBaseStructure);
/* PWM?£ê????? */
TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1; //?????aPWM?£ê?1
TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable; //ê1?üê?3?
TIM_OCInitStructure.TIM_Pulse = 0; //éè??3?ê?PWM??3??í?è?a0
TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_Low; //μ±?¨ê±?÷??êy?μD?óúCCR1_Valê±?aμíμ???
macTIM_OCxInit ( macTIMx, &TIM_OCInitStructure ); //ê1?üí¨μà3
macTIM_OCxPreloadConfig ( macTIMx, TIM_OCPreload_Enable ); //ê1?ü?¤×°??
TIM_ARRPreloadConfig(macTIMx, ENABLE); //ê1?üTIM3??????′??÷ARR
/* TIM3 enable counter */
TIM_Cmd(macTIMx, ENABLE); //ê1?ü?¨ê±?÷3
TIM_ITConfig(macTIMx, TIM_IT_Update, ENABLE); //ê1?üupdate?D??
NVIC_Config_PWM(); //?????D??ó??è??
}
void GDG_GPIO_Config(void) //1aμ?1ü?ì2aòy??
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOA, ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);
}
void MOTORA_L_GPIO_Config(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOA, ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);
GPIO_ResetBits(GPIOA, GPIO_Pin_4);
GPIO_SetBits(GPIOA, GPIO_Pin_5);
}
void MOTORA_R_GPIO_Config(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOA, ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);
GPIO_SetBits(GPIOA, GPIO_Pin_4);
GPIO_ResetBits(GPIOA, GPIO_Pin_5);
}
void Delay(__IO u32 nCount)
{
for(; nCount != 0; nCount--);
}
void jiance(void){
if(GPIO_Pin_0!=0){
MOTORA_L_GPIO_Config();
Delay(0x0FFFFF);
}
else {
MOTORA_R_GPIO_Config();
Delay(0x0FFFFF);
}
}
void TIMx_Breathing_Init(void)
{
TIMx_GPIO_Config();
TIMx_Mode_Config();
jiance();
}
求看哪里有问题!
要看芯片资料。
我看了L298N的技术资料,明白高低电平来控制转动方向,我的问题就是编程的问题,4和5程序里让他产生两种信号,但只产生一种,想知道哪里出问题了_(:з」∠)_
希望大神指教程序哪里有问题!