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);
}