Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
lock attach
Attachments are accessible only for community members.
robs1
Level 4
Level 4
100 sign-ins 50 replies posted First solution authored

Hi, I have to create a code that realize a pmw with its inverse (100 kHz of frequency) with dead time 100 ns.

I attached my code that gives me on the oscilloscope a 5 Hz pwm and I don't know why.

I don't understand the meaning of tOn and I don't know how to set the duty cycle of pwm. I need to use this .h file.

Can you help me to find errors in my code? 

I saw that counters of atom arrive to count until very  high value, but I set the timer to trigger the reset of the counters at 500 ticks ... maybe the timer is not linked to atom? 

Thank you in advance.

0 Likes
1 Solution
Giraffe1492
Level 5
Level 5
25 sign-ins 25 likes received 10 solutions authored

It seems that you are trying to generate a PWM signal with a frequency of 100 kHz and its inverse with a dead time of 100 ns using the AURIX™ microcontroller. To help you with your code, let's first clarify some concepts:


tOn is the time duration for which the PWM signal is in the \"ON\" state (high) during one period. The duty cycle of the PWM signal is the ratio of tOn to the total period of the PWM signal. To set the duty cycle, you need to adjust the tOn value accordingly.


Now, let's address the issues in your code:


1. To achieve a 100 kHz frequency, you need to set the period of the PWM signal to 10 µs (1/100 kHz). Make sure you have set the correct timer configuration to achieve this period.


2. To set the duty cycle, you need to adjust the tOn value. For example, if you want a 50% duty cycle, you need to set tOn to half of the total period (5 µs in this case).


3. To generate the inverse PWM signal with a dead time of 100 ns, you can use another PWM channel with the same period and duty cycle but with a phase shift equal to the dead time. In this case, the phase shift should be 100 ns.


4. Make sure that the timer is properly linked to the PWM channels (ATOM) and that the timer is configured to reset the counters at the correct value (500 ticks in your case).


Without seeing your code, it's difficult to pinpoint the exact errors. However, you can refer to the https://www.infineon.com/cms/en/product/power/ac-dc-power-conversion/ac-dc-pwm-pfc-controller/pwm-ff...
https://www.infineon.com/cms/en/product/promopages/makeradar/Iframes/LearnRADAR/RadarEquation/
https://www.infineon.com/cms/en/product/power/ac-dc-power-conversion/ac-dc-pwm-pfc-controller/pwm-ff...
https://www.infineon.com/cms/en/product/promopages/makeradar/makeradar-school/programming-tutorial/
https://www.infineon.com/cms/en/product/microcontroller/32-bit-industrial-microcontroller-based-on-a...

 

View solution in original post

0 Likes
8 Replies
Giraffe1492
Level 5
Level 5
25 sign-ins 25 likes received 10 solutions authored

It seems that you are trying to generate a PWM signal with a frequency of 100 kHz and its inverse with a dead time of 100 ns using the AURIX™ microcontroller. To help you with your code, let's first clarify some concepts:


tOn is the time duration for which the PWM signal is in the \"ON\" state (high) during one period. The duty cycle of the PWM signal is the ratio of tOn to the total period of the PWM signal. To set the duty cycle, you need to adjust the tOn value accordingly.


Now, let's address the issues in your code:


1. To achieve a 100 kHz frequency, you need to set the period of the PWM signal to 10 µs (1/100 kHz). Make sure you have set the correct timer configuration to achieve this period.


2. To set the duty cycle, you need to adjust the tOn value. For example, if you want a 50% duty cycle, you need to set tOn to half of the total period (5 µs in this case).


3. To generate the inverse PWM signal with a dead time of 100 ns, you can use another PWM channel with the same period and duty cycle but with a phase shift equal to the dead time. In this case, the phase shift should be 100 ns.


4. Make sure that the timer is properly linked to the PWM channels (ATOM) and that the timer is configured to reset the counters at the correct value (500 ticks in your case).


