6 PWM Generation in MKV31F512VLL12

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

6 PWM Generation in MKV31F512VLL12

Jump to solution
1,101 Views
HARINI_T
Contributor I

Hi all, 

I have been working in the generation of 6 PWM pulses from FTM0 module in MKV31F512VLL12. I am facing issues in duty cycle updation. The value of duty cycle is not getting updated inside the while loop and instead takes the value of duty cycle from the initialization. i.e. The duty cycle value is not getting updated even redefined and remains to be the same value, which was given during initialization. 

The parameters defined are: 

1. Edge Aligned PWM

2. Frequency - 10kHz

3. No complementary mode used

4. duty cycle will be varying based on the status of 3 GPIO pins. I have attached the image of the expected PWM outputs in the 6 channels for the input from the Hall transducer, which is read via the GPIO pins. 

Input 1Input 2Input 3  PWMo/p  
GPIOB 1GPIOB 10GPIOB 2Channel 0Channel 1Channel 2Channel 4Channel 5Channel 6
0011DisabledDisabledDisabledDisabled1
010Disabled1Disabled1DisabledDisabled
011Disabled1DisabledDisabledDisabled1
100DisabledDisabled1Disabled1Disabled
1011DisabledDisabledDisabled1Disabled
110DisabledDisabled11DisabledDisabled


@EdwinHz  Can you please help me with this? Anticipating your response. Thank you!

Labels (1)
0 Kudos
1 Solution
1,084 Views
EdwinHz
NXP TechSupport
NXP TechSupport

Hi @HARINI_T!

The issue you are experiencing is due to a synchronization mistake. Let me explain:

 

You initialize the FTM with the default configuration using:

 FTM_GetDefaultConfig(&ftminitialisation);

This configuration is set up with a software trigger to update the registers:

/* Software trigger will be used to update registers */
    config->pwmSyncMode = (uint32_t)kFTM_SoftwareTrigger;

Therefore, you need to provide the trigger in your code in order to update the registers.

This is because several FTM registers (including FTMx_CnV) have a buffer and cannot be directly written to when addressed by the software in order to ensure a properly synced write of the register:

“In output modes, writing to a CnV register latches the value into a buffer. A CnV register is updated with the value of its write buffer according to Registers updated from write buffers.” (p. 849 of RM).

When using:

 FTM_UpdatePwmDutycycle(BOARD_FTM_BASEADDR, FTM_Channel_0, 0U, g_d0);

you are only writing the new value on the buffer, so you need to create the software trigger to write the value that is currently stored in the buffer, into the actual register. This can be done with the following function:

FTM_SetSoftwareTrigger(BOARD_FTM_BASEADDR, true);

 

For more information about the buffer and register synchronization requirements, please see Chapter 38.3.11 “Synchronization (FTMx_SYNC)” of the Reference Manual.

 

Always a pleasure to help,

Edwin.

View solution in original post

3 Replies
1,067 Views
HARINI_T
Contributor I

Hi @EdwinHz,

I am now facing few issues if the code is inside the while loop. Without the code inside the while loop, the output is obtained as per the table I have mentioned in my previous query. But if I put the code inside the while loop, I am unable to generate the desired signal.  

1. The PWM output is not achieved from the desired pins instead I am observing a logic high output without any PWM pulses.

2. And the rest of the 4 pins are producing PWM pulses with a random dutycycle value, which I havent initialized anywhere in my code. All the 4 pins are producing the same dutycycle of 20 percent and frequency is around 100kHz, which is also not set by me. I have attached the images of the output generated herewith. PFA. 

Figure 1. 3.3V output from the pins which needs to produce PWM pulses. 
Figure 2. PWM pulses from the undesired pins having 20 percent dutycycle and 100kHz frequency. 

0 Kudos
1,085 Views
EdwinHz
NXP TechSupport
NXP TechSupport

Hi @HARINI_T!

The issue you are experiencing is due to a synchronization mistake. Let me explain:

 

You initialize the FTM with the default configuration using:

 FTM_GetDefaultConfig(&ftminitialisation);

This configuration is set up with a software trigger to update the registers:

/* Software trigger will be used to update registers */
    config->pwmSyncMode = (uint32_t)kFTM_SoftwareTrigger;

Therefore, you need to provide the trigger in your code in order to update the registers.

This is because several FTM registers (including FTMx_CnV) have a buffer and cannot be directly written to when addressed by the software in order to ensure a properly synced write of the register:

“In output modes, writing to a CnV register latches the value into a buffer. A CnV register is updated with the value of its write buffer according to Registers updated from write buffers.” (p. 849 of RM).

When using:

 FTM_UpdatePwmDutycycle(BOARD_FTM_BASEADDR, FTM_Channel_0, 0U, g_d0);

you are only writing the new value on the buffer, so you need to create the software trigger to write the value that is currently stored in the buffer, into the actual register. This can be done with the following function:

FTM_SetSoftwareTrigger(BOARD_FTM_BASEADDR, true);

 

For more information about the buffer and register synchronization requirements, please see Chapter 38.3.11 “Synchronization (FTMx_SYNC)” of the Reference Manual.

 

Always a pleasure to help,

Edwin.

1,075 Views
HARINI_T
Contributor I

Hi Edwin,

Thanks a lot for the spontaneous reply @EdwinHz. It greatly helped me in debugging the program. I tried your method and was very happy to obtain the output. Thanks again!  


0 Kudos