完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
电子发烧友论坛|
HI,目前我使用PIC18浏览器开发板和PIC18F822作为主控制器。我使用C18(V3.47)编译器在我的系统上。任何人可以共享PWM代码进行实验。我尝试了下面的代码,给出了SC18的用户指南文件,并且我试图观察RC2上的PWM,但是没有PWMUTU。有人能帮我吗?问候,阿南德
以上来自于百度翻译 以下为原文 Hi , Currently i am using PIC18 explorer development board and PIC18f8722 as main controller. I am using C18 (v3.47) compiler on my system. Can anyone share PWM code for experimenting. I tried the below code given in c18 peripheral user guide document and i tried to observe the pwm on RC2 but no pwm output seen. can anyone help me on this. /****************************************************************** * NOTES: * Code uses the Peripheral library support available with MCC18 Compiler * Code Tested on: * PicDem2+ demo board with PIC18F4685 controller * PWM output is obtained on CCP1 pin. duty cycle is gievn by * *Formula for Period and Duty cycle calculatio * * PWM period = [(period ) + 1] x 4 x Tosc x TMR2 prescaler * * PWM x Duty cycle = (DCx<9:0>) x Tosc * * Resolution (bits) = log(Fosc/Fpwm) / log(2) **********************************************************************/ #define USE_OR_MASKS #include #include "pwm.h" void main(void) { char period=0x00; unsigned char outputconfig=0,outputmode=0,config=0; unsigned int duty_cycle=0; //----Configure pwm ---- //period = 0xFF; period = 0xFF; OpenPWM1( period); //Configure PWM module and initialize PWM period //-----set duty cycle---- duty_cycle = 0x0F00; SetDCPWM1(duty_cycle); //set the duty cycle //----set pwm output---- outputconfig = FULL_OUT_FWD ; outputmode = PWM_MODE_1; SetOutputPWM1( outputconfig, outputmode); //output PWM in respective modes while(1); //observe output on CCP1 pin ClosePWM1(); } Regards, Anand |
|
相关推荐
4个回答
|
|
|
您的代码看起来几乎可以,但是(尤其是对于PIC18)使用PWM库函数是一种混乱。尝试不同的值为周期和DutySyLook。还有,你在TIS中设置了PIN作为输出吗?
以上来自于百度翻译 以下为原文 Your code looks almost ok, but (especially for PIC18) using the PWM library functions was kind of a mess. Try different values for period and duty_cycle. Also, did you set that pin as output in TRIS? |
|
|
|
|
|
Hi Cinziag,RC2引脚设置在OpenPWM1()函数中。空隙OpenPWM1(CHAR周期){CCP1CON=0B000 000 1100;/CCPXM011xx=PWM MODETISCITBITS。TrISC2=0;//---------------------------T-2,TMR2ON=0;//停止Time2注册到POR状态PR2=周期;//设置PayoD T2CONTITS。TMR2ON=1;//打开PWM1}不确定在RC2中没有得到任何输出吗?问候,阿南德
以上来自于百度翻译 以下为原文 Hi Cinziag , RC2 pin is set inside OpenPWM1() functions. void OpenPWM1( char period ) { CCP1CON |= 0b00001100; //ccpxm3:ccpxm0 11xx=pwm mode TRISCbits.TRISC2 = 0; //--------------------------------------------------- T2CONbits.TMR2ON = 0; // STOP TIMER2 registers to POR state PR2 = period; // Set period T2CONbits.TMR2ON = 1; // Turn on PWM1 } Not sure I am not getting any out in RC2? Regards, Anand |
|
|
|
|
|
我看,我只使用那些功能,很少有把握,你试过改变周期等吗?
以上来自于百度翻译 以下为原文 I see, I only used those functions rarely Not sure, did you try changing the period etc? |
|
|
|
|
|
对。我试过了。但是在RC2引脚上没有PWM信号产生,你能建议做什么吗?问候,阿南德
以上来自于百度翻译 以下为原文 Yes. I tried . But no pwm signal generating on RC2 pin. Can you please suggest what to do? Regards, Anand |
|
|
|
|
只有小组成员才能发言,加入小组>>
MPLAB X IDE V6.25版本怎么对bootloader和应用程序进行烧录
475 浏览 0 评论
5794 浏览 9 评论
2334 浏览 8 评论
2224 浏览 10 评论
请问是否能把一个ADC值转换成两个字节用来设置PWM占空比?
3530 浏览 3 评论
1124浏览 1评论
有偿咨询,关于MPLAB X IPE烧录PIC32MX所遇到的问题
1098浏览 1评论
我是Microchip 的代理商,有PIC16F1829T-I/SS 技术问题可以咨询我,微信:A-chip-Ti
873浏览 1评论
MPLAB X IDE V6.25版本怎么对bootloader和应用程序进行烧录
475浏览 0评论
/9
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2025-12-2 14:00 , Processed in 0.732545 second(s), Total 80, Slave 63 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191

淘帖
3221