Without seeing your code, it's difficult to pinpoint the exact errors. However, you can refer to the https://www.infineon.com/cms/en/product/power/ac-dc-power-conversion/ac-dc-pwm-pfc-controller/pwm-ff...
https://www.infineon.com/cms/en/product/promopages/makeradar/Iframes/LearnRADAR/RadarEquation/
https://www.infineon.com/cms/en/product/power/ac-dc-power-conversion/ac-dc-pwm-pfc-controller/pwm-ff...
https://www.infineon.com/cms/en/product/promopages/makeradar/makeradar-school/programming-tutorial/
https://www.infineon.com/cms/en/product/microcontroller/32-bit-industrial-microcontroller-based-on-a...

 

0 Likes

Hi! Thank you very much. 
so for dead time is not enough to set dead time settings but also shift ? 
In general if I want a shift between pwms (not between pwm and its inverse) how can I do it? So i mean between two ccx pin. 

for the code I have attached it in my questions all files! 
maybe you can see them? 

0 Likes

I can't open links that you posted because tells me "no page founded".

I use this istructions but the counters are not reset by the timer...


#include "pwmatomhl.h"

#include "Ifx_Types.h"
#include "IfxGtm_Atom_Pwm.h"
#include "IfxGtm_Atom_Timer.h"
#include "IfxStdIf_Timer.h"
#include "IfxGtm_Atom_PwmHl.h"
#include "Ifx_TypesReg.h"


volatile static Ifx_GTM* const gtm_ptr = &MODULE_GTM;

#define PIN_CLOCK IfxGtm_ATOM2_1_TOUT19_P00_10_OUT //timer atom and channel
#define PWM_FREQUENCY 100000 //100kHz

//Structure to configure the timer to reset atom counters
IfxGtm_Atom_Timer_Config g_timerConfig; /* Timer configuration structure */
IfxGtm_Atom_Timer g_timerDriver; /* Timer Driver structure */

