自家写main需要注意哪些?我用例子里的potentiometer_start(); 电位器启动,可是没动静,大神帮我看看是不是我移植有问题:
define PROJECT_CHK
#include "CrossCheck.h"
#undef PROJECT_CHK
#include "MCTuningClass.h"
#include "MCInterfaceClass.h"
#include "MCTasks.h"
#include "Parameters conversion.h"
#include "Timebase.h"
#include "UITask.h"
#include "MCLibraryISRPriorityConf.h"
#include <stdio.h>
#include "stm32_eval.h"
/********************************W22-Foc-2015.02.03********************************/
#include "MC.h"
/********************************end********************************/
/************ W22-Foc-2015.02.03-DEFINE for USER STATE MACHINE *****************/
#define US_RESET 0x00
#define US_POSITIVE_RUN 0x01
#define US_STOP 0x02
#define COUNT_MAX_SEC 3
#define STOP_DURATION_SEC 2
#define COUNT_MAX (COUNT_MAX_SEC * USER_TIMEBASE_FREQUENCY_HZ)
#define STOP_DURATION (STOP_DURATION_SEC * USER_TIMEBASE_FREQUENCY_HZ)
#define USER_TIMEBASE_FREQUENCY_HZ 10
#define USER_TIMEBASE_OCCURENCE_TICKS (SYS_TICK_FREQUENCY/USER_TIMEBASE_FREQUENCY_HZ)-1u
/********************************end********************************/
#define FIRMWARE_VERS "STM32 FOC SDK\0Ver.4.0.0"
const char s_fwVer[32] = FIRMWARE_VERS;
#ifdef __GNUC__
/* With GCC/RAISONANCE, small printf (option LD Linker->Libraries->Small printf
set to 'Yes') calls __io_putchar() */
#define PUTCHAR_PROTOTYPE int __io_putchar(int ch)
#else
#define PUTCHAR_PROTOTYPE int fputc(int ch, FILE *f)
#endif /* __GNUC__ */
/* Uncomment the following line to enable the demo mode */
/* #define DEMOMODE */
/* DEMO MODE prototypes, variables, macros */
#if defined(DEMOMODE)
#define MANUAL_MODE 0x00
#define DEMO_MODE 0x01
static volatile uint8_t Mode = DEMO_MODE;
void Demo(void);
void TqSpeedMode_start(void);
#endif
void potentiometer_start(void);
/* Private function prototypes -----------------------------------------------*/
void SysTick_Configuration(void);
/* Private variables ---------------------------------------------------------*/
/*******************************2015-02-03-W22-Foc********************************/
static CMCI oMCI_1;
static uint8_t User_State = US_RESET;
bool cmd_status = FALSE;
static uint16_t UserCnt = 0;
uint16_t potentiometer_value=0;
uint16_t speed_max_valueRPM = MOTOR_MAX_SPEED_RPM; //Maximum value for speed reference from Workbench
uint16_t speed_min_valueRPM = 1000; //Set the minimum value for speed reference
uint16_t speed_firstramp_duration = 100; //Set the duration for first ramp
/*******************************end********************************/
CMCI oMCI[MC_NUM];
CMCT oMCT[MC_NUM];
uint32_t wConfig[MC_NUM] = {UI_CONFIG_M1,UI_CONFIG_M2};
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
/**
* @brief Main program.
* @param None
* @retval None
*/
int main(void)
{
/*!< At this stage the microcontroller clock setting is already configured,
this is done through SystemInit() function which is called from startup
file (startup_stm32f10x_xx.s) before to branch to application main.
To reconfigure the default setting of SystemInit() function, refer to
system_stm32f10x.c file
*/
#if !defined(STM32F0XX)
/*NVIC Priority group configuration.
Default option is NVIC_PriorityGroup_3.
*/
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_3);
#endif
/*MCInterface and MCTuning boot*/
MCboot(oMCI,oMCT);
/*Systick configuration.*/
SysTick_Configuration();
while(1)
{
potentiometer_start();
}
}
void potentiometer_start()
{
oMCI_1 = GetMCI(M1);
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN;
GPIO_Init(GPIOA, &GPIO_InitStructure);
if (TB_UserTimebaseHasElapsed())
{
/* User defined code */
switch (User_State)
{
case US_RESET:
{
/* Next state */
/* This command sets what will be the first speed ramp after the
MCI_StartMotor command. It requires as first parameter the oMCI[0], as
second parameter the target mechanical speed in thenth of Hz and as
third parameter the speed ramp duration in milliseconds. */
MCI_ExecSpeedRamp(oMCI_1, 1800/6, speed_firstramp_duration);
/* This is a user command used to start the motor. The speed ramp shall be
pre programmed before the command.*/
cmd_status = MCI_StartMotor(oMCI_1);
/* It verifies if the command "MCI_StartMotor" is successfully executed
otherwise it tries to restart the procedure */
if(cmd_status==FALSE)
{
User_State = US_RESET; // Command NOT executed
}
else User_State = US_POSITIVE_RUN; // Command executed
UserCnt = 0;
}
break;
case US_POSITIVE_RUN:
{
/*control point for regular conversion request pending*/
if(MC_RegularConvState() == UDRC_STATE_IDLE)
/*define the regular channel for ADC (PC4) with a sampling time */
MC_RequestRegularConv(ADC_Channel_14,ADC_SampleTime_71Cycles5);
/*in case of End Of Conversion (EOC) the variable defined below contains
the last ADC value for PC4 (potentiometer->MCU pin) */
else if(MC_RegularConvState() == UDRC_STATE_EOC)
potentiometer_value = MC_GetRegularConv();
/* It counts the time for each new speed value assignment */
if (UserCnt < COUNT_MAX)
{
UserCnt++;
}
else
{
UserCnt=0;
/* In case of low RPM value < Minimum Speed (speed_min_value) the
motor is forced to stop */
if(((potentiometer_value+1)*speed_max_valueRPM / 65535) <= speed_min_valueRPM)
{
User_State = US_STOP;
UserCnt=0;
}
else
{
/* It changes the motor speed reference according with the potentiometer
value acquired by ADC on channel PC4 - the duration of the ramp is fixed
at 100 milliseconds */
MCI_ExecSpeedRamp(oMCI_1, ((potentiometer_value+1)*speed_max_valueRPM / 65535)/6, speed_firstramp_duration);
}
}
}
break;
case US_STOP:
{
/* This is a user command to stop the motor */
MCI_StopMotor(oMCI_1);
/* After the time "STOP_DURATION" the motor will be restarted */
if (UserCnt >= STOP_DURATION)
{
/* Next state */
User_State = US_RESET;
UserCnt = 0;
}
else
{
UserCnt++;
}
}
break;
}
TB_SetUserTimebaseTime(USER_TIMEBASE_OCCURENCE_TICKS);
}
} |