RT1062 TMR 0 - 100 % duty PWM

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

RT1062 TMR 0 - 100 % duty PWM

2,109 Views
scatty
Contributor I

Hi,

I am using TMR instance with variable-frequency pwm mode (toggle OFLAG output using alternating compare registers). 

Is it possible to achieve 0% and 100% duty hardware PWM? COMPN == 0 generates one clock cycle wide pulse -  depends on TMR clock. For 150 MHz its about 6ns, but for prescaled clocks it will be much more.

Adam

0 Kudos
Reply
8 Replies

2,103 Views
jeremyzhou
NXP Employee
NXP Employee

Hi,

Thank you for your interest in NXP Semiconductor products and for the opportunity to serve you.
To provide the fastest possible support, I'd highly recommend you to refer to the qtmr_inputcapture_outputpwm demo in the SDK library, which demonstrates how to set up the QTMR channel to output PWM.
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.
-------------------------------------------------------------------------------

0 Kudos
Reply

2,100 Views
scatty
Contributor I

Hi,

I have already tested:

1. qtmr_inputcapture_outputpwm - which generates 50% PWM

2. qtmr_inputcapture_outputpwm_dma - which explictly forbids 0% and 100% PWM, because it's not working properly.

My question is - is there any workaround for this?

0 Kudos
Reply

2,059 Views
jeremyzhou
NXP Employee
NXP Employee

Hi,

Thanks for your reply.
In qtmr_inputcapture_outputpwm demo, it has provided the QTMR_SetupPwm() function to set up the PWM signal output, which supports to configure different sets of frequency and duty percent.
So I think you can give a try.


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.
-------------------------------------------------------------------------------

0 Kudos
Reply

2,097 Views
mjbcswitzerland
Specialist V

Hi

As reference I am showing the routine that is used to control the intensity of the TFT display back light on the 1060-EVK in the uTasker project.
It uses the FlexPWM rather than the Quad-Timer but the relevant fact for you is the way that it controls the 0% and 100% cases.
Instead of generating 0% and 100% PWM signals it simply switches the output over to its GPIO function and drives '0' or '1 levels.

 

extern void fnSetBacklight(unsigned char ucBacklightPWM)
{

    if (ucBacklightPWM >= 100) {                                          // consider as maximum brightness and apply constant '1'
        _CONFIG_DRIVE_PORT_OUTPUT_VALUE(2, (LCD_BACKLIGHT), (LCD_BACKLIGHT), (PORT_SRE_SLOW | PORT_DSE_LOW))
    }
    else if (ucBacklightPWM == 0) {                                       // consider as off and apply constant '0'
        _CONFIG_DRIVE_PORT_OUTPUT_VALUE(2, (LCD_BACKLIGHT), (0), (PORT_SRE_SLOW | PORT_DSE_LOW))
    }
    else {
        PWM_INTERRUPT_SETUP timer_setup;
        timer_setup.int_type = PWM_INTERRUPT;                            // PWM setup type
        timer_setup.int_handler = 0;
        timer_setup.pwm_reference = (_FLEX_PWM_4 | _FLEX_PWM_A_3);       // the timer to generate the control signal with
        timer_setup.pwm_mode  = (PWM_SYS_CLK | PWM_PRESCALER_16 | PWM_EDGE_ALIGNED); // generate PWM signal on this timer output port
        timer_setup.pwm_frequency = PWM_FREQUENCY(20000, 16);            // backlight frequency
        timer_setup.pwm_value  = _PWM_PERCENT(ucBacklightPWM, timer_setup.pwm_frequency); // PWM value
        fnConfigureInterrupt((void *)&timer_setup);                      // configure PWM output for backlight control
    }
}

 

This is generally a good solution because HW timers often have difficulties at the extremes and even when set to 0 and 100% generate very small spikes, and in some cases it may not be possible/allowed to do it due to the timer's design.
Therefore it is also a general "workaround" to ensure exact operation in any case.

Regards

Mark
[uTasker project developer for Kinetis and i.MX RT]
Contact me by personal message or on the uTasker web site to discuss professional training or product development requirements

 

0 Kudos
Reply

2,092 Views
scatty
Contributor I

Hi Mark,

Thanks You for Your efforts, but You have presented software solution, which I can implement on my own. I am using variable-frequency PWM with highest possible clock to drive 3 - 4 stepper/servo motors, so any hardware solution will be much better than software. 

From Your post, I guess there is not any hardware workaround. I find pin mux change at run time as not elegant solution  

Thanks,

Adam

0 Kudos
Reply

2,087 Views
mjbcswitzerland
Specialist V

Hi Adam

If you are controlling the PWM value via HW a software manipulation is of course not very suitable. However you didn't make this clear in your post so I suggested a simple workaround (as you asked whether workarounds were available) which is valid for non-HW controlled PWM values.

Another reason why I thought you must be doing simple PWM control is the fact that you are using the QUAD-Timer for this, whereby the PWM capability is really just a side-note to it main purpose and usage. Normally for PWM application one would use the FlexPWM module which is massively more capable than the Quad-Timer for such functions.

Can you explain the reasons for the decision to use the Quad-Timer for such an application?

Regards

Mark

 

0 Kudos
Reply

2,033 Views
scatty
Contributor I

HI Mark,

Sorry for late reply. I am new to NXP MCU, until now I was using Atmel SAM. So now, I am doing just research, writting drivers with tests, checking hardware possibilities. 

About using QTMR over FlexPWM - as You mentioned in Your post (didn't tested FlexPWM yet), FlexPWM also can't generate hardware constant OFF period, so for my purpose QTMR will be much better. Let me explain: motors are driven with STEP and DIR signals. So, what I need is:

1. Highest possible clock (150 MHz I guess?)

2. Possibility to generate constant OFF period, because QTMR/PWM timers are 16-bit wide and during acceleration and decceleration phases, OFF period have to be longer than 16-bit.

 

After every single step, there is calculation for new period and so on. I am going to chain 2 channels of QTMR:

1. First channel is going to just generate pulses for second channel

2. Second channel will generate hardware STEP signal. OFF period will be always shorter than 32-bit timer. 

3. Simple math to calculate COMP1, COMP2 values for second channel, DMA for first channel CMPLD1 and CMPLD2. 

4. Also I can chain third channel to calculate current position of motor by counting second channel pulses. 

Regards,

Adam

0 Kudos
Reply

2,020 Views
mjbcswitzerland
Specialist V

Hi Adam

You can also consider the FlexIO and there are connection possibilities between the timer modules via the XBAR (with AIO for logic functions) so even if a single timer by itself doesn't allow the perfect operation be be achieved a combination may make it possible.

See XBAR/AIO video here: https://www.youtube.com/watch?v=zNWIG-O7ZW0&list=PLWKlVb_MqDQEOCnsNOJO8gd3jDCwiyKKe&index=6

Regards

Mark

 

0 Kudos
Reply