完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
我刚开始使用MCC,所以我可能做错了什么,但是我做了一个简单的测试项目,在PIC16F1778上测试10位PWM3和16位增强的PWM5。当我打开管脚管理器时,PWM只能分配给RA0-RA5,而不能分配给RC0-7,尽管文档表明可以使用PORTC(但是PORTB不能)。因此,我把RAW2和PWM5上的PWM3设置为100 kHz到RA1上的100 kHz。逻辑分析器显示RA2上的预期波形,但不显示RA1。下面是生成的代码:根据文档,这似乎是正确的。
以上来自于百度翻译 以下为原文 I have only just now started using the MCC, so I might be doing something wrong, but I made a simple test project to test the 10 bit PWM3 and the 16 bit enhanced PWM5, on the PIC16F1778. When I open the pin manager, the PWMs can be assigned only to RA0-RA5, and not to RC0-7, although the documentation indicates that PORTC can be used (but PORTB cannot). So I set PWM3 to 100 kHz on RA2 and PWM5 to 100 kHz on RA1. The logic analyzer shows the expected waveform on RA2 but not on RA1. Here is the generated code: /** TRISx registers */ TRISE = 0x08; TRISA = 0xF9; TRISB = 0xFF; TRISC = 0xF9; /** ANSELx registers */ ANSELC = 0xF4; ANSELB = 0x3F; ANSELA = 0x3F; bool state = GIE; GIE = 0; PPSLOCK = 0x55; PPSLOCK = 0xAA; PPSLOCKbits.PPSLOCKED = 0x00; // unlock PPS RA1PPSbits.RA1PPS = 0x19; //RA1->PWM3:PWM3OUT; T2INPPSbits.T2INPPS = 0x13; //RC3->TMR2:T2IN; RA2PPSbits.RA2PPS = 0x1D; //RA2->PWM5:PWM5OUT; PPSLOCK = 0x55; PPSLOCK = 0xAA; PPSLOCKbits.PPSLOCKED = 0x01; // lock PPS GIE = state; and void PWM5_Initialize(void) { // set the PWM5 to the options selected in the User Interface //PHIE disabled; DCIE disabled; OFIE disabled; PRIE disabled; PWM5INTE = 0x00; //PHIF cleared; OFIF cleared; DCIF cleared; PRIF cleared; PWM5INTF = 0x00; //PS No_Prescalar; CS FOSC; PWM5CLKCON = 0x00; //LDS LD5_trigger; LDT disabled; LDA load; PWM5LDCON = 0x80; //OFM independent_run; OFS OF5_match; OFO match_incrementing; PWM5OFCON = 0x00; //PWM5PHH 0; PWM5PHH = 0x00; //PWM5PHL 0; PWM5PHL = 0x00; //PWM5DCH 0; PWM5DCH = 0x00; //PWM5DCL 74; PWM5DCL = 0x4A; //PWM5PRH 0; PWM5PRH = 0x00; //PWM5PRL 147; PWM5PRL = 0x93; //PWM5OFH 0; PWM5OFH = 0x00; //PWM5OFL 73; PWM5OFL = 0x49; //PWM5TMRH 0; PWM5TMRH = 0x00; //PWM5TMRL 0; PWM5TMRL = 0x00; //MODE standard_PWM; POL active_hi; EN enabled; PWM5CON = 0x80; } void PWM5_Start(void) { PWM5CONbits.EN = 1; } void PWM5_Stop(void) { PWM5CONbits.EN = 0; } That seems to be correct according to the documentation |
|
相关推荐
6个回答
|
|
什么版本的MPLABX?你为什么确定这不是模拟器问题?你确认你有最新的MCC了吗?
以上来自于百度翻译 以下为原文 What version of MPLabX? Why are you sure it is not a simulator issue? Did you verify you have the latest MCC? |
|
|
|
通过添加以下代码,我验证了PWM5正在运行:所以我假设模拟器没有正常工作。然而,我也尝试去探测PORTAbits的状态,但这并不起作用。我认为还可以读取引脚的状态。我通过观察RC0的状态确认它正在运行。它主要跟随PWM输出,但是在过渡中有延迟,并且忽略一些脉冲。这就是我所期望的。[编辑]我使用MPLABX版本3.45和XC8版本1.33。它是MCC版本3.22.2。
以上来自于百度翻译 以下为原文 I verified that PWM5 is running by adding the following code: while (1) { if(PWM5CONbits.OUT==1) { PWMstate=1; } if(PWM5CONbits.OUT==0) { PWMstate=0; } LATCbits.LATC0 = PWMstate; // Add your application code } So I assume the simulator is not working properly. However, I also tried to detect the state of PORTAbits and that did not work. I think it is also possible to read the state of a pin. I confirmed that it is running by observing the state of RC0. It mostly follows the PWM output but has delays in transition and misses some pulses. And that is what I would expect. [edit] I'm using MPLABX Version 3.45 and XC8 version 1.33. It is MCC Version 3.26.2. |
|
|
|
试试MPLABX V3.50,看看它里面的模拟器是否更好。编译器是不太可能的。它必须有一个坏的注册地址或一些奇怪的东西。我想你检查了勘误表。
以上来自于百度翻译 以下为原文 Try MPLabX v3.50 and see if the simulator in it is any better. It is less likely the compiler. It would have to have a bad register address or something weird. And I assume you checked the errata. |
|
|
|
代码中的注释称为PWM3-&GT RA1和PWM5->RA2。
以上来自于百度翻译 以下为原文 RA1PPSbits.RA1PPS = 0x19; //RA1->PWM3:PWM3OUT; T2INPPSbits.T2INPPS = 0x13; //RC3->TMR2:T2IN; RA2PPSbits.RA2PPS = 0x1D; //RA2->PWM5:PWM5OUT; The comments in the code say PWM3 -> RA1 and PWM5 -> RA2 |
|
|
|
是的,你是对的。我查看了管脚管理器网格,选择的管脚的浅绿色背景没有显示,以及取消选择的管脚的黄色。
以上来自于百度翻译 以下为原文 Yes, you are right. I was looking at the pin manager grid and the light green background for the selected pins does not show up as well as the yellow for the deselected pins. |
|
|
|
我手动将PWM3设置为RC1,将PWM5设置为RC2:现在逻辑分析器显示RC1上的活动,但不显示RC2。然而,它不是一个好的PWM信号。
以上来自于百度翻译 以下为原文 I manually set PWM3 to RC1 and PWM5 to RC2: RC1PPSbits.RC1PPS = 0x19; //RC1 was RA1->PWM3:PWM3OUT; T2INPPSbits.T2INPPS = 0x13; //RC3->TMR2:T2IN; RC2PPSbits.RC2PPS = 0x1D; //RC2 was RA2->PWM5:PWM5OUT; Now the logic analyzer shows activity on RC1 but not RC2. However it is not a good PWM signal. |
|
|
|
只有小组成员才能发言,加入小组>>
5161 浏览 9 评论
1999 浏览 8 评论
1928 浏览 10 评论
请问是否能把一个ADC值转换成两个字节用来设置PWM占空比?
3171 浏览 3 评论
请问电源和晶体值之间有什么关系吗?PIC在正常条件下运行4MHz需要多少电压?
2226 浏览 5 评论
731浏览 1评论
613浏览 1评论
有偿咨询,关于MPLAB X IPE烧录PIC32MX所遇到的问题
503浏览 1评论
PIC Kit3出现目标设备ID(00000000)与预期的设备ID(02c20000)不匹配。是什么原因
629浏览 0评论
527浏览 0评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-11-22 23:59 , Processed in 1.262069 second(s), Total 87, Slave 70 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号