完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
我试图配置PIC16F1579运行4通道的独立和独立运行PWM。看来,当我改变了一个频道的dutyCouter,它也会影响到其他频道。不确定如果我错过了某处或没有正确配置它。将样本init和设置为dutyCy.U.PoSlice=GIE;GPSE=0x55;PPSLoCK=0xAA;PPsLoopBit。PPsLoCK=0x00;;/ /解锁PPS//CKPPsBITS;CKPPS= 0x04;//RA4--&G.EasART:CK//RA4PPSITS。RA4PPS= 0x09;//RA4--&G.EuSART:CK RB4PPSBIT。RB4PPS= 0x05;//66ppsBist.RB6PPS= 0x03;/pWM3:PWM1OUT RB7PPsBIT.RB7PPS= 0x06;//RB7- &;pWM4:PWM4OUD RA4PPS= 0x09;RXPPS= 0x15;RC5PPS= 0x0A;//RC5PPSITS。RC5PPS= 0x0a;//RC5--Gt;EUSAART:DT PPSROCK=0x55;PPSROCK=0xAA;PPS RB4--gt;pWM1:PWM3OUT RB5PPsBI.RB5PPS= 0x04;//RB5--gt;pWM2:PWM2OUT锁比特=0x01;//锁定PPS Ge=状态;SLRCONB= 0B10000;//清除速率寄存器/OdCONB= 0B11110000;ANSELB=0x00;//PWM1 PWM1CKCONN=0x01;/ /来自HFINTOSC W/O预分频器//PWM1PR=63;//500 kHz=0.000002=(PR+1)*预刻度/32000000 pWM1PR=63;//500 kHz=0.000002。=(pr + 1)*预缩放/ 32000000 pWM1pH=0;pWM1DC=0;pWM1ITE= 0x00;//没有中断使PWM1Itff=0x00;//清除中断标志PWM1LDCONN=0x00;/ /负载PWM1OFCON=0x00;/ /独立运行模式PWM1CONN=0x80;//启用,标准PWM模式,有源高输出//PWM2PWM2CLKCON=0x01;//来自HFINTOSC W/O预分频器PWM2PR=63;//500 kHz=0.000002(PR+1)*预量/32000000 pWM2pH=0;PWM2DC=0;PWM2ITEE=0x00;//没有中断使能PWM2Itf= 0x00;/ /清除中断标志PWM2LDCONN=0x00;/ /负载武装的PWM2OFCONN=0x00;/ /NT运行模式PWM2CON=0x80;//启用,标准PWM模式,有源高输出//PWM3 PWM3CKCONN=0x01;/ /来自HFINTOSC W/O预分频器PWM3PR=63;//500 kHz=0.000002(PR + 1)*预刻度/32000000 pWM3PH=0;PWM3DC=0;PWM3OFE=0;PWM3ITEE=0x00;/ /没有中断启用PWM3Itf= 0x00;;清除中断标志PWM3LDCONN=0x00;//负载载波PWM3OFCON=0x00;/ /独立运行模式PWM3CONC= 0x80;//启用,标准PWM模式,有源高输出//PWM4 PWM4CKCONN=0x01;/ /来自HFINTOSC W/O预分频器PWM4PR=63;//500 kHz=0.000002=(PR+1)*预刻度/32000000 pWM4pH=0;PWM4DC=0;PWM4OTE=0;PWM4NETE=0x00;//没有中断使PWM4ITNF=0x00;//清除中断标志PWM4LDCONN=0x00;/ /负载独立的PWM4OFCON=0x00;/ /独立运行模式PWM4CON= 0x80;//启用,标准PWM模式,活动高输出}空隙IIIIT({ / /配置输出TrISABIT.tiSISA0=)0;//输出TrISAbIt=0;//输出TrISaB2=0;/TrISC00=0;//输出TISCIST1。TISISC1=0;//输出TISCcBITS;TISISC2=0;/LATA0=0;//输出断开LATABIT。LATA1=0;//输出关断LATABIT。S.LATC1=0;//输出断开/ 0 /;输出/ /配置输入TISCcTIs;TrISC3=1;//输入TISCc4=1;//输入TISCcTIs:TrISC5=1;//输入TISCISTITS TRISC6=1;//输入/ /配置PPS输出TrISBITS.TISBB4=0;0;//输出TrISB7=0;//输出RX/TX TrISABIIT.TISISA4=0;//TX TrISCITS.TrISC5=1;//RX}/ /改变CyCurdDutyCype的样本[2 ] = MyOut0+MyOut1;PWM3Con=0x00;/ /禁用pWMPWM3DC= DutyCype [2 ];/ /更改DCPWM3PR=63;//500 kHz=0.000002=(PR+1)*PRESCale/3200 000 PWM3PH=0;/pWM1DC=0;PWM3ITE= 0x00;//没有中断启用PWM3Itff=0x00;//清除中断标志WM3LDCONC= 0x00;/ /负载ARMMEM3OFCONN=0x00;/ /独立运行模式激活HypWM3CON=0x80;//使能,标准PWM模式
以上来自于百度翻译 以下为原文 I am trying to configure the PIC16F1579 to run 4 channel of standalone and Independently run PWM. It seem that when I change the DutyCycle of one of the channel, it will affected other channel as well. Not sure if I miss out somewhere or did not configure it properly. Enclosed the sample Init and Setting for the DutyCycle. void PPSInit() { bool state = GIE; GIE = 0; PPSLOCK = 0x55; PPSLOCK = 0xAA; PPSLOCKbits.PPSLOCKED = 0x00; // unlock PPS //CKPPSbits.CKPPS = 0x04; // RA4->EUSART:CK //RA4PPSbits.RA4PPS = 0x09; // RA4->EUSART:CK RB4PPSbits.RB4PPS = 0x05; // RB4->PWM1:PWM3OUT RB5PPSbits.RB5PPS = 0x04; // RB5->PWM2:PWM2OUT RB6PPSbits.RB6PPS = 0x03; // RB6->PWM3:PWM1OUT RB7PPSbits.RB7PPS = 0x06; // RB7->PWM4:PWM4OUT RA4PPS = 0x09; RXPPS = 0x15; RC5PPS = 0x0A; //RC5PPSbits.RC5PPS = 0x0A; // RC5->EUSART:DT PPSLOCK = 0x55; PPSLOCK = 0xAA; PPSLOCKbits.PPSLOCKED = 0x01; // lock PPS GIE = state; SLRCONB = 0b00000000; // CLEAR SLEW RATE Register //ODCONB = 0b11110000; ANSELB = 0x00; //PWM1 PWM1CLKCON = 0x01; // From HFINTOSC w/o prescaler //PWM1PR = 63; // 500Khz = 0.000002 = (PR + 1 )* Prescale / 32000000 PWM1PR = 63; // 500Khz = 0.000002 = (PR + 1 )* Prescale / 32000000 PWM1PH = 0; PWM1DC = 0; PWM1OF = 0; PWM1INTE = 0x00; // no interrupts enabled PWM1INTF = 0x00; // clear interrupt flag PWM1LDCON = 0x00; // load armed PWM1OFCON = 0x00; // independent run mode PWM1CON = 0x80; // enable, standard PWM mode, active high output //PWM2 PWM2CLKCON = 0x01; // From HFINTOSC w/o prescaler PWM2PR = 63; // 500Khz = 0.000002 = (PR + 1 )* Prescale / 32000000 PWM2PH = 0; PWM2DC = 0; PWM2OF = 0; PWM2INTE = 0x00; // no interrupts enabled PWM2INTF = 0x00; // clear interrupt flag PWM2LDCON = 0x00; // load armed PWM2OFCON = 0x00; // independent run mode PWM2CON = 0x80; // enable, standard PWM mode, active high output //PWM3 PWM3CLKCON = 0x01; // From HFINTOSC w/o prescaler PWM3PR = 63; // 500Khz = 0.000002 = (PR + 1 )* Prescale / 32000000 PWM3PH = 0; PWM3DC = 0; PWM3OF = 0; PWM3INTE = 0x00; // no interrupts enabled PWM3INTF = 0x00; // clear interrupt flag PWM3LDCON = 0x00; // load armed PWM3OFCON = 0x00; // independent run mode PWM3CON = 0x80; // enable, standard PWM mode, active high output //PWM4 PWM4CLKCON = 0x01; // From HFINTOSC w/o prescaler PWM4PR = 63; // 500Khz = 0.000002 = (PR + 1 )* Prescale / 32000000 PWM4PH = 0; PWM4DC = 0; PWM4OF = 0; PWM4INTE = 0x00; // no interrupts enabled PWM4INTF = 0x00; // clear interrupt flag PWM4LDCON = 0x00; // load armed PWM4OFCON = 0x00; // independent run mode PWM4CON = 0x80; // enable, standard PWM mode, active high output } void IOInit() { // Configure Output TRISAbits.TRISA0 = 0; //output TRISAbits.TRISA1 = 0; //output TRISAbits.TRISA2 = 0; //output TRISCbits.TRISC0 = 0; //output TRISCbits.TRISC1 = 0; //output TRISCbits.TRISC2 = 0; //output LATAbits.LATA0=0; //Output Off LATAbits.LATA1=0; //Output Off LATAbits.LATA2=0; //Output Off LATCbits.LATC0=0; //Output Off LATCbits.LATC1=0; //Output Off LATCbits.LATC2=0; //Output Off // Configure Input TRISCbits.TRISC3 = 1; //input TRISCbits.TRISC4 = 1; //input TRISCbits.TRISC5 = 1; //input TRISCbits.TRISC6 = 1; //input // Configure PPS Output TRISBbits.TRISB4 = 0; //output TRISBbits.TRISB5 = 0; //output TRISBbits.TRISB6 = 0; //output TRISBbits.TRISB7 = 0; //output // Configure RX/TX TRISAbits.TRISA4 = 0; // TX TRISCbits.TRISC5 = 1; // RX } // Sample of changing the Duty Cycle DutyCycle[2] = myOut0+myOut1; PWM3CON = 0x00; // Disable PWM PWM3DC = DutyCycle[2]; // Change DC PWM3PR = 63; // 500Khz = 0.000002 = (PR + 1 )* Prescale / 32000000 PWM3PH = 0; //PWM1DC = 0; PWM3OF = 0; PWM3INTE = 0x00; // no interrupts enabled PWM3INTF = 0x00; // clear interrupt flag PWM3LDCON = 0x00; // load armed PWM3OFCON = 0x00; // independent run mode active high PWM3CON = 0x80; // enable, standard PWM mode |
|
相关推荐
2个回答
|
|
有人面临同样的问题吗?我尝试测试,下面是总结。如果PWM1 dutyCouple改变,它将影响PWM2如果PWM2 dutyCurry变化,它将影响PWM3如果PWM3 dutyCouple变化,其他OKIF PWM4 dutyCouple变化,它将影响PWM1和2样本测试代码IF(ByTeDATA=43)//+{PWM3CONBITS.PWM3EN=0;PWM3DC= PWM3DC++P;1。WM3CONBITS.PWM3EN=1;}(ByTeDATA==45)//{pWM3CONTIT.PWM3EN=0;PWM3DC= PWM3DC-1;PWM3CONBITS.PWM3EN=1;
以上来自于百度翻译 以下为原文 Anyone facing the same problem? I try to test and below are the summary. if PWM1 DutyCycle change, it will affect PWM2 if PWM2 DutyCycle change, it will affect PWM3 if PWM3 DutyCycle change, other OK if PWM4 DutyCycle change, it will affect PWM1 and 2 sample test code if (bytedata == 43) //+ { PWM3CONbits.PWM3EN = 0; PWM3DC=PWM3DC+1; PWM3CONbits.PWM3EN = 1; } if (bytedata == 45)//- { PWM3CONbits.PWM3EN = 0; PWM3DC=PWM3DC-1; PWM3CONbits.PWM3EN = 1; |
|
|
|
|
|
|
|
只有小组成员才能发言,加入小组>>
5223 浏览 9 评论
2024 浏览 8 评论
1949 浏览 10 评论
请问是否能把一个ADC值转换成两个字节用来设置PWM占空比?
3198 浏览 3 评论
请问电源和晶体值之间有什么关系吗?PIC在正常条件下运行4MHz需要多少电压?
2252 浏览 5 评论
768浏览 1评论
655浏览 1评论
有偿咨询,关于MPLAB X IPE烧录PIC32MX所遇到的问题
582浏览 1评论
PIC Kit3出现目标设备ID(00000000)与预期的设备ID(02c20000)不匹配。是什么原因
666浏览 0评论
569浏览 0评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-12-15 23:00 , Processed in 1.342624 second(s), Total 80, Slave 64 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号