<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: How to change duty cycle using TPM? in Kinetis Microcontrollers</title>
    <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/How-to-change-duty-cycle-using-TPM/m-p/891613#M52697</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I think I understood what you said. My PWM frequency is 50Hz, so the PWM period is 20ms. My sample time must be greater than 20ms, right? Seems obvious, but I didn't realize it earlier.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 17 May 2019 15:24:54 GMT</pubDate>
    <dc:creator>nícolasludwig</dc:creator>
    <dc:date>2019-05-17T15:24:54Z</dc:date>
    <item>
      <title>How to change duty cycle using TPM?</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/How-to-change-duty-cycle-using-TPM/m-p/891608#M52692</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello everybody.&lt;/P&gt;&lt;P&gt;My board is FRDM-KL27Z and I use Kinetis Design Studio. I'm using the accelerometer (bubble_level_tpm example on KSDK 1.3.0 folder) and the TPM driver example, at the same folder. In short, my project consists to equilibrate a bar using two brushless motors, simulating a drone. This video explains what I'm trying to do:&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;A href="https://www.youtube.com/watch?v=AN3yxIBAxTA" style="color: #2989c5; text-decoration: none;"&gt;https://www.youtube.com/watch?v=AN3yxIBAxTA&lt;/A&gt;&lt;/P&gt;&lt;P&gt;I get the accelerometer data, calculate the PID control, and then the result of PID is used to send PWM signal to the ESCs, which controls the motors. I'm also using LPTMR to make a sampling time of 5ms.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;#include &amp;lt;stdio.h&amp;gt;&lt;BR /&gt;#include &amp;lt;string.h&amp;gt;&lt;BR /&gt;// SDK Included Files&lt;BR /&gt;#include "board.h"&lt;BR /&gt;#include "fsl_lptmr_driver.h"&lt;BR /&gt;#include "fsl_tpm_driver.h"&lt;BR /&gt;#include "fsl_debug_console.h"&lt;BR /&gt;#include "accel.h"&lt;BR /&gt;#include "fsl_clock_manager.h"&lt;/P&gt;&lt;P&gt;#define LPTMR_INSTANCE 0U&lt;/P&gt;&lt;P&gt;short int tempoInterrupt = 0;&lt;BR /&gt;void lptmr_isr_callback(void)&lt;BR /&gt;{&lt;BR /&gt; tempoInterrupt = 1;&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;void delay (uint32_t d)&lt;BR /&gt;{&lt;BR /&gt; uint32_t t;&lt;BR /&gt; for (t=0; t &amp;lt; d; t++);&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;int main (void)&lt;BR /&gt;{&lt;BR /&gt; // ********** VARIÁVEIS PID **********&lt;BR /&gt; /* Variáveis de controle do cálculo do PID.*/&lt;BR /&gt; float erro = 0; // Variável que recebe o erro.&lt;BR /&gt; float erroAnterior = 0; // Variável para a realmientação do erro.&lt;BR /&gt; float proporcional = 0;&lt;BR /&gt; float integral = 0; // Variável para controle do integrador.&lt;BR /&gt; float derivativo = 0; // Variável para controle do derivador.&lt;/P&gt;&lt;P&gt;/* Variáveis de controle para o motor.*/&lt;BR /&gt; int PID = 0; // Sentido do Giro do Motor&lt;BR /&gt; unsigned int PWM = 0; // Valor do PWM para ser enviado ao motor.&lt;/P&gt;&lt;P&gt;/* Variáveis de controle da posição.*/&lt;BR /&gt; int SetPoint = 0; // Valor do SetPoint.&lt;BR /&gt; //int posAtual = 0; // Recebera o valor de posicao atual.&lt;/P&gt;&lt;P&gt;/* Valores do controlador e tempo de amostragem.*/&lt;BR /&gt; short int tAmost = 5; // Tempo de amostragem que queremos para o nosso sistema em milisegundos.&lt;BR /&gt; float KP = 1; // Ganho Porporcional.&lt;BR /&gt; float KI = 0; // Ganho Integral.&lt;BR /&gt; float KD = 0; // Ganho Derivativo.&lt;BR /&gt; float p = 100; // Frequencia de 100 rad/s. Somente passará os 100.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt; short int ehnegativo = 0;&lt;/P&gt;&lt;P&gt;lptmr_state_t lptmrState;&lt;BR /&gt; // Configure LPTMR.&lt;BR /&gt; lptmr_user_config_t lptmrUserConfig =&lt;BR /&gt; {&lt;BR /&gt; .timerMode = kLptmrTimerModeTimeCounter, /*! Use LPTMR in Time Counter mode */&lt;BR /&gt; .freeRunningEnable = false, /*! When hit compare value, set counter back to zero */&lt;BR /&gt; .prescalerEnable = false, /*! bypass prescaler */&lt;BR /&gt; .prescalerClockSource = kClockLptmrSrcLpoClk, /*! use 1kHz Low Power Clock */&lt;BR /&gt; .isInterruptEnabled = true&lt;BR /&gt; };&lt;/P&gt;&lt;P&gt;// Initialize LPTMR&lt;BR /&gt; LPTMR_DRV_Init(LPTMR_INSTANCE, &amp;amp;lptmrState, &amp;amp;lptmrUserConfig);&lt;/P&gt;&lt;P&gt;// Set the timer period for 5 milliseconds&lt;BR /&gt; LPTMR_DRV_SetTimerPeriodUs(LPTMR_INSTANCE, 5000);&lt;/P&gt;&lt;P&gt;// Specify the callback function when a LPTMR interrupt occurs&lt;BR /&gt; LPTMR_DRV_InstallCallback(LPTMR_INSTANCE, lptmr_isr_callback);&lt;/P&gt;&lt;P&gt;&lt;BR /&gt; tpm_general_config_t driverInfo;&lt;/P&gt;&lt;P&gt;//*************************************************************&lt;BR /&gt; //******************** VARIÁVEIS PARA PWM *********************&lt;BR /&gt; tpm_pwm_param_t motor1 = {&lt;BR /&gt; .mode = kTpmEdgeAlignedPWM,&lt;BR /&gt; .edgeMode = kTpmHighTrue,&lt;BR /&gt; .uFrequencyHZ = 50u,&lt;BR /&gt; .uDutyCyclePercent = 6.5&lt;BR /&gt; };&lt;/P&gt;&lt;P&gt;tpm_pwm_param_t motor2 = {&lt;BR /&gt; .mode = kTpmEdgeAlignedPWM,&lt;BR /&gt; .edgeMode = kTpmHighTrue,&lt;BR /&gt; .uFrequencyHZ = 50u,&lt;BR /&gt; .uDutyCyclePercent = 6.5&lt;BR /&gt; };&lt;/P&gt;&lt;P&gt;//*************************************************************&lt;BR /&gt; //**************** VARIÁVEIS PARA ACELERÔMETRO ****************&lt;BR /&gt; accel_dev_t accDev;&lt;BR /&gt; accel_dev_interface_t accDevice;&lt;BR /&gt; accel_sensor_data_t accelData;&lt;BR /&gt; accel_i2c_interface_t i2cInterface;&lt;BR /&gt; tpm_pwm_param_t yAxisParams;&lt;BR /&gt; tpm_pwm_param_t xAxisParams;&lt;BR /&gt; int16_t xData, yData;&lt;BR /&gt; int16_t xAngle, yAngle;&lt;/P&gt;&lt;P&gt;// Register callback func for I2C&lt;BR /&gt; i2cInterface.i2c_init = I2C_DRV_MasterInit;&lt;BR /&gt; i2cInterface.i2c_read = I2C_DRV_MasterReceiveDataBlocking;&lt;BR /&gt; i2cInterface.i2c_write = I2C_DRV_MasterSendDataBlocking;&lt;/P&gt;&lt;P&gt;accDev.i2c = &amp;amp;i2cInterface;&lt;BR /&gt; accDev.accel = &amp;amp;accDevice;&lt;/P&gt;&lt;P&gt;accDev.slave.baudRate_kbps = BOARD_ACCEL_BAUDRATE;&lt;BR /&gt; accDev.slave.address = BOARD_ACCEL_ADDR;&lt;BR /&gt; accDev.bus = BOARD_ACCEL_I2C_INSTANCE;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt; // Enable clock for PORTs, setup board clock source&lt;BR /&gt; hardware_init();&lt;/P&gt;&lt;P&gt;//*************************************************************&lt;BR /&gt; //************** CONFIGURAÇÕES PARA ACELERÔMETRO **************&lt;/P&gt;&lt;P&gt;// Accel device driver utilizes the OSA, so initialize it.&lt;BR /&gt; OSA_Init();&lt;/P&gt;&lt;P&gt;// Initialize the Accel.&lt;BR /&gt; accel_init(&amp;amp;accDev);&lt;/P&gt;&lt;P&gt;// Prepare memory for initialization.&lt;BR /&gt; memset(&amp;amp;driverInfo, 0, sizeof(driverInfo));&lt;/P&gt;&lt;P&gt;// Init TPM.&lt;BR /&gt; TPM_DRV_Init(0, &amp;amp;driverInfo);&lt;/P&gt;&lt;P&gt;// Set clock for TPM.&lt;BR /&gt; TPM_DRV_SetClock(0, kTpmClockSourceModuleClk, kTpmDividedBy128);&lt;/P&gt;&lt;P&gt;// Starts PWM.&lt;BR /&gt; TPM_DRV_PwmStart(0, &amp;amp;motor1, 0); //pino PTE24&lt;BR /&gt; TPM_DRV_PwmStart(0, &amp;amp;motor2, 2); //pino PTA5&lt;/P&gt;&lt;P&gt;// Start counting LPTMR&lt;BR /&gt; LPTMR_DRV_Start(LPTMR_INSTANCE);&lt;/P&gt;&lt;P&gt;&lt;BR /&gt; while(1)&lt;BR /&gt; {&lt;BR /&gt; if (tempoInterrupt == 1)&lt;BR /&gt; {&lt;BR /&gt; tempoInterrupt = 0;&lt;BR /&gt; // Wait 5 ms in between samples (accelerometer updates at 200Hz).&lt;BR /&gt; //OSA_TimeDelay(5);&lt;/P&gt;&lt;P&gt;// Get new accelerometer data.&lt;BR /&gt; accDev.accel-&amp;gt;accel_read_sensor_data(&amp;amp;accDev, &amp;amp;accelData);&lt;/P&gt;&lt;P&gt;// Get the X and Y data from the sensor data structure.fxos_data&lt;BR /&gt; xData = (int16_t) ((accelData.data.accelXMSB &amp;lt;&amp;lt; 8) | accelData.data.accelXLSB);&lt;BR /&gt; yData = (int16_t) ((accelData.data.accelYMSB &amp;lt;&amp;lt; 8) | accelData.data.accelYLSB);&lt;/P&gt;&lt;P&gt;// Convert raw data to angle (normalize to 0-90 degrees). No negative angles.&lt;BR /&gt; //xAngle = abs((int16_t)(xData * 0.011));&lt;BR /&gt; //yAngle = abs((int16_t)(yData * 0.011));&lt;BR /&gt; //xAngle = (int16_t) (xData * 0.011);&lt;BR /&gt; //yAngle = (int16_t) (yData * 0.011);&lt;/P&gt;&lt;P&gt;xAngle = (int16_t) (xData * 0.0055);&lt;BR /&gt; yAngle = (int16_t) (yData * 0.0055);&lt;/P&gt;&lt;P&gt;//Cálculos PID&lt;BR /&gt; erro = yAngle - SetPoint;&lt;/P&gt;&lt;P&gt;if (erro &amp;lt; 0)&lt;BR /&gt; ehnegativo = 1;&lt;BR /&gt; if ((erro &amp;lt; 0.5) &amp;amp;&amp;amp; (erro &amp;gt; -0.5))&lt;BR /&gt; erro = 0;&lt;/P&gt;&lt;P&gt;proporcional = KP * erro;&lt;BR /&gt; integral = integral + ((KI * (erro + erroAnterior) * (tAmost / 1000)) / 2);&lt;BR /&gt; derivativo = (((2 - (p * (tAmost / 1000))) * (derivativo)) + (2 * p * (tAmost / 1000) * KD * erro) - (2 * p * (tAmost / 1000) * KD * erroAnterior) / (2 + (p * (tAmost / 1000))));&lt;/P&gt;&lt;P&gt;PID = proporcional + integral + derivativo;&lt;/P&gt;&lt;P&gt;if (PID &amp;lt; 0)&lt;BR /&gt; PID = PID * (-1);&lt;/P&gt;&lt;P&gt;PWM = (5 * PID) / 100;&lt;/P&gt;&lt;P&gt;if (PWM &amp;gt; 10) // 10% = 2ms&lt;BR /&gt; PWM = 10;&lt;BR /&gt; else if (PWM &amp;lt; 5) // 5% = 1ms&lt;BR /&gt; PWM = 5;&lt;/P&gt;&lt;P&gt;if (ehnegativo == 1)&lt;BR /&gt; {&lt;BR /&gt; motor1.uDutyCyclePercent = 6.5 + PWM;&lt;BR /&gt; motor2.uDutyCyclePercent = 6.5 - PWM;&lt;BR /&gt; }&lt;BR /&gt; else&lt;BR /&gt; {&lt;BR /&gt; motor1.uDutyCyclePercent = 6.5 - PWM;&lt;BR /&gt; motor2.uDutyCyclePercent = 6.5 + PWM;&amp;nbsp;&lt;BR /&gt; }&lt;/P&gt;&lt;P&gt;erroAnterior = erro;&lt;BR /&gt; }&lt;BR /&gt; }&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I attached the main.c file to help you.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;My problem is, I can't change the duty cycle of the TPM. I start the PWM signal in "TPM_DRV_PwmStart(0, &amp;amp;motor1, 0)" outside the loop (while) and then, inside the loop, I tried to change de duty cycle with "motor1.uDutyCyclePercent = some value" but not worked. I tried also to stop the PWM and start again inside the loop, but still didn't work.&lt;/P&gt;&lt;P&gt;I tried everything, but the duty cycle of the PWM don't change. I tried to create a simple code, without PID calculations, but happened the same issue. The only way to change it is putting a value outside the loop, at the beginning of the code.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;How can I change it INSIDE the loop, constantly?&lt;/P&gt;&lt;P&gt;Thanks in advance.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 14 May 2019 23:23:45 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/How-to-change-duty-cycle-using-TPM/m-p/891608#M52692</guid>
      <dc:creator>nícolasludwig</dc:creator>
      <dc:date>2019-05-14T23:23:45Z</dc:date>
    </item>
    <item>
      <title>Re: How to change duty cycle using TPM?</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/How-to-change-duty-cycle-using-TPM/m-p/891609#M52693</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi &lt;A _jive_internal="true" data-content-finding="Community" data-userid="314952" data-username="nícolasludwig" href="https://community.nxp.com/people/nícolasludwig"&gt;Nícolas Ludwig&lt;/A&gt;,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; Your SDK code is really very old, please refer to our newest SDK code for FRDM-KL27, you can download it from this link:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; &lt;A class="link-titled" href="https://mcuxpresso.nxp.com/en/welcome" title="https://mcuxpresso.nxp.com/en/welcome"&gt;Welcome | MCUXpresso SDK Builder&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; Choose the board as FRDM-KL27, generate the code and download it.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; You can refer to this project:&lt;/P&gt;&lt;P&gt;SDK_2.5.0_FRDM-KL27Z\boards\frdmkl27z\driver_examples\tpm\simple_pwm&lt;/P&gt;&lt;P&gt;&amp;nbsp; About the TPM duty change, please also refer to the RM:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="pastedImage_4.png"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/81192iA3977B3967440918/image-size/large?v=v2&amp;amp;px=999" role="button" title="pastedImage_4.png" alt="pastedImage_4.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Wish it helps you!&lt;/P&gt;&lt;P&gt;If you still have question about it after you use the newest SDK code, please kindly let me know.&lt;/P&gt;&lt;P&gt;Please don't use the old SDK code again&lt;/P&gt;&lt;P&gt;Have a great day,&lt;BR /&gt;Kerry&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;-------------------------------------------------------------------------------&lt;BR /&gt;Note:&lt;BR /&gt;- If this post answers your question, please click the "Mark Correct" button. Thank you!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;- We are following threads for 7 weeks after the last post, later replies are ignored&lt;BR /&gt; Please open a new thread and refer to the closed one, if you have a related question at a later point in time.&lt;BR /&gt;-------------------------------------------------------------------------------&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 May 2019 07:50:22 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/How-to-change-duty-cycle-using-TPM/m-p/891609#M52693</guid>
      <dc:creator>kerryzhou</dc:creator>
      <dc:date>2019-05-15T07:50:22Z</dc:date>
    </item>
    <item>
      <title>Re: How to change duty cycle using TPM?</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/How-to-change-duty-cycle-using-TPM/m-p/891610#M52694</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello&amp;nbsp;&lt;A class="jx-jive-macro-user" href="https://community.nxp.com/people/kerryzhou"&gt;kerryzhou&lt;/A&gt;.&amp;nbsp;Thanks for answering!&lt;/P&gt;&lt;P&gt;I updated the SDK and opened the simple pwm project. It works, the duty cycle changes, but under some circumstances.&lt;/P&gt;&lt;P&gt;When I write in every cycle of the loop (while) to change the duty cycle for a SAME duty cycle (my test was always change to 10%), it screw up&amp;nbsp;all the signal. But, when I write the same thing with a delay, like near 1 second, it stays stable, always changing to 10%. With a few noises, but&amp;nbsp;despicables.&amp;nbsp;When I decrease the delay, the signal starts to be bad. It seems that in high frequencies of update, the&amp;nbsp;PWM signal goes very bad.&lt;/P&gt;&lt;P&gt;I attached three images, one the result of the signal updating with delay (the perfect PWM signal), other with some "lines" (that's the one with delay decreased) and other without any delay. Both codes were exactly the same, it only differs from the delay.&lt;/P&gt;&lt;P&gt;So, there's some explanation about this problem? It's normal? There's other way to keep the PWM signal perfect without delays?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 17 May 2019 01:12:51 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/How-to-change-duty-cycle-using-TPM/m-p/891610#M52694</guid>
      <dc:creator>nícolasludwig</dc:creator>
      <dc:date>2019-05-17T01:12:51Z</dc:date>
    </item>
    <item>
      <title>Re: How to change duty cycle using TPM?</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/How-to-change-duty-cycle-using-TPM/m-p/891611#M52695</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Nicolas Ludwig,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Do you mean, you delete the getchar code, then just modify the updatedDutycycle ?&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="pastedImage_1.png"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/81418iDB1F0C68B7CAE377/image-size/large?v=v2&amp;amp;px=999" role="button" title="pastedImage_1.png" alt="pastedImage_1.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; Is it right?&lt;/P&gt;&lt;P&gt;&amp;nbsp; If yes, you can't change it very quickly in the while(1), just as I told you in the previous reply:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="pastedImage_4.png"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/81465i8B08C59AC369B272/image-size/large?v=v2&amp;amp;px=999" role="button" title="pastedImage_4.png" alt="pastedImage_4.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;As you know, the while(1) runs very quickly, If you update the duty cycle in one PWM cycle, your output will have problems, it's totally caused by your code.&lt;/P&gt;&lt;P&gt;I don't know how you want to change the duty, when you want to change the duty, anyway, I think you won't change the duty a lot of time just in one PWM cycle.&lt;/P&gt;&lt;P&gt;You need to give an event to trigger the duty change things, instead of just always changes it in the while(1) directly.&lt;/P&gt;&lt;P&gt;take an example:&lt;/P&gt;&lt;P&gt;while(1)&lt;/P&gt;&lt;P&gt;(&lt;/P&gt;&lt;P&gt;&amp;nbsp; if(change duty flag==1)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; change the duty;&lt;/P&gt;&lt;P&gt;)&lt;/P&gt;&lt;P&gt;Now, you need to design your app, when you want to set change duty flag, and make sure it won't set just in one PWM cycle.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Wish it helps you!&lt;/P&gt;&lt;P&gt;If you still have question about it after you use the newest SDK code, please kindly let me know.&lt;/P&gt;&lt;P&gt;Please don't use the old SDK code again&lt;/P&gt;&lt;P&gt;Have a great day,&lt;BR /&gt;Kerry&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;-------------------------------------------------------------------------------&lt;BR /&gt;Note:&lt;BR /&gt;- If this post answers your question, please click the "Mark Correct" button. Thank you!&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;- We are following threads for 7 weeks after the last post, later replies are ignored&lt;BR /&gt; Please open a new thread and refer to the closed one, if you have a related question at a later point in time.&lt;BR /&gt;-------------------------------------------------------------------------------&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 17 May 2019 05:59:32 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/How-to-change-duty-cycle-using-TPM/m-p/891611#M52695</guid>
      <dc:creator>kerryzhou</dc:creator>
      <dc:date>2019-05-17T05:59:32Z</dc:date>
    </item>
    <item>
      <title>Re: How to change duty cycle using TPM?</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/How-to-change-duty-cycle-using-TPM/m-p/891612#M52696</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi&amp;nbsp;&lt;A class="jx-jive-macro-user" href="https://community.nxp.com/people/kerryzhou"&gt;kerryzhou&lt;/A&gt;. Yes, that's what I did, just to test. I know that while(1) runs very quickly, but also I'll need to update duty cycle between 5~10ms, because I'll implement PID control on my project, and I need some sampling time. With this sample time I'm getting problems. The only way to prevent the signal issues is increasing the sampling time?&lt;/P&gt;&lt;P&gt;Thanks for helping me.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 17 May 2019 12:44:15 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/How-to-change-duty-cycle-using-TPM/m-p/891612#M52696</guid>
      <dc:creator>nícolasludwig</dc:creator>
      <dc:date>2019-05-17T12:44:15Z</dc:date>
    </item>
    <item>
      <title>Re: How to change duty cycle using TPM?</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/How-to-change-duty-cycle-using-TPM/m-p/891613#M52697</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I think I understood what you said. My PWM frequency is 50Hz, so the PWM period is 20ms. My sample time must be greater than 20ms, right? Seems obvious, but I didn't realize it earlier.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 17 May 2019 15:24:54 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/How-to-change-duty-cycle-using-TPM/m-p/891613#M52697</guid>
      <dc:creator>nícolasludwig</dc:creator>
      <dc:date>2019-05-17T15:24:54Z</dc:date>
    </item>
    <item>
      <title>Re: How to change duty cycle using TPM?</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/How-to-change-duty-cycle-using-TPM/m-p/891614#M52698</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi &lt;SPAN class=""&gt;&lt;A _jive_internal="true" data-content-finding="Community" data-userid="314952" data-username="nícolasludwig" href="https://community.nxp.com/people/nícolasludwig"&gt;Nícolas Ludwig&lt;/A&gt;&lt;/SPAN&gt;,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; Clever!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; Yes, that's what I want to say, it should be larger than 20ms, if you ware using the PWM period is 20ms.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; Please try it on your side.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Wish it helps you!&lt;/P&gt;&lt;P&gt;If you still have question about it, please kindly let me know.&lt;/P&gt;&lt;P&gt;Have a great day,&lt;BR /&gt;Kerry&lt;/P&gt;&lt;P style="min- padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;-------------------------------------------------------------------------------&lt;BR /&gt;Note:&lt;BR /&gt;- If this post answers your question, please click the "Mark Correct" button. Thank you!&lt;/P&gt;&lt;P style="min- padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;- We are following threads for 7 weeks after the last post, later replies are ignored&lt;BR /&gt; Please open a new thread and refer to the closed one, if you have a related question at a later point in time.&lt;BR /&gt;-------------------------------------------------------------------------------&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 20 May 2019 08:08:09 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/How-to-change-duty-cycle-using-TPM/m-p/891614#M52698</guid>
      <dc:creator>kerryzhou</dc:creator>
      <dc:date>2019-05-20T08:08:09Z</dc:date>
    </item>
    <item>
      <title>Re: How to change duty cycle using TPM?</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/How-to-change-duty-cycle-using-TPM/m-p/891615#M52699</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi&amp;nbsp;&lt;A class="jx-jive-macro-user" href="https://community.nxp.com/people/kerryzhou"&gt;kerryzhou&lt;/A&gt;.&lt;/P&gt;&lt;P&gt;It worked. But it works properly without the accelerometer code. When I comment the lines, and sampling the code in a period of 20ms~100ms, it works very well, without noises at the signal. But with all the code working&amp;nbsp;together, the signal gets some noises,&amp;nbsp;including sometimes changing the frequency. It just works well with a sampling time &amp;gt;300ms.&lt;/P&gt;&lt;P&gt;Do you know if have something to do in this case?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you for helping me until now.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 21 May 2019 00:28:06 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/How-to-change-duty-cycle-using-TPM/m-p/891615#M52699</guid>
      <dc:creator>nícolasludwig</dc:creator>
      <dc:date>2019-05-21T00:28:06Z</dc:date>
    </item>
    <item>
      <title>Re: How to change duty cycle using TPM?</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/How-to-change-duty-cycle-using-TPM/m-p/891616#M52700</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi &lt;SPAN class=""&gt;&lt;A _jive_internal="true" class="" data-content-finding="Community" data-userid="314952" data-username="nícolasludwig" href="https://community.nxp.com/people/nícolasludwig"&gt;Nícolas Ludwig&lt;/A&gt;&lt;/SPAN&gt;,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; Thank you for your updated information.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; From your description, after you combine with the accelerometer code, then your PWM signal get some noises, so the problem still in the code structure side, how did you add your accelerometer code? Whether the accelermometer code will cause the TPM duty change time point smaller than one PWM period?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Have a great day,&lt;BR /&gt;Kerry&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;-------------------------------------------------------------------------------&lt;BR /&gt;Note:&lt;BR /&gt;- If this post answers your question, please click the "Mark Correct" button. Thank you!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;- We are following threads for 7 weeks after the last post, later replies are ignored&lt;BR /&gt; Please open a new thread and refer to the closed one, if you have a related question at a later point in time.&lt;BR /&gt;-------------------------------------------------------------------------------&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 21 May 2019 02:33:24 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/How-to-change-duty-cycle-using-TPM/m-p/891616#M52700</guid>
      <dc:creator>kerryzhou</dc:creator>
      <dc:date>2019-05-21T02:33:24Z</dc:date>
    </item>
  </channel>
</rss>

