完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
电子发烧友论坛|
大家好,我需要做一个PIC18F822微控制器的项目来控制和调节QuANSER耦合坦克模块。这不是解决家庭作业的要求。好,所以我做了什么,直到现在:我有PICDEM PIC18演示板,我使用电位器作为参考值(设置多少%的坦克将被填充)我使用端口RF1和RF4连接来自坦克1和坦克2I的水平传感器,使用端口RA2 t输出PWM信号在我当前状态下它做什么:读出电位器值并将相同的值设置到PWM你可以选择哪个传感器是活动的(tank1或tank2传感器)如果传感器值低于电位器设置的值,PWM工作在与如果传感器值等于或大于由电位器设置的值,那么PWM被设置为0,电机停止。到目前为止,我所做的是非常低效的,但它尊重我的论文题目,我不想这样,我需要一些提示来做以下工作。基于一些公式,根据期望的水平和值调节发动机的ROT/min。我有一些代码,我知道它可以把数值结果(例如在Volts中——知道我们在这个微控制器上有3.8V)转换为二进制,以实时建立PWM控制。此外,我不会张贴整个源代码,我不想它被那些验证论文的真实性机器人索引,我会张贴部分代码和/或截图。谢谢!
以上来自于百度翻译 以下为原文 Good day guys, I need to do a project on the PIC18F8722 microcontroller to control and regulate the Quanser Coupled Tanks module. This is not a homework solving request. Good, so what did I do until now:
Somehow I need some live PWM control based on some formula that regulates the rot/min of the engine based on the desired level and value. I have some code that I know it works to convert a numeric result (as in Volts for example - knowing that we have 3.8V on this microcontroller) to binary to set up the PWM control in realtime. Also, I won't post the whole source code, I don't want it to be indexed by those authenticity bots that verify the thesis, I will post part of the code and/or screenshots. Thank you! |
|
相关推荐
2个回答
|
|
|
0111000;// 90% PWM IF(ADCRESUT2≫=ADCREST){CCPR1L= 0B000 010100;// 5% PWM },否则(ADCReult2和gt;=204){CCPR1L= 0B0100000;//80% PWM IF(ADCRESUT2≫=ADCREST){CCPR1L= 0B000 010100;//5% PWM }}否则(ADCReult2和gt;=306){CCP1L= 0B000 011000;//70% PW)。更新:IF(ADCRESUT2&GT=102){CCPR1L= 0B.B000 010100;// 5% PWM },否则(ADCRESUT2和gt;=408){CCPR1L= 0B11110000;// 60% PWM IF(ADCRESUT2>=ADCREST){CCPR1L= 0B000 010100;//5% PWM };否则(ADCRESTUT2≫=510){CCPR1L= 0B11001000;//50% PWM IF(ADCRESUT2>=ADCREST){CCPR1L= 0B000 010100;//5% P)M if(ADCRESUT2&GT=ADCREST){CCPR1L= 0{ADCResult2>==612){CCPR1L=0b10100000{CCPR1L=0b10100000;//40%PWM如果(ADCResult2>_==ADCR结果结果){CCPR1L=0b000000000000000000000000000BCRCRCR结果2>==612;//40%PWM如果(ADCResult2>==ADCResult2>;//40%PWM如果//40%PWM如果(ADCR结果结果结果2>==ADCR结果结果){CCPR1L=0b10b10b20202020BCR结果结果;//30%PWM如果;//30%PWM如果(ADCR如果(ADCResult2>=816){CCPR1L=0b01010000;//20%如果(ADCResult2>;=ADCResult2>==ADCResult2>;=ADCResult2>;//5%PWM}}如果(CCPR1L=0b000000000000万{CCPR1L=0b000000000000000000000000万{CCPR1L=0b0000000000000000000000001000;//5%PWM}}}否则如果(ADCResult2>==918){CCCResult2> 918{CCPR1L=0b000000000000000000000000000000000000000000000000100b001011000100010001000100010001000100010001000100010001000;//10 00010100;//5%PWM}TRISAbits.RA2=0;这是正确的吗?ADCRESTR2是从传感器接收到的结果,其中ADCResult是电位器所必须设定的值。
以上来自于百度翻译 以下为原文 UPDATE: if (ADCResult2 >= 102){ CCPR1L=0b01101000; //90%PWM if (ADCResult2 >= ADCResult){ CCPR1L=0b00010100; //5%PWM } } else if(ADCResult2 >= 204){ CCPR1L=0b01000000; //80%PWM if (ADCResult2 >= ADCResult){ CCPR1L=0b00010100; //5%PWM } } else if(ADCResult2 >= 306){ CCPR1L=0b00011000; //70%PWM if (ADCResult2 >= ADCResult){ CCPR1L=0b00010100; //5%PWM } } else if(ADCResult2 >= 408){ CCPR1L=0b11110000; //60%PWM if (ADCResult2 >= ADCResult){ CCPR1L=0b00010100; //5%PWM } } else if(ADCResult2 >= 510){ CCPR1L=0b11001000; //50%PWM if (ADCResult2 >= ADCResult){ CCPR1L=0b00010100; //5%PWM } } else if(ADCResult2 >= 612){ CCPR1L=0b10100000; //40%PWM if (ADCResult2 >= ADCResult){ CCPR1L=0b00010100; //5%PWM } } else if(ADCResult2 >= 714){ CCPR1L=0b01111000; //30%PWM if (ADCResult2 >= ADCResult){ CCPR1L=0b00010100; //5%PWM } } else if(ADCResult2 >= 816){ CCPR1L=0b01010000; //20%PWM if (ADCResult2 >= ADCResult){ CCPR1L=0b00010100; //5%PWM } } else if(ADCResult2 >= 918){ CCPR1L=0b00101000; //10%PWM if (ADCResult2 >= ADCResult){ CCPR1L=0b00010100; //5%PWM } } else if(ADCResult2 >= 1020){ CCPR1L=0b00010100; //5%PWM } TRISAbits.RA2=0; Is this correct? ADCResult2 is the result received from the sensor where ADCResult is the value that I must set by the potentiometer. |
|
|
|
|
|
你好,罗伯特。是的,你说得对,这正是我第一次尝试解决这个问题。这是我想要的电平(例如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. |
|
|
|
|
只有小组成员才能发言,加入小组>>
MPLAB X IDE V6.25版本怎么对bootloader和应用程序进行烧录
490 浏览 0 评论
5806 浏览 9 评论
2346 浏览 8 评论
2234 浏览 10 评论
请问是否能把一个ADC值转换成两个字节用来设置PWM占空比?
3541 浏览 3 评论
1146浏览 1评论
有偿咨询,关于MPLAB X IPE烧录PIC32MX所遇到的问题
1114浏览 1评论
我是Microchip 的代理商,有PIC16F1829T-I/SS 技术问题可以咨询我,微信:A-chip-Ti
883浏览 1评论
MPLAB X IDE V6.25版本怎么对bootloader和应用程序进行烧录
490浏览 0评论
/9
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2025-12-9 18:51 , Processed in 0.817220 second(s), Total 74, Slave 57 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191

淘帖
1523