你好,罗伯特。是的,你说得对,这正是我第一次尝试解决这个问题。这是我想要的电平(例如60%),这是由传感器读出的电平(当然低于60%),当电平达到60时,PWM被设置为零,如果电平低于预设值,则它返回到100%发动机节气门。但是那并不太好,因为开关可能损坏电机(老师这样建议我,他部分正确),所以我又拍了一张照片。我正在为传感器读取的每个值设置不同的功率设置(例如,0-10%-100%PWM,20-30%-90%PWM……)等等)。我尝试过这个,因为现在我们确信我们的坦克不会溢出,因为停止的命令可能会延迟。好的,现在当我们达到我们期望的水平时,PWM开关到5%以补偿通过井底从水箱流出的水,我将改变或补偿5%到我们实际使用的水量(可能是4%,可能是6%,直到我把它和真实交易联系起来)。这是我的计划,我今晚尝试,并模拟它做我想要的。我不想使用PID(是的,这是我们使用的最佳解决方案,因为我不知道如何实现PID,我不知道如何解释PID,也不知道如何根据变量计算PID)。我试图避免先进的控制解决方案,如P,I,PI,PD,PID的我怎么能!如果你有一个更好的想法如何控制它没有“长期损害”,请让我知道。这是我在模拟中实际工作的演示代码。如果(ADCResult2>==0&安培;ADCResult2&ADCResult2&ADCResult2<=204){CCPR1L=0b01111101;CCPR1L=0b01111101;//100%PWM如果(ADCResult2>ADCResult2>ADCResult2<=306306;//100%PWM如果{CCPR1L=0b01110000;//90%PWM如果(AD如果(ADCResult2>ADCResult2>;=408){CCPR1L=0b00000000110;//5%PWM}}{CCPR1L=0b00000110;//5%PWM}否则{CCPR1L=0b00000000110;//5%PWM}}否则(ADCResult2>_306&__&__;ADCResult2&;ADCResult2<;=408){CCPR1L=0b01100100100100100000000000000100;//80%PWM如果(ADCR结果2>;//80%PWM如果(ADCResult2>;== 408&&ADCResult2<=510){CCPR1L=0b01010111;//70%PWM,如果 (ADCResult2 >= ADCResult){ CCPR1L=0b00000110; //5%PWM }}else if(ADCResult2 >= 510 && ADCResult2 <= 612){CCPR1L=0b01001011; //60%PWM if (ADCResult2 >= ADCResult){ CCPR1L=0b00000110; //5%PWM }}else if(ADCResult2 >= 612 && ADCResult2 <=714){CCPR1L=0b00111110; //50%PW如果(ADCResult2>==ADCRes.){CCPR1L=0b00000000110;//5%PWM}}如果(ADCResult2>_=714&_&_;ADCResult2&放大器;ADCResult2&>ADCResult2>==ADCResult2>==ADCRes.){CCPR1L=0b000000000000000000000110;//5%PWM}}否则(如果CCPR1L=0b000000000000000000000000000000000000000000000000000000110110110110CCPR1L=CCPR1L=CCPR1L=CCPR1L esult2>=816&ADCResult2<=918){CCPR1L=0b00100101;//如果(ADCResult2>==ADCRes.){CCPR1L=0b00000000110;//5%PWM}}}如果(ADCResult2>__=918&_____安培;ADCResult2&&&ADCResult2&&00000000000000011001;//20%PWM如果(ADCResult2>ADCResult2>==ADCRCResult2>;=ADCRCRCResultADCResult2>;//20%PWM如果){CCPR1L=0b00000000000000000000000000000000000000000000000ADCResult2>=1020){CCPR1L=0b01111101;//5%PWM}TRISAbits.RA2=0;Bes不要客气,Theo。
以上来自于百度翻译
以下为原文
Hello Robert.
Yes, you are right, exactly that was my first try to solve this problem. Here is the level I want (eg. 60%) here is the level that is read by the sensor (of course under 60%) and when the level reaches 60 the PWM is set to zero, if the level is under the preset value it turns back to 100% engine throttle. But that was not quite ok since on's and off's could damage the motor (I was advised this way by the teacher, and he is partially right) so I took another shot.
I am setting a different power setting for each value read by the sensor (eg. for 0-10% - 100% PWM, 20-30% - 90% PWM... etc.). I tried this since now we're sure that our tank will not overflow because the command to stop could come with a delay. Good, now when we reach our desired level the PWM switches to 5% to compensate the water that's going out of the tank through the bottom hole and I'm going to change/compensate that 5% to what we use in reality (maybe 4%, maybe 6%, I can't know that until I hook this up to the real deal).
Now that is my plan that I tried tonight and simulated it does what I want. I don't want to use a PID (and yes, that is our best solution to use because I don't know how to implement one, I don't know how to explain one, and I don't know how to calculate one based on my variables). I am trying to avoid advanced control solutions like P, I, PI, PD, PID's how I can!
If you have a better idea on how to control it without "long term damage" please let me know. This is my demo code that actually worked in simulation.
if (ADCResult2 >= 0 && ADCResult2 <= 204){
CCPR1L=0b01111101; //100%PWM
if (ADCResult2 >= ADCResult){
CCPR1L=0b00000110; //5%PWM
}
}
else if(ADCResult2 >= 204 && ADCResult2 <= 306){
CCPR1L=0b01110000; //90%PWM
if (ADCResult2 >= ADCResult){
CCPR1L=0b00000110; //5%PWM
}
}
else if(ADCResult2 >= 306 && ADCResult2 <=408){
CCPR1L=0b01100100; //80%PWM
if (ADCResult2 >= ADCResult){
CCPR1L=0b00000110; //5%PWM
}
}
else if(ADCResult2 >= 408 && ADCResult2 <= 510){
CCPR1L=0b01010111; //70%PWM
if (ADCResult2 >= ADCResult){
CCPR1L=0b00000110; //5%PWM
}
}
else if(ADCResult2 >= 510 && ADCResult2 <= 612){
CCPR1L=0b01001011; //60%PWM
if (ADCResult2 >= ADCResult){
CCPR1L=0b00000110; //5%PWM
}
}
else if(ADCResult2 >= 612 && ADCResult2 <=714){
CCPR1L=0b00111110; //50%PWM
if (ADCResult2 >= ADCResult){
CCPR1L=0b00000110; //5%PWM
}
}
else if(ADCResult2 >= 714 && ADCResult2 <= 816){
CCPR1L=0b00110010; //40%PWM
if (ADCResult2 >= ADCResult){
CCPR1L=0b00000110; //5%PWM
}
}
else if(ADCResult2 >= 816 && ADCResult2 <= 918){
CCPR1L=0b00100101; //30%PWM
if (ADCResult2 >= ADCResult){
CCPR1L=0b00000110; //5%PWM
}
}
else if(ADCResult2 >= 918 && ADCResult2 <= 1020){
CCPR1L=0b00011001; //20%PWM
if (ADCResult2 >= ADCResult){
CCPR1L=0b00000110; //5%PWM
}
}
else if(ADCResult2 >= 1020){
CCPR1L=0b01111101; //5%PWM
}
TRISAbits.RA2=0;
Best regards,
Theo.