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.

CCS/RM48L952: PWM and rti combining

Part Number: RM48L952

Tool/software: Code Composer Studio

Hi,

I have separately generated PWM using HET with desired frequency and duty. and also separately worked with the RTI and both are working fine. but when i try to merge these to based on my need, HET is not working when i place the HET function into RTI function. Please help me to short it out.

the HET is getting toggled for every 20ms once. i need the HET to be in ON condition for 2 seconds in RTI function (T1 - 100*20ms = 2 seconds) .

rti compare 20ms once

Source code:

#include "sys_common.h"
#include "system.h"
#include "adc.h"
#include "sci.h"
#include "gio.h"
#include "math.h"
#include "het.h"
#include "rti.h"


float o;
char y[20];


int T1 = 100;
int T2 = 50;
int T= 200;

int i1 = 0, j1 = 0, k1 = 0;

float a;


float vt,ti,sf,fio2,tp,rr, peep;
float ps;
float ti1,tp1; //calculated inspiration for valve actuation
float vte = 0; //Exhalation flow sensor
float afr, o2fr, dt1, dt2;
float dt3 = 0;


int b;


char s[4];
static unsigned char i[6];
static unsigned char *j=i;

static unsigned char command;
hetSIGNAL_t setup_pwm;

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

void wait(uint32 time);

void main(void)
{

rtiInit();
gioInit();
gioSetDirection(gioPORTB, 1);
sciInit();
hetInit();
adcInit();
adcStartConversion(adcREG1,adcGROUP1);
sciReceive(scilinREG,1,(unsigned char*)&command);
j=i;

b = 1;
_enable_IRQ();

while(1)
{
hetInit();

if(b == 1)
{
//hetInit();

rtiEnableNotification(rtiNOTIFICATION_COMPARE0);


rtiStartCounter(rtiCOUNTER_BLOCK0);
}

}
}

void rtiNotification(uint32 notification)
{


if (i1 < T1 && T1 > 0)
{

hetInit();
float ff = 100.0;
pwmStart(hetRAM1, pwm0);
setup_pwm.period=(float64)1e6/1000;
float DuttyC2= ff/100;
uint32 Dutcycle2=setup_pwm.period*DuttyC2;
uint32 Porcentdutty2=DuttyC2*100;
pwmSetSignal(hetRAM1,pwm0,setup_pwm);
pwmSetDuty_full(hetRAM1,pwm0,Porcentdutty2,Dutcycle2);

o = i1; //Mean presure
sciSend(scilinREG,1,(unsigned char*)"#");
y[0]=((int)o/100)%10 + 0x30;
y[1]=((int)o/10)%10 + 0x30;
y[2]=((int)o)%10 + 0x30;
sciSend(scilinREG,4,(unsigned char*)&y);
sciSend(scilinREG,1,(unsigned char*)"f");
sciSend(scilinREG,2,(unsigned char*)"\n\r");

i1++;
}
else if( i1 >= T1 && j1 < T2 && T2 > 0)
{

pwmStop(hetRAM1, pwm0);

o = j1; //Mean presure
sciSend(scilinREG,1,(unsigned char*)"!");
y[0]=((int)o/100)%10 + 0x30;
y[1]=((int)o/10)%10 + 0x30;
y[2]=((int)o)%10 + 0x30;
sciSend(scilinREG,4,(unsigned char*)&y);
sciSend(scilinREG,1,(unsigned char*)"g");
sciSend(scilinREG,2,(unsigned char*)"\n\r");
j1++;

}

else if (i1 >= T1 && j1>= T2 && k1 < T && T > 0)
{

pwmStop(hetRAM1, pwm0);

o = k1; //Mean presure
sciSend(scilinREG,1,(unsigned char*)"&");
y[0]=((int)o/100)%10 + 0x30;
y[1]=((int)o/10)%10 + 0x30;
y[2]=((int)o)%10 + 0x30;
sciSend(scilinREG,4,(unsigned char*)&y);
sciSend(scilinREG,1,(unsigned char*)"h");
sciSend(scilinREG,2,(unsigned char*)"\n\r");
k1++;

}
else if( i1 >= T1 && j1>= T2 && k1 >= T)
{
i1 = 0;
j1 = 0;
k1 = 0;
}

}


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 = (uint32) 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;

}


void wait(uint32 time)
{
while(time){time--;};
}
void esmGroup1Notification(int bit)
{
return;
}
void esmGroup2Notification(int bit)
{
return;
}


