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.
工具/软件:Code Composer Studio
您好!
我使用 具有所需频率和占空比的 HET 单独生成 PWM。 并且 还单独与 RTI 配合使用、两者都正常工作。 但是、当我根据我的需要尝试将这些合并到中时、当我将 HET 函数放入 RTI 函数时、HET 不起作用。 请帮助我将其简短描述。
HET 每20ms 切换一次。 我需要 HET 在 RTI 函数中处于 ON 状态2秒(T1 - 100*20ms = 2秒)。
RTI 将20ms 进行一次比较
源代码:
#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;
字符 y[20];
int t1 = 100;
int t2 = 50;
int T = 200;
int i1 = 0、J1 = 0、K1 = 0;
浮点 A;
浮点 VT、ti、sf、fiO2、tp、rr、peep;
浮点 ps;
浮动 ti1、TP1;//计算的阀驱动吸气
浮点 VTE = 0;//呼气流量传感器
float AFR、o2fr、dt1、dt2;
float Dt3 = 0;
int b;
字符 s[4];
静态无符号字符 i[6];
静态无符号字符*j=i;
static unsigned char 命令;
hetSIGNAL_t setup_pwm;
静态常量 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 fuser_pwmDuty、
uint32 pwmdutty);
空等待(uint32时间);
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();
如果(b = 1)
{
//hetInit();
rtiEnableNotification (rtiNOTIFICATION_COMPARE0);
rtiStartCounter (rtiCOUNTER_BLOCK0);
}
}
}
void rtiNotification (uint32通知)
{
如果(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 Portcentdutty2=DuttyC2*100;
pwmSetSignal (hetRAM1、pwm0、setup_PWM);
pwmSetDuty_full (hetRAM1、pwm0、Portcentdutty2、Dutcycle2);
O = i1;//平均值预置
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\n");
I1++;
}
否则、如果(i1 >= T1 && J1 < T2 && T2 > 0)
{
pwmStop (hetRAM1、pwm0);
O = J1;//平均值预置
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\n");
J1++;
}
否则、如果(i1 >= T1 && J1>= T2 && K1 < T && T > 0)
{
pwmStop (hetRAM1、pwm0);
O = K1;//平均预置
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\n");
K1+;
}
否则 if (i1 >= T1 &J1>= T2 &K1 >= T)
{
I1 = 0;
J1 = 0;
K1 = 0;
}
}
void pwmSetDuty_full (hetRAMBASE_t * hetRAM、uint32 PWM、uint32 fuser_pwmDuty、
uint32 pwmdutty){
uint32行动;
uint32 pwmPolarity = 0U;
uint32 var;
if (hetRAM == hetRAM1){
pwmPolarity = s_het1pwmPolarity[PWM];
}
if (fuse pwmDuty = 0U){
操作=(pwmPolarity = 3U)? 0U:2U;
}否则、如果(fuse _pwmDuty >= 100U){
操作=(pwmPolarity = 3U)? 2U:0U;
}否则{
操作= pwmPolarity;
}
//var =(uint32) pwmdutty * 1.2613;//(((pwmPeriod * pwmDuty)/ 100U)
var =(uint32) pwmdutty * 0.86;
hetRAM->指令[(PWM << 1U)+ 41U].Control =(hetRAM->指令[(PWM
<< 1U)+ 41U].Control)&(~(uint32)(0x00000018U))
|(操作<< 3U);
hetRAM->指令[(PWM << 1U)+ 41U].Data =(var << 7U)+ 128U;
}
空等待(UINT32时间)
{
while (time){time--;};
}
void esmGroup1通知(int 位)
{
返回;
}
void esmGroup2Notification (int 位)
{
返回;
}
void sciNotification (sciBASE-t * sci、无符号标志)
{
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;
开关(I[0])
{
案例"R":
r=((i[2]- 0x30)*100 +(i[3]- 0x30)*10 +(i[4]- 0x30));
//rr=12;
中断;
案例"I":
TI=((i[4]-0x30)*10+(i[5]-0x30));
TI=ti/10;
中断;
案例"p":
TP=((I[3]- 0x30)*10 +(I[4]- 0x30));
中断;
案例'f':
FiO2=((I[2]- 0x30)*100 +(I[3]- 0x30)*10 +(I[4]- 0x30));
中断;
案例"v":
VT=((I[1]- 0x30)*1000 +(I[2]- 0x30)*100 +(I[3]- 0x30)*10 +(I[4]- 0x30));
中断;
情况"b":
peep=((i[3]- 0x30)*10 +(i[4]- 0x30));
中断;
案例"A":
B=((I[1]- 0x30)*10 +(I[2]- 0x30);
中断;
案例"m":
PS=((I[3]- 0x30)*10 +(I[4]- 0x30);
中断;
案例"d":
A =((I[1]- 0x30)*10 +(I[2]- 0x30);
中断;
默认值:
中断;
}
i[0]='k';
}
sciReceive (sci、1、(unsigned char*) j);
}
Manjunathan、您好!
问题的主要原因可能是调用 het_init 过多、并且位置错误。 每次调用 HET_INIT 时、HET_INIT 都会重置 HET、因此在 RTI 通知例程中调用会导致每个 RTI 中断上重置 HET (我认为您已将20ms 设置为比较值时间?)。 在 main 中进入 while (1)循环之前、应调用 het_init、以便仅在启动时初始化一次。
此外、我注意到您的代码中还有一些其他地方在功能/意图方面存在问题。
[引用 user="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|[0]|i]='d]='0|[0]|[]|[]=']=']|[0]|[0]=']|=']|=']|[0]=']|[]|
J++;[/引号]
您是否真的打算按位或每个等效测试的结果? 这些应该是逻辑的、还是'||'?
[引用 user="Manjunathan K"] if (j=&i[6])
您是否确实打算检查'j'的内容是否与数组 i 的第7个元素的地址相等?
谢谢 Chuck Davenport 先生、
最初、我在 while (1)之前调用了 het_init。
但是、 如果我没有在 while (1)内调用 het_init、HET 不会生成 PWM。 如果我在(1) HET 不工作时未调用 HET
此外、我注意到您的代码中还有一些其他地方在功能/意图方面存在问题。
Manjunathan Kif (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++;我将上述逻辑用于以上述任一字符开头的串行接收数据(起始字节)
您是否真的打算按位或每个等效测试的结果? 这些应该是逻辑的、还是'||'?
Manjunathan Kif (j=&i[6])
是这是逻辑或(我需要 在此处执行或逻辑)
您是否确实打算检查'j'的内容是否与数组 i 的第7个元素的地址相等?
是的、串行数据的大小固定为 i[6]、在串行接收到的数据中的第6个字符之后、下一个串行连接。 这就是 我编写这样的逻辑的原因。 我认为有很多更简单的方法。 但串行接收对我来说很好、所以我让函数按原样使用。
请忽略 void sciNotification (sciBASE-t * sci、unsigned flags)、它对我来说工作正常
我遇到的问题是以下函数。 注-两个功能单独工作
void rtiNotification (uint32通知)。
{float ff = 100.0;
pwmStart (hetRAM1、pwm0);
setup_pwm.period=(float64) 1e6/1000;
float DuttyC2= ff/100;
uint32 Dutcycle2=setup_pwm.period* DuttyC2;
uint32 Portcentdutty2=DuttyC2*100;
pwmSetSignal (hetRAM1、pwm0、setup_PWM);
pwmSetDuty_full (hetRAM1、pwm0、Portcentdutty2、Dutcycle2);
}
void main()
while (1)
{
hetInit();
如果(b = 1)
{
rtiEnableNotification (rtiNOTIFICATION_COMPARE0);
rtiStartCounter (rtiCOUNTER_BLOCK0);
}
void pwmSetDuty_full (hetRAMBASE_t * hetRAM、uint32 PWM、uint32 fuser_pwmDuty、
uint32 pwmdutty)
当我将 HET Generate 函数调用到 rtiNotification (UINT32通知)函数中时、它只执行一次 (PWM 信号的频率为 1kHz -且占空比为50%) 20ms RTI 应该执行20次(20个周期- 20个周期- 20个周期-开和20个周期)、 而是仅执行一次。
如果解释不清楚,我会在一份文件中再次解释。 帮助我简要说明问题。
大家好、 Chuck Davenport 先生、
我已附加 PWM 组合 RTI 程序 zip 文件。 请帮助我解决问题。