完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
嗨,我是新的PIC控制器。我正在使用“PIC24FJ16GA02”为我的项目。我必须产生一个PWM信号的时间为2ms和关断时间为1ms,总时间为3ms的1个周期。我希望在程序中使用中断服务程序中的PWM中断。我被困在产生中断。任何人可以帮助我的代码来生成PWM。我正在使用MPLAB IDE V8988与编译器C30。谢谢你。
以上来自于百度翻译 以下为原文 Hi.., I am new to PIC controllers. I am using "PIC24FJ16GA002" for my project. I have to generate a PWM signal with a on-time of 2ms and off-time of 1ms with a total time of 3ms for 1 cycle. I would like use the PWM interrupts in the interrupt service routine in the program. I am stuck in generating the interrupt. Can anyone help me with the code to generate the PWM. I am using MPLAB IDE v8.89 with compiler C30. Thank you in advance.. |
|
相关推荐
14个回答
|
|
你希望中断做什么?如果您正确地将OC模块设置为PWM模式,那么它将很高兴地为您自己生成该波形。在此模式下,OC模块中断仅由驱动活动的FAULT管脚触发。您可以对任意定时器使用中断服务来获得每个周期的一个中断U将OC模块连接到。
以上来自于百度翻译 以下为原文 What do you want the interrupt to do? If you correctly set up the OC module in PWM mode, then it will happily generate that waveform for you all by itself. In this mode, the OC module interrupt is only triggered by the FAULT pin being driven active. You can get one interrupt per cycle by using the interrupt service for whichever timer you have connected the OC module to. |
|
|
|
嗨,谢谢你的帮助。请检查一下我的代码,并且请让我知道我是否错了。void InitializeTimer1For_PWM(void){T1CON=0x00;//停止Timer1并重置控制reg.TMR1=0x00;//清除定时器寄存器PR1=0xFFFFFF的内容;//用值0xFFFFFFFF加载周期寄存器IPC0bits.T1IP=0x01;//Setup Timer1中断,用于期望的优先级IFS0bits.T1IF=0;//清除Timer1中断状态标志IEC0bits.T1IE=1;//Enable Timer1中断T1CONbits.TON=1;//Start Timer1,预调焦器设置为1:1,和//时钟源设置为内部指令周期}void Initialize_PWM(void){OC1CONbits.OCM=0b000;//清除OCM位,输出ocm比较位OC1R=0x0F;OC1RS=0x0F;具有最小pwmOC3CONbits.OCTSEL=0;OC1R=0x0F;OC1CONbits.OCM=0b110;//starting模块。我在代码中使用了这两个函数。如果有什么错误,请帮我输入正确的代码在这里,谢谢,
以上来自于百度翻译 以下为原文 Hi.., Thank you for the help. Please have a check on my code and please let me know if I am wrong. void InitializeTimer1For_PWM(void) { T1CON = 0x00; //Stops the Timer1 and reset control reg. TMR1 = 0x00; //Clear contents of the timer register PR1 = 0xFFFF; //Load the Period register with the value 0xFFFF IPC0bits.T1IP = 0x01; //Setup Timer1 interrupt for desired priority level IFS0bits.T1IF = 0; //Clear the Timer1 interrupt status flag IEC0bits.T1IE = 1; //Enable Timer1 interrupts T1CONbits.TON = 1; //Start Timer1 with prescaler settings at 1:1 and //clock source set to the internal instruction cycle } void Initialize_PWM(void) { OC1CONbits.OCM= 0b000; //clearing OCM bits, ocm is output compare bits OC1R=0x0F; OC1RS=0x0F; //starting module with minimum pwm OC3CONbits.OCTSEL=0; OC1R=0x0F; OC1CONbits.OCM=0b110; } I have used these 2 functions in the code. Please help me with the right code if I am wrong somewhere above. Thank you, |
|
|
|
如果你要启用定时器中断,那么你最好也添加一个中断服务例程。你还没有提到中断需要什么。
以上来自于百度翻译 以下为原文 If you're going to enable timer interrupts, then you better add an interrupt service routine as well. You still have not mentioned what the interrupt is required for. |
|
|
|
嗨…我想用中断来产生具有特定摆率的PWM。是的,我被中断服务例程部分卡住了。我不知道如何编码这个中断服务例程部分。请帮我完成这个代码。我可以得到使用PIC24FJ16GA002内部振荡器初始化和生成PWM信号的样本代码吗?谢谢。
以上来自于百度翻译 以下为原文 Hi... I thought of using interrupt to generate the pwm with the specific slew rate. And yeah I'm stuck with interrupt service routine part . I don't know how to code this interrupt service routine part. Please help me out to complete the code. May I get the sample code for initialising and generating the PWM signal using an internal oscillator for PIC24FJ16GA002. Thank you.. |
|
|
|
您可以在论坛上找到许多代码示例(包括我的一个线程):尝试googlehttps://www.google.it/#hl...Ddariog&gws_rd=ssl
以上来自于百度翻译 以下为原文 You can find lot of code examples (including a thread of mine) on the forum: try google https://www.google.it/#hl...Ddariog&gws_rd=ssl |
|
|
|
嗨……是的,我发现了很多,例如,我在上面写了我上面的代码。但我没有得到PWM输出。因此,如果我得到一个精确的控制器的样本代码,我使用PIC24FJ16GA02,它会更好。谢谢你。
以上来自于百度翻译 以下为原文 Hi... Yeah I found many e.g. s' with the help of which I wrote my above code.. but I'm not getting the pwm output .. So if I get a sample code for the exact controller I'm using PIC24FJ16GA002 it would be better. Thank you.. |
|
|
|
嗯,1)你的PIC在运行吗?硬件,主循环…2)如Qhb所说,不需要激活Irqs3),你可以选择使用主时钟的定时器,以一个较少的变量开始…
以上来自于百度翻译 以下为原文 Hmm, 1) is your PIC running at all? hardware, main loop... 2) as Qhb says above, no need to active IRQs 3) you may choose to use Main Clock insted of a timer, to start with one less variable... |
|
|
|
嗯?你打算如何控制“转换率”?这是数字输出,转换速率由输出驱动器阻抗和负载阻抗控制。编译器用户指南中有空中断服务的例子。由于您没有真正解释中断应该做什么,我们不能再建议了。
以上来自于百度翻译 以下为原文 Huh? How do you propose to control the "slew rate" ? This is a digital output, the slew rate is controlled by the output driver impedance, and the impedance of your load. There are examples of an empty interrupt service in the compiler user guide. As you have not really explained what the interrupt should do, we can't advise any further. |
|
|
|
我很确定“回转率”是指“占空比”…
以上来自于百度翻译 以下为原文 I am pretty sure "slew rate" was meant for "duty cycle"... |
|
|
|
如果是“占空比”,那么外围设备已经完全为您做了,不需要中断,正如我在#2后面已经提到的。
以上来自于百度翻译 以下为原文 If it is "duty cycle", then that is what the peripheral is already doing completely for you, with no need for an interrupt, as I already mentioned in post#2. |
|
|
|
嗨……是的,我的意思是dutyCurv作为上行率。谢谢你的建议,qhb和Dario G。确切地说,我正在寻找的是在每个固定的时间间隔中断的常量信号。某处看起来像正方形或PWM信号。
以上来自于百度翻译 以下为原文 Hi.. Yes I meant the dutycycle as the slew rate above. Thank you for the suggessions qhb and Dario G. Exactly what I am looking for is a constant signal interrupted at every regular determined interval. That would somewhere look like a square or pwm signal. |
|
|
|
你的措辞使得你很难看清你现在是否已经明白你不需要中断。你应该在开始编码或拷贝你还不明白的代码之前阅读更多关于PWM的信息。你将无法得到完整的PIC代码。手册(DS8981C)是你的朋友。也见13.2,当然还有“输出比较寄存器”的描述。你读过的重要笔记1RPARX(OCX)必须配置为一个可用的RPN引脚。有关更多信息,请参见第9.4节“外围引脚选择”。DS70005157A包含输出比较模块的更多信息。为什么设置OC3CONbits.OCTSEL=0,而其余都引用OC1?为什么使用TMR1?如qhb在#3后面所言:IEC0bits.T1IE=1;//Enable Timer1中断没有定义中断函数就没有意义。
以上来自于百度翻译 以下为原文 Your wording makes it difficult to see whether you now have understood that you do not need interrupts. You should read more about PWM before you start coding or copying code which you do not yet understand. You will no get complete code for your PIC presented to all your needs. Chapter 13 of your PIC's manual (DS39881C) is your friend. See also 13.2 and of course the description of the "Output Compare Register". Did you read the important note 1 RPORx (OCx) must be configured to an available RPn pin. For more information, see Section 9.4 “Peripheral Pin Select”. ? DS70005157A contains more information for the Output Compare Module. Why do you set OC3CONbits.OCTSEL=0 while all the rest refers to OC1 ? Why do you use TMR1 ? As qhb said in post #3 with this line: IEC0bits.T1IE = 1; //Enable Timer1 interrupts does not make sense without defining an interrupt function for it. |
|
|
|
嗨,谢谢Rodims的建议。我是新的微控制器,我将从基础开始。
以上来自于百度翻译 以下为原文 Hi.. Thank you Rodims for the suggesions. I am new with the micro-controllers I will start from the basics. |
|
|
|
嗨,DarioG,请你检查一下我的线好吗?HTTP://www. McCHIP.COM/FUMMS/M9431.1.ASPX?树= TraceI也坚持PWM,但与PIC32 MX。
以上来自于百度翻译 以下为原文 Hi DarioG, can u please check my thread. http://www.microchip.com/forums/m947321.aspx?tree=true I'm also stuck with PWM but with PIC32MX. |
|
|
|
只有小组成员才能发言,加入小组>>
5039 浏览 9 评论
1936 浏览 8 评论
1872 浏览 10 评论
请问是否能把一个ADC值转换成两个字节用来设置PWM占空比?
3092 浏览 3 评论
请问电源和晶体值之间有什么关系吗?PIC在正常条件下运行4MHz需要多少电压?
2160 浏览 5 评论
601浏览 1评论
466浏览 1评论
PIC Kit3出现目标设备ID(00000000)与预期的设备ID(02c20000)不匹配。是什么原因
496浏览 0评论
400浏览 0评论
IPECMD命令烧录AVR128DA48芯片,报找不到芯片错误
877浏览 0评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-9-6 05:21 , Processed in 1.495613 second(s), Total 105, Slave 88 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191