Hi,
have you ever figured out what the underlying problem was? I have a very similar situation on an RT1020 but I am not using Keil.
Hi.
Did you test this waveform using the routine test I shared? If not, please download my project directly and test it with MCUXpresso IDE.
Have a great day,
TIC
-------------------------------------------------------------------------------
Note:
- If this post answers your question, please click the " Mark Correct " button. Thank you!
- We are following threads for 7 weeks after the last post, later replies are ignored
Please open a new thread and refer to the closed one, if you have a related Please open a new thread and refer to the closed one, if you have a related question at a later point in time.
-------------------------------------------------------------------------------
Have you ever sent the code and then reset it with the software in emulation before sending it again? When I run the code again after a software reset with KEIL it sends an incorrect number of pulses, the first time I run the code after powering up the board it sends the correct number of pulses.
Also is it convenient for you to do a test with keil? Or take a look at the KEIL routine I sent you and test it with that.
Hi,
I am using MCUXpreeso IDE, because my output is in GPIO_AD_B1_00, J23-6 in MIMXRT1050, so I need to initialize its related pins, the corresponding code is in BOARD_InitPins() function.
Have a great day,
TIC
-------------------------------------------------------------------------------
Note:
- If this post answers your question, please click the " Mark Correct " button. Thank you!
- We are following threads for 7 weeks after the last post, later replies are ignored
Please open a new thread and refer to the closed one, if you have a related Please open a new thread and refer to the closed one, if you have a related question at a later point in time.
-------------------------------------------------------------------------------
I found that the code downloaded to the board every time I press the board reset button the logic analyzer can catch the waveform, every time I press it the waveform and the number of pulses caught are correct, but in the keil debug state with the reset on the software at runtime with the logic analyzer the number of pulses caught will be one more, you can try it. You can try it and see what is the reason.
I can't get a waveform in the simulation, and I can catch the waveform with a manual reset of the board, but the waveform is also not correct, and the number of pulses is also not correct.
Board IMXRT1050-EVKB
The pins are J23's 6
/*
* Copyright 2017-2020 NXP
* All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
/*******************************************************************************
* Includes
******************************************************************************/
#include "fsl_debug_console.h"
#include "board.h"
#include "bsp_tmr.h"
//#include "fsl_qtmr.h"
#include "pin_mux.h"
#include "clock_config.h"
/*******************************************************************************
* Definitions
******************************************************************************/
/* The QTMR instance/channel used for board */
#define BOARD_QTMR_BASEADDR TMR3
#define BOARD_FIRST_QTMR_CHANNEL kQTMR_Channel_0
#define BOARD_SECOND_QTMR_CHANNEL kQTMR_Channel_1
#define QTMR_ClockCounterOutput kQTMR_ClockCounter0Output
/* Interrupt number and interrupt handler for the QTMR instance used */
#define QTMR_IRQ_ID TMR3_IRQn
#define QTMR_IRQ_HANDLER TMR3_IRQHandler
/* QTMR Clock source divider for Ipg clock source, the value of two macros below should be aligned. */
#define QTMR_PRIMARY_SOURCE (kQTMR_ClockDivide_128)
#define QTMR_CLOCK_SOURCE_DIVIDER (128U)
/* The frequency of the source clock after divided. */
#define QTMR_SOURCE_CLOCK (CLOCK_GetFreq(kCLOCK_IpgClk) / QTMR_CLOCK_SOURCE_DIVIDER)
/*******************************************************************************
* Prototypes
******************************************************************************/
/*******************************************************************************
* Variables
******************************************************************************/
volatile bool qtmrIsrFlag = false;
/*******************************************************************************
* Code
******************************************************************************/
void QTMR_IRQ_HANDLER(void)
{
/* Clear interrupt flag.*/
QTMR_ClearStatusFlags(BOARD_QTMR_BASEADDR, BOARD_SECOND_QTMR_CHANNEL, kQTMR_CompareFlag);
qtmrIsrFlag = true;
}
/*!
* @brief Main function
*/
int main(void)
{
uint32_t i = 0;
qtmr_config_t qtmrConfig;
gpio_pin_config_t gpt_config;
gpt_config.direction = kGPIO_DigitalOutput;
gpt_config.outputLogic = 0;
gpt_config.interruptMode = kGPIO_NoIntmode;
/* Board pin, clock, debug console init */
BOARD_ConfigMPU();
BOARD_InitPins();
BOARD_BootClockRUN();
BOARD_InitDebugConsole();
GPIO_PinInit(GPIO1, 16, &gpt_config);
QTMR_GetDefaultConfig(&qtmrConfig);
/* Initial the input channel. */
qtmrConfig.primarySource = QTMR_PRIMARY_SOURCE;
QTMR_Init(BOARD_QTMR_BASEADDR, BOARD_SECOND_QTMR_CHANNEL, &qtmrConfig);
IpFreq=CLOCK_GetFreq(kCLOCK_IpgClk);
//PlsueCh0Init();
PulseChxStream_Init(TMR3,TMR3_IRQn,100000,4,1,0,0x0A67);
for(i=0;i<100000000;i++);
PulseChxStream_Init(TMR3,TMR3_IRQn,100000,4,1,0,0x0A67);
for(i=0;i<100000000;i++);
PulseChxStream_Init(TMR3,TMR3_IRQn,100000,4,1,0,0x0A67);
for(i=0;i<100000000;i++);
PulseChxStream_Init(TMR3,TMR3_IRQn,100000,4,1,0,0x0A67);
while (1)
{
}
}
我把您的代码移植到qtmr_timer的例程里替换掉源文件,编译下载到板卡仿真,用逻辑分析仪抓取不到波形
Are you using KEIL? I have KEIL 5.27, how come I can't open your function file?
Hi,
I modified evkbimxrt1050_qtmr_timer code in SDK library to implement Pulse-Output Mode according to the code you shared, and the function is normal under test.
PWM output pin is GPIO_AD_B1_00, J23-6 in MIMXRT1050.
Attached is my code.
Have a great day,
TIC
-------------------------------------------------------------------------------
Note:
- If this post answers your question, please click the " Mark Correct " button. Thank you!
- We are following threads for 7 weeks after the last post, later replies are ignored
Please open a new thread and refer to the closed one, if you have a related Please open a new thread and refer to the closed one, if you have a related question at a later point in time.
-------------------------------------------------------------------------------
KEIL 5.27 development environment used
The analyzer measures Pin6 of GPIO2
Hi.
Please share the complete code project and I'll test it with a MIMXRT1050 board to see if I can reproduce the problem.
Have a great day,
TIC
-------------------------------------------------------------------------------
Note:
- If this post answers your question, please click the " Mark Correct " button. Thank you!
- We are following threads for 7 weeks after the last post, later replies are ignored
Please open a new thread and refer to the closed one, if you have a related Please open a new thread and refer to the closed one, if you have a related question at a later point in time.
-------------------------------------------------------------------------------
I am trying to control the stepper motor in this way to do angle control, if the number of pulses sent is not correct it will definitely affect the accuracy of the motor rotation angle.
I've tested this over and over again, and I feel that QTMER channel 0 is not turning off the output in time after the counting comparison, causing the output channel to send an extra pulse.
It feels like it's still a problem with the chip's hardware, and my program follows the manual's examples to the letter. You can also use 1052-EVK to actually test it.
If you have a code example, send it to me and I'll test it with a logic analyzer.
Thank you!
Hello, this is not a regular occurrence, sometimes the correct number is sent, sometimes it's just wrong for several times in a row (always 1 more).
There will also be times when you will send the right quantity once, and then send it again with one more quantity, and so on alternately.
However, each time you reset the chip the first time you send the quantity is correct, after sending it once it is not correct.
Hi.
Do the multiple discoveries you are talking about happen every time? Or is there a fixed rate or order of occurrence?
Have a great day,
TIC
-------------------------------------------------------------------------------
Note:
- If this post answers your question, please click the " Mark Correct " button. Thank you!
- We are following threads for 7 weeks after the last post, later replies are ignored
Please open a new thread and refer to the closed one, if you have a related Please open a new thread and refer to the closed one, if you have a related question at a later point in time.
-------------------------------------------------------------------------------
I set LENGTH=0 to read the value in the CNTR after the send is complete, LENGTH=1 would have the CNTR preloaded with the new value as soon as the counting is complete, so that the value would not be read.
Hello: After I set LENGTH=1 the count is still incorrect, sometimes it sends 1 more pulse, and repeated tests the pulse will only send more and not less.
Hi,
Thank you for your interest in NXP Semiconductor products and for the opportunity to serve you.
After going through your demo code, it's basic as same as the code in the RM (as the figures show).
And I find that the below code is inconsistent with the comment, so please check it carefully.
// 定时器3的输出是该定时器的时钟源。
/* TMR1_CTRL: CM=0,PCS=7,SCS=0,ONCE=1,LENGTH=1,DIR=0,COINIT=0,OUTMODE=7 */
TIMx->CHANNEL[OutChanel].CTRL=OutMode; /* 0x0A47 设置模式 TMR3的定时器1作为通道0的时钟源 */
Have a great day,
TIC
-------------------------------------------------------------------------------
Note:
- If this post answers your question, please click the "Mark Correct" button. Thank you!
- We are following threads for 7 weeks after the last post, later replies are ignored
Please open a new thread and refer to the closed one, if you have a related question at a later point in time.
-------------------------------------------------------------------------------
47.6.5.12 Pulse-Output Mode used
This routine used
TIMx- >CHANNEL[OutChanel].CTRL &=~TMR_CTRL_CM_MASK; /* reset counter */
TIMx- >CHANNEL[TimChanel].CTRL &=~TMR_CTRL_CM_MASK; /* reset timer */
// select IP_bus_clk / 16 as the clock source for Timer 3
/* TMR3_CTRL: CM = 0, PCS = 0x0C, SCS = 0, ONCE = 0, LENGTH = 1, DIR = 0, COINIT = 0, OUTMODE = 3 */
// TMR3- >CHANNEL[1].COMP1=CLOCK_GetFreq(kCLOCK_ IpgClk)/128/Plusefreq; /* (16 * 37500) / 60e6 = 0.01 sec */
if(Plusefreq <10000)
{
TIMx- >CHANNEL[TimChanel].CTRL=0x1E23; /* Set mode */
TIMx- >CHANNEL[ TimChanel].COMP1=IpFreq/128/(Plusefreq);
}
else
{
TIMx- >CHANNEL[TimChanel].CTRL=0x1023; /* set mode */
TIMx- >CHANNEL[TimChanel].COMP1=IpFreq/1 /(Plusefreq);
}
/* TMR3_SCTRL: TCF = 0, TCFIE = 0, TOF = 0, TOFIE = 0, IEF = 0, IEFIE = 0, IPS = 0, INPUT = 0,
Functional Description
Capture_Mode = 0, MSTR = 0, EEOF = 0, VAL = 0, FORCE = 0 , OPS = 0, OEN = 0
*/
TIMx- >CHANNEL[TimChanel].SCTRL=0x00;
TIMx- >CHANNEL[TimChanel]. LOAD=0x00; /* Reset load register */
/* TMR3_CSCTRL: DBG_EN=0,FAULT=0,ALT_LOAD=0,ROC=0,TCI=0,UP=0,OFLAG=0,
TCF2EN=0,TCF1EN=0,TCF2=0,TCF1=0,CL2=0,CL1= 0 */
TIMx- >CHANNEL[TimChanel].CSCTRL=0x00; /* Set Comparator Control Register */
// The output of Timer 3 is the clock source for this timer.
/* TMR1_CTRL: CM=0,PCS=7,SCS=0,ONCE=1,LENGTH=1,DIR=0,COINIT=0,OUTMODE=7 */
TIMx- >CHANNEL[OutChanel].CTRL=OutMode; /* 0x0A47 Setting Mode Timer1 of TMR3 as clock source for channel 0 */
/* TMR1_SCTRL: TCF=0,TCFIE=0,TOF=0,TOFIE=0,IEF=0,IEFIE=0,IPS=0,INPUT=0,
Capture_Mode=0,MSTR=0,EEOF=0,VAL=0,FORCE=0,OPS=0, OEN=1 */
TIMx- >CHANNEL[OutChanel].SCTRL=0x0001;
TIMx- >CHANNEL[OutChanel].CNTR=0x00; /* Reset counter register */
TIMx- >CHANNEL[OutChanel].LOAD=0x00; /* Reset Load register */
TIMx- >CHANNEL[OutChanel].COMP1=PluseData; /* Set compare 1 register Number of pulses to output */
// Set to interrupt after last pulse
/* TMR1_CSCTRL: DBG_EN=0,FAULT=0,ALT_LOAD=0,ROC=0, TCI=0,UP=0,OFLAG=0,
TCF2EN=0,TCF1EN=1,TCF2=0,TCF1=0,CL2=0,CL1=0 */
TIMx- >CHANNEL[OutChanel].CSCTRL=0x40; /* Set Comparator Control Register */
// Finally, start the counter running
TIMx - >CHANNEL[TimChanel]. CNTR=0; /* Reset counter */
// /* Set interrupt priority,*/
// set_IRQn_Priority(IRQn,Group4_PreemptPriority_6, Group4_SubPriority_0);
// // /* Turn on interrupt */
// EnableIRQ(IRQn);
TIMx- >CHANNEL[OutChanel].CTRL|=(1 << 13); /* Run counter */
TIMx- >CHANNEL[TimChanel].CTRL|=(1 << 13); /* Run source clock counter */
Here's the routine I changed.
I need to send the exact number of pulses to control the stepper motor to rotate at a certain angle, the number of pulses sent should not be too much or too little so that the angle is accurate.
I now realize the 10HZ-500KHZ frequency send, is the number of pulses have more than one phenomenon, interrupting the debugging point feel is the manual routine TMR1 shutdown is not timely caused by more than one, monitor the value of CNTR and compare the value of the register is the same, there is a head nodding don't know what the problem is, please point out. Thank you!