void ATomPwmprova(){


IfxGtm_enable(&MODULE_GTM); /* Enable GTM */
IfxGtm_Cmu_setClkFrequency(&MODULE_GTM, IfxGtm_Cmu_Clk_0, 100000000); // Set the CMU clock 0 frequency - ATOM
IfxGtm_Cmu_enableClocks(&MODULE_GTM, IFXGTM_CMU_CLKEN_CLK0); // Enable the CMU clock 0 - ATOM


//Configuration of the timer reset of atom counters

IfxGtm_Atom_Timer_initConfig(&g_timerConfig,&MODULE_GTM);//To set default parameters for timer
g_timerConfig.atom = PIN_CLOCK.atom;
g_timerConfig.timerChannel = PIN_CLOCK.channel;
g_timerConfig.triggerOut = &PIN_CLOCK;
g_timerConfig.base.frequency = 10000; // CM0: clock reset
g_timerConfig.base.countDir = IfxStdIf_Timer_CountDir_up;
// g_timerConfig.base.countDir = IfxStdIf_Timer_CountDir_upAndDown;
g_timerConfig.base.trigger.enabled = TRUE;
g_timerConfig.base.trigger.outputEnabled = TRUE;
g_timerConfig.base.trigger.triggerPoint = 500; // CM1: triggera a mezzo periodo
g_timerConfig.initPins = TRUE;
g_timerConfig.clock=IfxGtm_Cmu_Clk_0;

// g_timerConfig.base.minResolution = (1.0 / g_timerConfig.base.frequency) / 1000;
// g_timerConfig.base.trigger.risingEdgeAtPeriod = TRUE;


//IfxGtm_Atom_Timer_setFrequency(&g_timerDriver, 100000);

IfxGtm_Atom_Timer_init(&g_timerDriver, &g_timerConfig);
IfxGtm_Atom_Timer_run(&g_timerDriver);

 

// create ATOM configuration

IfxGtm_Atom_ToutMapP ccx[] = {&IfxGtm_ATOM0_0_TOUT48_P22_1_OUT};//output pin pwm
IfxGtm_Atom_ToutMapP coutx[] = {&IfxGtm_ATOM0_1_TOUT47_P22_0_OUT};//output pin pwm inverse


IfxGtm_Atom_PwmHl_Config pwmHlConfig;
IfxGtm_Atom_PwmHl g_pwm;
IfxStdIf_PwmHl pwmhl;


IfxGtm_Atom_PwmHl_initConfig(&pwmHlConfig); //For default configurations

//For configurations

pwmHlConfig.timer=&g_timerDriver;

//BASE DA CONTINUARE forse non c'è bisogno
pwmHlConfig.base.outputMode = IfxPort_OutputMode_pushPull;
pwmHlConfig.base.channelCount=1;
pwmHlConfig.base.deadtime=0;

pwmHlConfig.ccx = ccx;
pwmHlConfig.coutx = coutx;

pwmHlConfig.base.emergencyEnabled = FALSE;
pwmHlConfig.base.ccxActiveState = Ifx_ActiveState_high;
pwmHlConfig.base.coutxActiveState = Ifx_ActiveState_low;
pwmHlConfig.base.ccxOutputEnabled=TRUE;
pwmHlConfig.base.coutxOutputEnabled=TRUE;
pwmHlConfig.initPins=TRUE;
// pwmHlConfig.atom=IfxGtm_Atom_0;
// initialize the ATOM
IfxGtm_Atom_PwmHl_init(&g_pwm, &pwmHlConfig);
IfxGtm_Atom_PwmHl_stdIfPwmHlInit(&pwmhl, &g_pwm);

 

// IfxGtm_Atom_Timer_run(&g_timerDriver);

 

IfxStdIf_Timer* timer = IfxStdIf_PwmHl_getTimer(&pwmhl);
Ifx_TimerValue onTime[1]; // assume configured for 1 HL channel

onTime[0] = 200; //dovrebbe essere in ticks
// onTime[1] = 20;


IfxGtm_Atom_PwmHl_setMode(&g_pwm, Ifx_Pwm_Mode_centerAligned);
IfxStdIf_Timer_disableUpdate(timer);
IfxStdIf_Timer_setPeriod(timer, 1000);
IfxStdIf_PwmHl_setOnTime(&pwmhl, onTime);
IfxStdIf_Timer_applyUpdate(timer);

}

 

 

 

 

Which is the error???

0 Likes
Di_W
Moderator
Moderator
Moderator
1000 replies posted 250 solutions authored 100 likes received

https://github.com/Infineon/AURIX_code_examples/blob/master/code_examples/GTM_ATOM_PWM_1_KIT_TC397_T...

Starting from the above code snippet, the corresponding .c file contains definitions for the LED pin used for PWM output, the clock frequency, the PWM period for the ATOM, and the PWM duty cycle step.

0 Likes
robs1
Level 4
Level 4
100 sign-ins 50 replies posted First solution authored

Thank you but I saw this example months ago, now I need to use the "IfxGtm_Atom_PwmHl.h" so to set timer and do shifts and dead time between PWMs. 

Nothing about that? 

I saw an example in Github with "IfxGtm_Atom_PwmHl.h" but my code doesn't work because timer not reset the counter! Can you help me with my error?

my code is above

0 Likes
robs1
Level 4
Level 4
100 sign-ins 50 replies posted First solution authored

I need to use "IfxGtm_Atom_PwmHl.h", I have already seen that example 

0 Likes
Di_W
Moderator
Moderator
Moderator
1000 replies posted 250 solutions authored 100 likes received

robs1, have you resolved your issue?

robs1
Level 4
Level 4
100 sign-ins 50 replies posted First solution authored

hi, yes i solved, the problem was that the timer must be of atom0 too.

Now I would like to have updown counters but it seems that a delay is present between channels, maybe I have to write in a different order the istruction of set of updown and run, I don't know

0 Likes