在自己创建工程之后,开始了对TT_M3HQ开发板的学习,主要功能是使用TT_M3HQ开发板实现对57式步进电机的控制,包括电机启停、方向控制、电机转速控制等。在学习的过程当中主要涉及到了系统时钟各个配置、GPIO功能、SysTick功能、UART功能、定时器功能和PWM功能。通过对原厂代码的解读,逐步了解了这些所涉及功能模块的初始化配置、及后面的操作;原厂的代码在BSP部分结合硬件做了程序的结构定义及封装,对代码来说理简洁,但对于我这个刚开始的新手来说,我还是一点点的去分析,然后改写成了自己的代码风格,对原厂代码设计巧妙的地方也分享给其它同事一起学习了……
本例程基于TT_M3HQ开发板主要实现的功能如下:
——初始化系统时钟,使其工作在80MHz的主频率下,实际测得大概是79880000Hz,通过SCOU对系统各个时钟模块进行监测;
——初始化GPIO口,通过串口命令实现对LED亮灭的控制、电机的运行使能和运转方向控制;
——初始化定时器定时功能,在定时器的中断回调函数中实现对变通GPIO的电平翻转操作,监测定时器的中断触发时间间隔;
——初始化定时器脉冲输出,实现对57式步进电机运转输入信号的控制;
——初始化串口功能,实现系统消息打印,接收PC的串口命令进行相应的操作;
——初始化SysTick,实现1ms的精确延时;
2.准备
2.1.搭建硬件环境
2.2.电机参数
电机型号:57BYG250B
电流:3A
输出力矩:1.2Nm(牛米)
机身长度:56mm
出轴长度:21mm
出轴方式:单轴,轴径8mm,单扁丝
出线方式:二相四根引出线(黑色A+ 绿色A- 红色B+ 蓝色B-)
2.3.驱动器参数
驱动器型号:TB6600
输入电压:DC 9V~24V
电流:4A 速度自适应电路,电流自动寻优
细分数:6400细分
各种保护:过流、过压、欠压、短路等保护
脱机:脱机(ENA)保护功能
3.程序设计
3.1.LED灯初始化及控制
- static void TT_M3HQ_InitLED(void)
- {
- port.p_pk_instance = TSB_PK;
- if(gpio_init(&port, GPIO_PORT_K) != TXZ_SUCCESS)
- {
- TT_M3HQ_Warning();
- }
- /* PK4 - LED0 */
- if(gpio_func(&port, GPIO_PORT_K, GPIO_PORT_4, (uint32_t)GPIO_PK4_OUTPUT, GPIO_PIN_OUTPUT) != TXZ_SUCCESS)
- {
- TT_M3HQ_Warning();
- }
- /* PK5 - LED1 */
- if(gpio_func(&port, GPIO_PORT_K, GPIO_PORT_5, (uint32_t)GPIO_PK5_OUTPUT, GPIO_PIN_OUTPUT) != TXZ_SUCCESS)
- {
- TT_M3HQ_Warning();
- }
- /* PK6 - LED2 */
- if(gpio_func(&port, GPIO_PORT_K, GPIO_PORT_6, (uint32_t)GPIO_PK6_OUTPUT, GPIO_PIN_OUTPUT) != TXZ_SUCCESS)
- {
- TT_M3HQ_Warning();
- }
- /* PK7 - LED3 */
- if(gpio_func(&port, GPIO_PORT_K, GPIO_PORT_7, (uint32_t)GPIO_PK7_OUTPUT, GPIO_PIN_OUTPUT) != TXZ_SUCCESS)
- {
- TT_M3HQ_Warning();
- }
- }
- void TT_M3HQ_LEDOnOFF(uint8_t index, uint8_t state)
- {
- if(state)
- {
- switch(index)
- {
- case 0 : gpio_write_bit(&port, GPIO_PORT_K, GPIO_PORT_4, GPIO_Mode_DATA, GPIO_PIN_SET); break;
- case 1 : gpio_write_bit(&port, GPIO_PORT_K, GPIO_PORT_5, GPIO_Mode_DATA, GPIO_PIN_SET); break;
- case 2 : gpio_write_bit(&port, GPIO_PORT_K, GPIO_PORT_6, GPIO_Mode_DATA, GPIO_PIN_SET); break;
- case 3 : gpio_write_bit(&port, GPIO_PORT_K, GPIO_PORT_7, GPIO_Mode_DATA, GPIO_PIN_SET); break;
- default: break;
- }
- }
- else
- {
- switch(index)
- {
- case 0 : gpio_write_bit(&port, GPIO_PORT_K, GPIO_PORT_4, GPIO_Mode_DATA, GPIO_PIN_RESET); break;
- case 1 : gpio_write_bit(&port, GPIO_PORT_K, GPIO_PORT_5, GPIO_Mode_DATA, GPIO_PIN_RESET); break;
- case 2 : gpio_write_bit(&port, GPIO_PORT_K, GPIO_PORT_6, GPIO_Mode_DATA, GPIO_PIN_RESET); break;
- case 3 : gpio_write_bit(&port, GPIO_PORT_K, GPIO_PORT_7, GPIO_Mode_DATA, GPIO_PIN_RESET); break;
- default: break;
- }
- }
- }
3.2.定时器功能初始化及中断回调函数
- static void TT_M3HQ_TimerEventHandler(uint32_t id, uint32_t status, TXZ_Result result)
- {
- static uint8_t i = 0;
- if(result == TXZ_SUCCESS)
- {
- if((status & T32A_INTx1_FLG_MASK) == T32A_INTx1_FLG_MASK)
- {
- if(i == 0)
- {
- i = 1;
- gpio_write_bit(&port, GPIO_PORT_N, GPIO_PORT_4, GPIO_Mode_DATA, GPIO_PIN_SET);
- }
- else
- {
- i = 0;
- gpio_write_bit(&port, GPIO_PORT_N, GPIO_PORT_4, GPIO_Mode_DATA, GPIO_PIN_RESET);
- }
- }
- }
- }
- static void TT_M3HQ_TimerStart(void)
- {
- /*--- Start ---*/
- if(t32a_timer_startIT(&t32a, T32A_TIMERA) != TXZ_SUCCESS)
- {
- TT_M3HQ_Warning();
- }
- if(t32a_SWcounter_start(&t32a, T32A_TIMERA) != TXZ_SUCCESS)
- {
- TT_M3HQ_Warning();
- }
- /*--- NVIC Enable ---*/
- NVIC_EnableIRQ(INTT32A00A_IRQn);
- }
- static void TT_M3HQ_TimerStop(void)
- {
- /*--- NVIC Disable ---*/
- NVIC_DisableIRQ(INTT32A00A_IRQn);
- /*--- Stop ---*/
- if (t32a_timer_stopIT(&t32a, T32A_TIMERA) != TXZ_SUCCESS)
- {
- TT_M3HQ_Warning();
- }
- if (t32a_SWcounter_stop(&t32a, T32A_TIMERA) != TXZ_SUCCESS)
- {
- TT_M3HQ_Warning();
- }
- }
- static void TT_M3HQ_InitTimer(void)
- {
- uint8_t flag = 1;
- cg_t paramCG;
- t32a.p_instance = TSB_T32A0;
- t32a.init_mode.mode.halt = T32A_DBG_HALT_STOP;
- t32a.init_mode.mode.mode = T32A_MODE_16;
- if(t32a_mode_init(&t32a) != TXZ_SUCCESS)
- {
- TT_M3HQ_Warning();
- }
- /* Run Control */
- t32a.init[T32A_TIMERA].runx.sftstp = T32A_COUNT_STOP;
- t32a.init[T32A_TIMERA].runx.sftsta = T32A_COUNT_DONT_START;
- t32a.init[T32A_TIMERA].runx.run = T32A_RUN_DISABLE;
- /* Counter Control */
- t32a.init[T32A_TIMERA].crx.prscl = T32A_PRSCLx_8;
- t32a.init[T32A_TIMERA].crx.clk = T32A_CLKx_PRSCLx;
- t32a.init[T32A_TIMERA].crx.wbf = T32A_WBF_DISABLE;
- t32a.init[T32A_TIMERA].crx.updn = T32A_COUNT_DOWN;
- t32a.init[T32A_TIMERA].crx.reld = T32A_RELOAD_TREGx;
- t32a.init[T32A_TIMERA].crx.stop = T32A_STOP_NON;
- t32a.init[T32A_TIMERA].crx.start = T32A_START_NON;
- /* Output Control 0 */
- t32a.init[T32A_TIMERA].outcrx0.ocr = T32A_OCR_DISABLE;
- /* Output Control 1 */
- t32a.init[T32A_TIMERA].outcrx1.ocrcap0 = T32A_OCRCAPx0_DISABLE;
- t32a.init[T32A_TIMERA].outcrx1.ocrcap1 = T32A_OCRCAPx1_DISABLE;
- t32a.init[T32A_TIMERA].outcrx1.ocrcmp0 = T32A_OCRCMPx0_DISABLE;
- t32a.init[T32A_TIMERA].outcrx1.ocrcmp1 = T32A_OCRCMPx1_DISABLE;
- /* Timer Counter 1 */
- t32a.init[T32A_TIMERA].rgx0.rgx0 = 0;
- t32a.init[T32A_TIMERA].rgx1.rgx1 = 0;
- /* Counter Capture */
- t32a.init[T32A_TIMERA].tmrx.tmrx = 0;
- /* Counter Capture Control A0 */
- t32a.init[T32A_TIMERA].capx0.capx0 = 0;
- /* Counter Capture Control A1 */
- t32a.init[T32A_TIMERA].capx1.capx1 = 0;
- /* Interrupt mask register Set */
- t32a.init[T32A_TIMERA].imx.imuf = T32A_IMUFx_MASK_REQ;
- t32a.init[T32A_TIMERA].imx.imof = T32A_IMOFx_MASK_REQ;
- t32a.init[T32A_TIMERA].imx.imx1 = T32A_IMx1_MASK_NOREQ;
- t32a.init[T32A_TIMERA].imx.imx0 = T32A_IMx0_MASK_REQ;
- /* DMA Request */
- t32a.init[T32A_TIMERA].dma_req.dmaenx2 = T32A_DMAENx2_DISABLE;
- t32a.init[T32A_TIMERA].dma_req.dmaenx1 = T32A_DMAENx1_DISABLE;
- t32a.init[T32A_TIMERA].dma_req.dmaenx0 = T32A_DMAENx0_DISABLE;
- /* User ID */
- t32a.init[T32A_TIMERA].id = 0;
- /* Handler */
- t32a.init[T32A_TIMERA].handler_T = TT_M3HQ_TimerEventHandler;
- /* CG Driver Register Address Allocation. */
- paramCG.p_instance = TSB_CG;
- /* Calculate timer counter. */
- if(t32a_Calculator(&(t32a.init[T32A_TIMERA].reldx.reld), 1000, cg_get_phyt0(¶mCG), t32a.init[T32A_TIMERA].crx.prscl) != TXZ_SUCCESS)
- {
- TT_M3HQ_Warning(); TT_M3HQ_LEDOnOFF(0, 1);
- }
- if(t32a_timer_init(&t32a, T32A_TIMERA) != TXZ_SUCCESS)
- {
- TT_M3HQ_Warning();
- }
- if(flag) TT_M3HQ_TimerStart();
- else TT_M3HQ_TimerStop();
- }
3.3.定时器脉冲输出配置
- static void TT_M3HQ_PulseHandler(uint32_t id, uint32_t status, TXZ_Result result)
- {
- if(result == TXZ_SUCCESS)
- {
- /* Check INTA1 */
- if((status & T32A_INTx1_FLG_MASK) == T32A_INTx1_FLG_MASK)
- {
- }
- }
- }
- static void TT_M3HQ_PulseTimerStart(void)
- {
- /*--- Start ---*/
- if(t32a_timer_startIT(&pulse, T32A_TIMERA) != TXZ_SUCCESS)
- {
- TT_M3HQ_Warning();
- }
- if(t32a_SWcounter_start(&pulse, T32A_TIMERA) != TXZ_SUCCESS)
- {
- TT_M3HQ_Warning();
- }
- /*--- NVIC Enable ---*/
- NVIC_EnableIRQ(INTT32A03A_IRQn);
- }
- static void TT_M3HQ_PulseTimerStop(void)
- {
- /*--- NVIC Disable ---*/
- NVIC_DisableIRQ(INTT32A03A_IRQn);
- /*--- Stop ---*/
- if(t32a_timer_stopIT(&pulse, T32A_TIMERA) != TXZ_SUCCESS)
- {
- TT_M3HQ_Warning();
- }
- if(t32a_SWcounter_stop(&pulse, T32A_TIMERA) != TXZ_SUCCESS)
- {
- TT_M3HQ_Warning();
- }
- }
- static void TT_M3HQ_InitPulse(void)
- {
- uint8_t flag = 1;
- cg_t paramCG;
- port.p_pj_instance = TSB_PJ;
- if(gpio_init(&port, GPIO_PORT_J) != TXZ_SUCCESS)
- {
- TT_M3HQ_Warning();
- }
- /* PJ0 - PUL */
- if(gpio_func(&port, GPIO_PORT_J, GPIO_PORT_0, (uint32_t)GPIO_PJ0_T32A03OUTA, GPIO_PIN_OUTPUT) != TXZ_SUCCESS)
- {
- TT_M3HQ_Warning();
- }
- /* PJ3 - DIR */
- if(gpio_func(&port, GPIO_PORT_J, GPIO_PORT_3, (uint32_t)GPIO_PN3_OUTPUT, GPIO_PIN_OUTPUT) != TXZ_SUCCESS)
- {
- TT_M3HQ_Warning();
- }
- /* PJ5 - ENA */
- if(gpio_func(&port, GPIO_PORT_J, GPIO_PORT_5, (uint32_t)GPIO_PN5_OUTPUT, GPIO_PIN_OUTPUT) != TXZ_SUCCESS)
- {
- TT_M3HQ_Warning();
- }
- TT_M3HQ_MotorRUN(0);
- TT_M3HQ_MotorDIR(0);
- pulse.p_instance = TSB_T32A3;
- pulse.init_mode.mode.halt = T32A_DBG_HALT_STOP;
- pulse.init_mode.mode.mode = T32A_MODE_16;
- if(t32a_mode_init(&pulse) != TXZ_SUCCESS)
- {
- TT_M3HQ_Warning();
- }
- /* Run Control */
- pulse.init[T32A_TIMERA].runx.sftstp = T32A_COUNT_STOP;
- pulse.init[T32A_TIMERA].runx.sftsta = T32A_COUNT_DONT_START;
- pulse.init[T32A_TIMERA].runx.run = T32A_RUN_DISABLE;
- /* Counter Control */
- pulse.init[T32A_TIMERA].crx.prscl = T32A_PRSCLx_8;
- pulse.init[T32A_TIMERA].crx.clk = T32A_CLKx_PRSCLx;
- pulse.init[T32A_TIMERA].crx.wbf = T32A_WBF_DISABLE;
- pulse.init[T32A_TIMERA].crx.updn = T32A_COUNT_UP;
- pulse.init[T32A_TIMERA].crx.reld = T32A_RELOAD_TREGx;
- pulse.init[T32A_TIMERA].crx.stop = T32A_STOP_NON;
- pulse.init[T32A_TIMERA].crx.start = T32A_START_NON;
- /* Output Control 0 */
- pulse.init[T32A_TIMERA].outcrx0.ocr = T32A_OCR_DISABLE;
- /* Output Control 1 */
- pulse.init[T32A_TIMERA].outcrx1.ocrcap1 = T32A_OCRCAPx1_DISABLE;
- pulse.init[T32A_TIMERA].outcrx1.ocrcap0 = T32A_OCRCAPx0_DISABLE;
- pulse.init[T32A_TIMERA].outcrx1.ocrcmp1 = T32A_OCRCMPx1_CLR;
- pulse.init[T32A_TIMERA].outcrx1.ocrcmp0 = T32A_OCRCMPx0_SET;
- /* Counter Capture */
- pulse.init[T32A_TIMERA].tmrx.tmrx = 0;
- /* Counter Capture Control A0 */
- pulse.init[T32A_TIMERA].capx0.capx0 = 0;
- /* Counter Capture Control A1 */
- pulse.init[T32A_TIMERA].capx1.capx1 = 0;
- /* Interrupt mask register Set */
- pulse.init[T32A_TIMERA].imx.imuf = T32A_IMUFx_MASK_REQ;
- pulse.init[T32A_TIMERA].imx.imof = T32A_IMOFx_MASK_REQ;
- pulse.init[T32A_TIMERA].imx.imx1 = T32A_IMx1_MASK_NOREQ;
- pulse.init[T32A_TIMERA].imx.imx0 = T32A_IMx0_MASK_NOREQ;
- /* DMA Request */
- pulse.init[T32A_TIMERA].dma_req.dmaenx2 = T32A_DMAENx2_DISABLE;
- pulse.init[T32A_TIMERA].dma_req.dmaenx1 = T32A_DMAENx1_DISABLE;
- pulse.init[T32A_TIMERA].dma_req.dmaenx0 = T32A_DMAENx0_DISABLE;
- /* User ID */
- pulse.init[T32A_TIMERA].id = 0;
- /* Handler */
- pulse.init[T32A_TIMERA].handler_T = TT_M3HQ_PulseHandler;
- /* CG Driver Register Address Allocation. */
- paramCG.p_instance = TSB_CG;
- // 100us
- if(t32a_Calculator(&pulse.init[T32A_TIMERA].rgx0.rgx0, 100, cg_get_phyt0(¶mCG), pulse.init[T32A_TIMERA].crx.prscl) != TXZ_SUCCESS)
- {
- TT_M3HQ_Warning();
- }
- // 200us --> Freq : 5kHz
- if(t32a_Calculator(&pulse.init[T32A_TIMERA].rgx1.rgx1, 200, cg_get_phyt0(¶mCG), pulse.init[T32A_TIMERA].crx.prscl) != TXZ_SUCCESS)
- {
- TT_M3HQ_Warning();
- }
- if (t32a_timer_init(&pulse, T32A_TIMERA) != TXZ_SUCCESS)
- {
- TT_M3HQ_Warning();
- }
- if(flag) TT_M3HQ_PulseTimerStart();
- else TT_M3HQ_PulseTimerStop();
- }
3.4.串口初始化
- static void TT_M3HQ_UART0_TxHandler(uint32_t id, TXZ_Result result)
- {
- }
- static void TT_M3HQ_UART0_RxHandler(uint32_t id, TXZ_Result result, uart_receive_t *p_info)
- {
- uint32_t i = 0;
- if(result == TXZ_SUCCESS)
- {
- for(i = 0; i < p_info->rx8.num; i++)
- {
- QUEUE_WRITE(QUEUE_DEBUG_RX_IDX, p_info->rx8.p_data[i]);
- }
- }
- }
- static void TT_M3HQ_InitUART0(void)
- {
- cg_t paramCG;
- paramCG.p_instance = TSB_CG;
- port.p_pa_instance = TSB_PA;
- if(gpio_init(&port, GPIO_PORT_A) != TXZ_SUCCESS)
- {
- TT_M3HQ_Warning();
- }
- /* PA1 - UART0 TXD */
- if(gpio_func(&port, GPIO_PORT_A, GPIO_PORT_1, (uint32_t)GPIO_PA1_UT0TXDA, GPIO_PIN_OUTPUT) != TXZ_SUCCESS)
- {
- TT_M3HQ_Warning();
- }
- /* PA2 - UART0 RXD */
- if(gpio_func(&port, GPIO_PORT_A, GPIO_PORT_2, (uint32_t)GPIO_PA2_UT0RXD, GPIO_PIN_INPUT) != TXZ_SUCCESS)
- {
- TT_M3HQ_Warning();
- }
- uart0.p_instance = TSB_UART0;
- uart0.init.id = 0;
- uart0.init.clock.prsel = UART_PLESCALER_1;
- if(uart_get_boudrate_setting(cg_get_phyt0(¶mCG), &uart0.init.clock, 115200, &uart0.init.boudrate) != TXZ_SUCCESS)
- {
- TT_M3HQ_Warning();
- }
- uart0.init.inttx = UART_TX_INT_ENABLE;
- uart0.init.intrx = UART_RX_INT_ENABLE;
- uart0.init.interr = UART_ERR_INT_ENABLE;
- uart0.init.txfifo.inttx = UART_TX_FIFO_INT_DISABLE;
- uart0.init.txfifo.level = 0;
- uart0.init.rxfifo.intrx = UART_RX_FIFO_INT_DISABLE;
- uart0.init.rxfifo.level = 8;
- uart0.init.nf = UART_NOISE_FILTER_NON;
- uart0.init.ctse = UART_CTS_DISABLE;
- uart0.init.rtse = UART_RTS_DISABLE;
- uart0.init.iv = UART_DATA_COMPLEMENTION_DISABLE;
- uart0.init.dir = UART_DATA_DIRECTION_LSB;
- uart0.init.sblen = UART_STOP_BIT_1;
- uart0.init.even = UART_PARITY_BIT_ODD;
- uart0.init.pe = UART_PARITY_DISABLE;
- uart0.init.sm = UART_DATA_LENGTH_8;
- uart0.transmit.handler = TT_M3HQ_UART0_TxHandler;
- uart0.receive.handler = TT_M3HQ_UART0_RxHandler;
- if(uart_init(&uart0) != TXZ_SUCCESS)
- {
- TT_M3HQ_Warning();
- }
- {
- uart_receive_t rx;
- rx.rx8.p_data = UART0_Buffer;
- rx.rx8.num = 100;
- if(uart_receiveIt(&uart0, &rx) != TXZ_SUCCESS)
- {
- TT_M3HQ_Warning();
- }
- }
- NVIC_EnableIRQ(INTUART0RX_IRQn);
- NVIC_EnableIRQ(INTUART0TX_IRQn);
- NVIC_EnableIRQ(INTUART0ERR_IRQn);
- }
3.5.电机运转使能、方向和速度控制
- void TT_M3HQ_MotorDIR(uint32_t dir)
- {
- if(dir)
- {
- gpio_write_bit(&port, GPIO_PORT_J, GPIO_PORT_3, GPIO_Mode_DATA, GPIO_PIN_RESET); // DIR 顺时针
- }
- else
- {
- gpio_write_bit(&port, GPIO_PORT_J, GPIO_PORT_3, GPIO_Mode_DATA, GPIO_PIN_SET); // DIR 逆时针
- }
- }
- void TT_M3HQ_MotorPUL(uint32_t Hz)
- {
- cg_t paramCG;
- uint32_t rgx0 = 0;
- uint32_t rgx1 = 0;
- uint32_t time = 1000 * 1000 / Hz;
- /* CG Driver Register Address Allocation. */
- paramCG.p_instance = TSB_CG;
- if(t32a_Calculator(&rgx0, (time / 2), cg_get_phyt0(¶mCG), pulse.init[T32A_TIMERA].crx.prscl) != TXZ_SUCCESS)
- {
- TT_M3HQ_Warning();
- }
- if(t32a_Calculator(&rgx1, (time / 1), cg_get_phyt0(¶mCG), pulse.init[T32A_TIMERA].crx.prscl) != TXZ_SUCCESS)
- {
- TT_M3HQ_Warning();
- }
- /* T32A Timer Register A0 Set */
- pulse.p_instance->RGA0 = 0;
- pulse.p_instance->RGA0 = rgx0;
- /* T32A Timer Register A1 Set */
- pulse.p_instance->RGA1 = 0;
- pulse.p_instance->RGA1 = rgx1;
- }
- void TT_M3HQ_MotorRUN(uint32_t en)
- {
- if(en)
- {
- gpio_write_bit(&port, GPIO_PORT_J, GPIO_PORT_5, GPIO_Mode_DATA, GPIO_PIN_SET); // ENA 使能
- }
- else
- {
- gpio_write_bit(&port, GPIO_PORT_J, GPIO_PORT_5, GPIO_Mode_DATA, GPIO_PIN_RESET); // ENA 禁止
- }
- }
3.6.PC控制命令解析和执行
- static void MessageHandler(void)
- {
- uint8_t i = 0;
- static uint32_t frequency = 5000;
- if(QUEUE_EMPTY(QUEUE_DEBUG_RX_IDX) == 0)
- {
- gucDebugBuffer[guiDebugLength++] = QUEUE_READ(QUEUE_DEBUG_RX_IDX);
- if(strncmp((char *)(gucDebugBuffer + guiDebugLength - 2), "\r\n", 2) == 0)
- {
- if(strcmp((char *)gucDebugBuffer, "\r\n") == 0)
- {
- printf("\r\nEmpty Line");
- }
- else
- {
- char *line = strtok((char *)gucDebugBuffer, "\r\n");
- if( strcmp(line, "start") == 0) TT_M3HQ_MotorRUN(1);
- else if(strcmp(line, "stop" ) == 0) TT_M3HQ_MotorRUN(0);
- else if(strcmp(line, "dir=1") == 0) TT_M3HQ_MotorDIR(1);
- else if(strcmp(line, "dir=0") == 0) TT_M3HQ_MotorDIR(0);
- else if(strcmp(line, "led=1") == 0) {for(i = 0; i < 4; i++) TT_M3HQ_LEDOnOFF(i, 1);}
- else if(strcmp(line, "led=0") == 0) {for(i = 0; i < 4; i++) TT_M3HQ_LEDOnOFF(i, 0);}
- else if(strcmp(line, "rgx++") == 0) {frequency += 500; TT_M3HQ_MotorPUL(frequency);}
- else if(strcmp(line, "rgx--") == 0) {frequency -= 500; TT_M3HQ_MotorPUL(frequency);}
- else printf("\r\nInvalid command");
- printf("\r\n%s", line);
- }
- guiDebugLength = 0;
- memset(gucDebugBuffer, 0, sizeof(gucDebugBuffer));
- }
- }
- }
4.调试运行
4.1.PC调试软件及控制指令
4.2.电机运转在500Hz的频率下
4.3.电机运转在13kHz的频率下
5.关于SCOU输出的疑问
参照原厂的代码,external_losc_enable如果调用,SCOUT选择fs,烧录程序后复位运行,SCOUT有32.768kHz的频率输出;这个时候如果不调用external_losc_enable,SCOUT选择fs,烧录程序后复位运行,SCOUT仍然有32.768kHz的频率输出;只的在整个板子断电后再上电运行,SCOUT才没有输出;也就是说,复位对选择fs进行SCOUT输出没有影响,这是正常现象吗?
6.工程代码
热门活动
全部回复 3