This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

[RM48] generating floating point duty cycle issue



Hi,

I tried to generate PWM signal with floating point duty cycle. but it is not working. the floating point is getting truncated because uint32 duty declaration.

how to solve this problem. Please support to short out the problem. for the reference i have attached the project also.

#include "sys_common.h"

#include "het.h"

static const float s_het1pwmPolarity[8U] = { 3U, 3U, 3U, 3U, 3U, 3U, 3U, 3U, };

void pwmSetDuty_full(hetRAMBASE_t * hetRAM, uint32 pwm, uint32 fuse_pwmDuty,

uint32 pwmdutty);

hetSIGNAL_t setup_pwm;

void main(void)

{

hetInit();

setup_pwm.period = (float64)1e6/5000;//5khz

uint32 Dutcycle = setup_pwm.period*0.085;

uint32 Porcentdutty=0.085*100;

pwmSetSignal(hetRAM1, pwm0, setup_pwm);

pwmSetDuty_full(hetRAM1, pwm0, Porcentdutty, Dutcycle);

pwmStart(hetRAM1, pwm0);

while(1);

}

void pwmSetDuty_full(hetRAMBASE_t * hetRAM, uint32 pwm, uint32 fuse_pwmDuty,

uint32 pwmdutty) {

uint32 action;

uint32 pwmPolarity = 0U;

uint32 var;

if (hetRAM == hetRAM1) {

pwmPolarity = s_het1pwmPolarity[pwm];

}

if (fuse_pwmDuty == 0U) {

action = (pwmPolarity == 3U) ? 0U : 2U;

} else if (fuse_pwmDuty >= 100U) {

action = (pwmPolarity == 3U) ? 2U : 0U;

} else {

action = pwmPolarity;

}

//var = (uint32) pwmdutty * 1.2613; //((pwmPeriod * pwmDuty) / 100U)

var = (float64) pwmdutty * 0.86;

hetRAM->Instruction[(pwm << 1U) + 41U].Control = ((hetRAM->Instruction[(pwm

<< 1U) + 41U].Control) & (~(uint32) (0x00000018U)))

| (action << 3U);

hetRAM->Instruction[(pwm << 1U) + 41U].Data = (var << 7U) + 128U;

}

4747.dty1.rar

#include "sys_common.h"#include "het.h"

static const float s_het1pwmPolarity[8U] = { 3U, 3U, 3U, 3U, 3U, 3U, 3U, 3U, };void pwmSetDuty_full(hetRAMBASE_t * hetRAM, uint32 pwm, uint32 fuse_pwmDuty, uint32 pwmdutty);

hetSIGNAL_t setup_pwm;
void main(void){ hetInit();
setup_pwm.period = (float64)1e6/5000;//5khz uint32 Dutcycle = setup_pwm.period*0.085; uint32 Porcentdutty=0.085*100; pwmSetSignal(hetRAM1, pwm0, setup_pwm); pwmSetDuty_full(hetRAM1, pwm0, Porcentdutty, Dutcycle); pwmStart(hetRAM1, pwm0);
while(1);}
void pwmSetDuty_full(hetRAMBASE_t * hetRAM, uint32 pwm, uint32 fuse_pwmDuty, uint32 pwmdutty) { uint32 action; uint32 pwmPolarity = 0U; uint32 var;
if (hetRAM == hetRAM1) { pwmPolarity = s_het1pwmPolarity[pwm]; }
if (fuse_pwmDuty == 0U) { action = (pwmPolarity == 3U) ? 0U : 2U; } else if (fuse_pwmDuty >= 100U) { action = (pwmPolarity == 3U) ? 2U : 0U; } else { action = pwmPolarity; } //var = (uint32) pwmdutty * 1.2613; //((pwmPeriod * pwmDuty) / 100U) var = (float64) pwmdutty * 0.86; hetRAM->Instruction[(pwm << 1U) + 41U].Control = ((hetRAM->Instruction[(pwm << 1U) + 41U].Control) & (~(uint32) (0x00000018U))) | (action << 3U); hetRAM->Instruction[(pwm << 1U) + 41U].Data = (var << 7U) + 128U;
}