void sciNotification(sciBASE_t *sci,unsigned flags)
{

if(i[0]=='r' | i[0]=='i' | i[0]=='p' | i[0]=='f' | i[0]=='v' | i[0]=='a'| i[0]=='b'| i[0]=='m'| i[0]=='d')
j++;

if(j==&i[6])
{
j=i;

switch(i[0])
{
case 'r':
rr=( (i[2] - 0x30)*100 + (i[3] - 0x30)*10 + (i[4] - 0x30));
//rr=12;
break;

case 'i':
ti=( (i[4] - 0x30)*10 + (i[5] - 0x30) );
ti=ti/10;
break;

case 'p':
tp=( (i[3] - 0x30)*10 + (i[4] - 0x30) );
break;

case 'f':
fio2=( (i[2] - 0x30)*100 + (i[3] - 0x30)*10 + (i[4] - 0x30));
break;

case 'v':
vt=( (i[1] - 0x30)*1000 + (i[2] - 0x30)*100 + (i[3] - 0x30)*10 + (i[4] - 0x30));
break;

case 'b':
peep=((i[3] - 0x30)*10 + (i[4] - 0x30));
break;
case 'a':
b=((i[1] - 0x30)*10 + (i[2] - 0x30));
break;
case 'm':
ps=((i[3] - 0x30)*10 + (i[4] - 0x30));
break;

case 'd':
a = ((i[1] - 0x30)*10 + (i[2] - 0x30));
break;
default:
break;
}
i[0]='k';
}
sciReceive(sci,1,(unsigned char*)j);
}

  • Hello Manjunathan,

    The primary source of your issue is probably calling het_init too much and in the wrong locations. het_init will reset the het each time it is called so calling within the RTI notification routine will cause it to be reset on each RTI interrupt (20ms is what I believe you have set as your compare value time?). het_init should be called before entering your while(1) loop in main so it is initialized once at startup only.

    Also, I noticed a few other places in your code that are questionable in regard to their functionality/intent.

    Manjunathan K said:
    if(i[0]=='r' | i[0]=='i' | i[0]=='p' | i[0]=='f' | i[0]=='v' | i[0]=='a'| i[0]=='b'| i[0]=='m'| i[0]=='d')
    j++;

    Do you really intend to bitwise OR the result of each of these equality tests? Should these be logical OR '||' instead?

    Manjunathan K said:
    if(j==&i[6])

    Do you really intend to check the content of 'j' for equality to the address of the 7th element of the array i?

  • Thank you, Mr.Chuck Davenport, 

    Initially, i have called the het_init before while (1).

    but the HET is not generating PWM if I didn't call the het_init inside the while(1). If i din't call het inside while (1) the HET is not working

    Also, I noticed a few other places in your code that are questionable in regard to their functionality/intent.

    Manjunathan K
    if(i[0]=='r' | i[0]=='i' | i[0]=='p' | i[0]=='f' | i[0]=='v' | i[0]=='a'| i[0]=='b'| i[0]=='m'| i[0]=='d')
    j++;
     
    I am using the above logic for serial recive data which starts (Start byte) with any one of the above mentioned character

    Do you really intend to bitwise OR the result of each of these equality tests? Should these be logical OR '||' instead?

    Manjunathan K
    if(j==&i[6])

    Yes this is logical OR (I need OR logic to be performed here)

    Do you really intend to check the content of 'j' for equality to the address of the 7th element of the array i?

     

    Yes, I have fixed size of serial data i[6], after 6th character in the serially received data comes by next serial conntent. thats why i have written logic like this. I think there are much simpler ways. but serial receive works fine for me, so i let the function as it is.

     

     Please ignore the void sciNotification(sciBASE_t *sci,unsigned flags), it is working fine for me

     

    The problem for me is with the below functions . NOTE - Both functions are working fine seperately

     

    void rtiNotification(uint32 notification). 

    {float ff = 100.0;

    pwmStart(hetRAM1, pwm0);
    setup_pwm.period=(float64)1e6/1000;
    float DuttyC2= ff/100;
    uint32 Dutcycle2=setup_pwm.period*DuttyC2;
    uint32 Porcentdutty2=DuttyC2*100;
    pwmSetSignal(hetRAM1,pwm0,setup_pwm);
    pwmSetDuty_full(hetRAM1,pwm0,Porcentdutty2,Dutcycle2);

    }

    Void main()

    while(1)
    {
    hetInit();

    if(b == 1)
    {

    rtiEnableNotification(rtiNOTIFICATION_COMPARE0);


    rtiStartCounter(rtiCOUNTER_BLOCK0);
    }

     

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

    when i call the het generate function into rtiNotification(uint32 notification) function, it is getting executed only once  (the frequency of pwm signal is  1khz- and duty is 50%) for 20ms rti it should be executed 20 times (20 cycles- 20 ON and 20 OFF), instead it is getting executed only once.

    If the explanation is not clear, i will again explain in a document. Help me short out the issue.

  • Hello Manjunathan,

    You also call het_init within the RTI notification function. This shouldn't be necessary.

    Have you confirmed that you are getting your RTI interrupts as you expect? If you can zip a simple project with the issue and attach it, I can take a closer look.
  • Hi, Mr.Chuck Davenport,

    I have attached the project file that will send characters

    1. '#f' once through serial communication for 100 times of 20ms time delay each 

    2. '!g' once through serial communication for 50 times of 20ms time delay each and 

    3. '&h' through serial communication for 200 times of 20ms time delay each.

    the above logic will be continuously executed in while loop through RTI function.

    This is how I confirmed that my rti is working fine.1362.rtisci07z.rar

  • Hi, Mr. Chuck Davenport,

    I have attached the PWM combined rti program zip file. please help me to sort out the problem.

    0842.clrti01z.rar