完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
电子发烧友论坛|
我生产的基于C18的代码工作得很好。在转换为XC8 1.43之后,PWM功能停止工作。其他一切都有效。我比较了代码,在运行时捕获SFR,但是找不到罪魁祸首。有人有什么建议吗?下面是主要的配置代码。C18基和XC8基是完全相同的:…..定义LCDBKBLUT T6CONtiTS。TMR6on on定义LCDYBKLITE TIIS TrISABITITS。TISISA0定义BuZiPin LababITIt。LATA1定义BuZY-CTR T4CONTITS。TMR4ON定义BuZY-CrrTr3TrISABITS。TrISA1…//VistueStase=配置时间。R4CCP3 PWM为蜂鸣器,用于蜂鸣器,=PIR3BITS。TMR4IF=0;/ /清除溢出标志PSTR2CONC= 0B000 000 01;/ /选择PWM通道A,PxA(电源断电)RPOR1=22;/ /指派RP1到功能22(CCP3/P3A,PWM输出)PR4= 0x0B11111111;//PWM周期=[PRX+10]·4:(1 /16MHz)·(预分频)(976)(HZ)CCPR3L=0;/PWM占空比=0% CCP3CON=0B000 000 1100;T4CONN=0 B000 000 011;/PrimCale 16,定时器使能CCTPTMRS0=0B0100000;//ECCP3使用Time3(捕获/比较)和Time4(PWM)//Eclipse } =配置LCD背光灯的Time6CCP2 PWM。R2CONN=0B000 000 01;//选择PWM信道A,PxA(上电缺省)RPOR0=18;/ /分配RP0至函数18(CCP2/2A,PWM输出)PR6= 0x0B11111001;/PWM周期=[PRX+1 ]·4(1 / 16MHz)·(预分频)(40Hz)CCPR2L= 0B10101110;//PWM占空比(CCPRXL:CCPXCON<5:4&GT)·(1/16MHz)·Prescale(70%)CCP2CON=0B0111100;/ /启用CCP2上的PWM,单输出T6CON=0B000 000 101;//预分频器4,使定时器CCTPMRS0=0B000 010000;//ECCP2使用Time3(捕获/比较)和Time6(PWM)…LCDY-BKLITY-TrIS=0;BuZY-CrTrTrIS=0;…
以上来自于百度翻译 以下为原文 My production C18-based code works perfectly. After I converted to XC8 1.43, PWM function stops working. Everything else works. I have compared code, captured SFR in run time, but couldn't find the culprit. Does anyone have any suggestion? Below are the major configuring code. C18-based and XC8-base are exact the same as below: ... #define LCD_BKLIGHT T6CONbits.TMR6ON #define LCD_BKLIGHT_TRIS TRISAbits.TRISA0 #define BUZ_PIN LATAbits.LATA1 #define BUZ_CTR T4CONbits.TMR4ON #define BUZ_CTR_TRIS TRISAbits.TRISA1 ... //====== Configuring Timer4 CCP3 PWM for buzzer ===================== PIR3bits.TMR4IF = 0;// clear overflow flag PSTR2CON = 0b00000001; // select PWM channel A, PxA (power-on default) RPOR1 = 22; // assign RP1 to function 22 (CCP3/P3A, PWM Output) PR4 = 0x0b11111111; // PWM Period= [PRx+1]•4•(1/16MHz)•(Prescale) (976Hz) CCPR3L = 0; // PWM duty=0% CCP3CON = 0b00001100; T4CON = 0b00000111; // prescale 16, timer is enable CCPTMRS0 |= 0b01000000; // ECCP3 uses Timer3 (capture/compare)and Timer4 (PWM) //====== Configuring Timer6 CCP2 PWM for LCD backlight ============= PIR5bits.TMR6IF = 0; // clear overflow flag PSTR2CON = 0b00000001; // select PWM channel A, PxA (power-on default) RPOR0 = 18; // assign RP0 to function 18 (CCP2/P2A, PWM Output) PR6 = 0x0b11111001; // PWM Period= [PRx+1]•4•(1/16MHz)•(Prescale) (4000Hz) CCPR2L = 0b10101110; // PWM duty= (CCPRxL:CCPxCON<5:4>)•(1/16MHz)•Prescale (70%) CCP2CON = 0b00111100; // Enable PWM on CCP2, single output T6CON = 0b00000101; // prescale 4, enable timer CCPTMRS0 |= 0b00010000; // ECCP2 uses Timer3 (capture/compare)and Timer6 (PWM) ... LCD_BKLIGHT_TRIS = 0; BUZ_CTR_TRIS = 0; ... |
|
相关推荐
19个回答
|
|
|
|
|
|
|
|
|
你好,杰姆斯,你在MPLAX X下编译吗?这个问题也可能在其他地方…你能检查一下你是否使用C18项目的标准链接器脚本或者是否已经修改了?当做
以上来自于百度翻译 以下为原文 Hi James, Do you compile both under MPLAB X ? The issue could also be elsewhere...Can you please check if you use a standard linker script with the C18 project or if it has been modified ? Regards |
|
|
|
|
|
它是SPIC18F47 J13,它们都是在MPLABX V3.65下编译的。一个使用C18 V3.47,其他使用XC8 V1.43。它是标准C18。您想检查PROJ属性中的特定字段吗?
以上来自于百度翻译 以下为原文 It's PIC18F47J13. They're both compiled under MPLABX v3.65. One uses C18 v3.47, other uses XC8 v1.43. it's standard C18. What specific field in Proj Property do you want to check? |
|
|
|
|
|
除了使用PWM的蜂鸣器之外,我删除了XC8代码中的所有其他功能。这个问题仍然存在,我把简化后的XC8代码转换成C18。蜂鸣器再次工作。在简化的XC8代码中,不管XC8优化是ON还是OFF都存在问题。正在验证计时器运行。Buzzer pin被正确驱动的ON/OFF验证。PWM波形没有被输出到引脚。我花了更多的时间调试这个,并且一直在等待MC做它的一部分。
以上来自于百度翻译 以下为原文 I removed all other functionalities in XC8 code, except the buzzer using PWM. the issue still exists. I converted the reduced XC8 code back to C18. The buzzer works again. In the reduced XC8 code, issue exists regardless XC8 optimization on or off. Timer is verified running. Buzzer pin is verified driven on/off correctly. The PWM wave form is not put out to the pin. I went extra miles to debug this, and have been waiting for MC doing its part. |
|
|
|
|
|
PR4= 0x0B11111111;PR6= 0x0B11111001;这些是什么?
以上来自于百度翻译 以下为原文 PR4 = 0x0b11111111; PR6 = 0x0b11111001; What are these? |
|
|
|
|
|
PR4:Time4期寄存器PR6:Time6期寄存器
以上来自于百度翻译 以下为原文 PR4: Timer4 Period Register PR6: Timer6 Period Register |
|
|
|
|
|
|
|
|
|
|
|
HIPR4: Time4期注册PR6:Time6期注册。我很确定我们这里有一个bug。您期望在PR4/5寄存器中有什么值?“0x”前缀是十六进制常量,但那些似乎是二进制的,在这种情况下,它们应该用“0B”HiHouthOrdJorde前缀。
以上来自于百度翻译 以下为原文 Hi PR4: Timer4 Period Register PR6: Timer6 Period Register I'm pretty sure we have a bug here. What values do you expect to be oaded in the PR4/5 registers? The "0x" prefix is for hexadecimal constants, but those ones seems to be binary ones, in wich case they should be prefixed with "0b" HIH Best regards Jorge |
|
|
|
|
|
0x或0b并不是两者。C18接受它作为二进制常数吗?
以上来自于百度翻译 以下为原文 0x or 0b Not Both. C18 accepts that as a binary constant? |
|
|
|
|
|
它们是我的错别字。它们应该是0B11111111和0B11111001。有趣的是,XC8不把它看成二进制,也不把它看成0x0B。这就是为什么它用C18工作,而不是用XC8工作。这是一个鬼鬼祟祟的打印错误。它在论坛中被发现很快,而不是在MS支持2个月。谢谢一群家伙。
以上来自于百度翻译 以下为原文 They are my typos. They're supposed to be 0b11111111 and 0b11111001. It's interesting that XC8 doesn't take it as binary, nor as hex as 0x0B. That's why it works with C18, but not with XC8. It's sneaky typo. It's discovered fast in forum, not in MS support for 2 months. thanks a bunch guys. |
|
|
|
|
|
因为B是一个有效的十六进制数字,所以它是一个有效的数字。是这个问题,还是它在这里键入错误?
以上来自于百度翻译 以下为原文 Since b is a valid hex digit it is a valid number. Was that the issue, or it is typed here wrong? |
|
|
|
|
|
Irc,XC8编译器应该在常量表达式警告中输出溢出,如0x0B…肯定不能适应8位寄存器。
以上来自于百度翻译 以下为原文 IIRC, the XC8 compiler should output an overflow in constant expression warning, as 0x0b... surely cannot fit into an 8-bit register. |
|
|
|
|
|
它是用C18在原始代码中键入的。由于C18把它作为二进制,所以值是正确的。所有的工作都是设计好的,然后我把代码移植到XC8。XC8将其取为0x11,而不是0x0b,而不是0xFF。我不知道为什么,“PR4= 0x0B11111111”,如果它被认为是十六进制,则有两个额外的比特。所以XC8应该发出警告,甚至是一个错误。我认为这应该是一个语法错误。代码现在用XC8工作。
以上来自于百度翻译 以下为原文 It's typo in the original code using C18. Since C18 takes it as binary, the value is correct. Everything works as designed. Then I ported the code to XC8. XC8 takes it as 0x11, not 0x0B, not 0xFF. I don't know why. The line "PR4 = 0x0b11111111;" has two extra bits if it is going to be considered hex. So XC8 should issue a warning, or even an error. I think it should be an syntax error. The code works now with XC8. |
|
|
|
|
|
XC8将这些值作为9位十六进制数,但只有两个最低有效位数被指派给PRx。
以上来自于百度翻译 以下为原文 XC8 takes those as 9-digit hexadecimal numbers, but only the two least significant digits are assigned to PRx. |
|
|
|
|
|
我惊讶的是,C18没有发出警告。因为PRx是8位宽度,十六进制数字得到TuncDead。XC8发出警告,见我以前的帖子。
以上来自于百度翻译 以下为原文 I'm surprise C18 did not throw a warning. Since PRx is 8-bit width, the hex number got truncated. XC8 does issue a warning, see my previous post. |
|
|
|
|
|
|
|
|
|
|
|
XC8必须发出语法错误有两个原因:1)PR4是一个8位寄存器(不是变量)。它必须是8位,周期2。很明显,“PR4= 0x0B11111111”不是一个8位变量/寄存器的有效C代码。如果编译器这样做,程序员不会抱怨,但会意识到编译器正在监视他/她。
以上来自于百度翻译 以下为原文 XC8 must issue a syntax error for two reasons: 1) PR4 is a 8-bit register (not a variable). It has to be 8bit, period. 2) It's clearly that "PR4 = 0x0b11111111;" is not a valid C code for an 8-bit variable/register If a compiler does this, the programmer wouldn't complain, but would appreciate that the compiler is watching his/her back. |
|
|
|
|
|
|
|
|
|
|
|
好,我的XC8产生这个:警告(751)…常数表达式中的算术溢出
以上来自于百度翻译 以下为原文 Okay, my XC8 generates this: Warning [751] ... arithmetic overflow in constant expression |
|
|
|
|
只有小组成员才能发言,加入小组>>
MPLAB X IDE V6.25版本怎么对bootloader和应用程序进行烧录
495 浏览 0 评论
5808 浏览 9 评论
2347 浏览 8 评论
2237 浏览 10 评论
请问是否能把一个ADC值转换成两个字节用来设置PWM占空比?
3542 浏览 3 评论
1151浏览 1评论
有偿咨询,关于MPLAB X IPE烧录PIC32MX所遇到的问题
1118浏览 1评论
我是Microchip 的代理商,有PIC16F1829T-I/SS 技术问题可以咨询我,微信:A-chip-Ti
886浏览 1评论
MPLAB X IDE V6.25版本怎么对bootloader和应用程序进行烧录
499浏览 0评论
/9
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2025-12-11 13:26 , Processed in 1.065350 second(s), Total 79, Slave 72 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191

淘帖
2521