完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
我正在工作的脉宽调制器是一个缩放从一个输入捕获脉冲。PIC,MX695F512H,正在开发的MLAX IDE V3.30,并利用和声1.08。该板是利用u***设备引导加载器进行编程定制的。目前,该设备捕获IC2上的输入脉冲,该输入脉冲可以创建1:1-约100kHz的切换输出引脚。配置在OC2上的PWM由于timeR2被配置为具有中断的32位定时器输出单频脉冲。周期寄存器设置为0D2000,外围时钟在80MHz处切换。输出捕获脉冲在40kHz切换。我的目标是改变周期寄存器PR2/PR3,以反映IC2的脉冲周期,并且希望在OC2中断例程中实现这一点。当脉冲变高时,PR2/PR3根据IC2上的脉冲周期而改变。当PR2/PR3匹配Timer2/3,Timer2/3回到零,反映IC2上的新周期的PR2/PR3总是比计时器大。2中断不中断?我没有看到关于中断的PWM时序图,没有在数据表OC章节,没有在设备系列的特定OC章节中,也没有在HARMony help Volume IV:Driver Libraries-OCs中。谢谢你能给我提供任何帮助!CY
以上来自于百度翻译 以下为原文 I am working on pulse width modulator that is a scaled from an Input capture pulse. The PIC, mx695f512H, is being developed in the MLABX IDE v3.30 and utilizing Harmony 1.08. The board is custom utilizing the u*** device bootloader for programming. Currently, the device captures the input pulse on the IC2 which can create a toggled output pin, 1:1 to about 100kHz. The PWM configured on OC2 outputs a single frequency pulse due to Timer2 configured as a 32 bit timer with interrupt. The period register is set to 0d2000 and the peripherals clock is switching at 80MHz. The output capture pulse is toggling at 40kHz. My goal is to change the Period Registers PR2/PR3 to reflect pulse period of IC2 and would like to accomplish this inside the OC2 interrupt routine. When the pulse goes high PR2/PR3 are changed according to pulse period on IC2. This would be good timing as PR2/PR3 matches Timer2/3, Timer2/3 gets set back to zero and PR2/PR3, reflecting new period on IC2, would always be greater than the timer at comparison. Question: Having followed the nearly the same procedure for the interrupt routines on the IC2 and the Timer2/3 the OC2 interrupt does not interrupt? I have not seen a timing diagram for the PWM concerning interrupts, not in the datasheet OC chapter, not in the specific OC chapter of the device family and not in the Harmony help Volume IV: Driver Libraries - OCs. Thank you for any help you could provide me with my problem! Cy |
|
相关推荐
6个回答
|
|
事实证明,根据一个程序员在一个示例输出比较章节中的注释,OC中断在PWM模式下是不可用的。我猜我需要把PR2/PR3的变化转移到Time2/3中断。
以上来自于百度翻译 以下为原文 Turns out, according to a programmers remark in an example Output Compare chapter, the OC interrupt is not available in PWM mode. Guess I will need to move the changing of PR2/PR3 into the timer2/3 interrupt. Cy |
|
|
|
因此,我试图改变32位输出比较的周期和每个周期结束时的占空比。当周期寄存器PR2和PR3与定时器2和定时器3相同,并且由定时器中断启动和处理时,周期结束。~在中断时,定时器被重置为零,OC2/3RS的值被加载到OC2/3R。这不起作用,将OC2挂起大约53,这是以80MHz运行的32位定时器的周期。根据IC2上的输入脉冲计算,每次在32定时器周围产生的输出脉冲在几个周期内大致是正确的。如果我注释掉PLIB_TMR_.32bitSet(TMR_ID_2,Current.);那么占空比将随着IC2的变化而动态变化,看起来是流动的。R是双缓冲的,这与不是双缓冲的PR2/3可能有所不同。问题:有什么原因我不能在周期末的每个周期都改变per.?谢谢你考虑我的问题!中断代码如下:uint32_t CurrentInput,当前周期,当前Du度,之前输入,PulseWidScaler=2;void_ISR(_TIMER_3_VECTOR,ipl4AUTO)void_ISR(_TIMER_TIMER_3_VECTOR,ipl4AUTO)IntHandlerDrvTmrInstanInstance0(void){PLIB_OC_OC_OC_OC_OC_脉冲Wid32位32Bit集(OC_ID_2,电流值);PLIB_TMR_TMR_周期32位集(TMR_ID_2,当前周期);PLIB_TMR_ID_ID_2,当前周期);;PLIB_32位集(TMR_ID_IB_INT_SourceFlagClear(INT_ID_0,INT_SOURCE_TIMER_3);}void._ISR(_INPUT_CAPTURE_2_VECTOR_INPUT_CAPTURE_2_矢量,ipl4AUTO)void.{CurrentInInTHandHandHandHandHandHandHandHandHandHandlerDrvICICIns实例0(void){CurrentInInIn输入=DRV_IC0_IC0_Capture3232Bit3232BitDataRead读取();如果(当前输入>>;先前输入;先前输入){当前输入(当前输入>(当前输入>>之前输入){当前周期=当前输入——当前输入——当前输入——先前输入——脉冲宽度caler;//DRV_TMR0_.ValueSet(Current.);}PreviousInput=CurrentInput;PLIB_INT_SourceFlagClear(INT_ID_0,INT_SOURCE_INPUT_CAPTURE_2);}
以上来自于百度翻译 以下为原文 So, I am attempting to change both the period of the 32 bit output compare, and the duty cycle at the end of each cycle. The period completes when the period registers PR2 and PR3 are the same as timer2 and timer3 setting off and handled by the timer3 interrupt. "~At the interrupt", the timers are reset to zero and the value of the OC2/3RS are loaded to OC2/3R. This does not work and hangs OC2 for about 53 which is the cycle of the 32bit timer running at 80MHz. The output pulse generated every time around the 32timer is roughly correct for several cycles as calculated from the input pulse on IC2. If I comment out the PLIB_TMR_Period32bitSet(TMR_ID_2, CurrentPeriod); Then the duty cycle will dynamically change and look fluid with the change of IC2. The OC2/3R are double buffered that is likely different from the PR2/3 which are not double buffered. Question: Any reason I can not change the peroid every period at the end of the period? Thank you for your consideration of my problem! The interrupt codes are below: uint32_t CurrentInput, CurrentPeriod, CurrentDuty, PreviousInput, PulseWidthScaler = 2; void __ISR(_TIMER_3_VECTOR, ipl4AUTO) IntHandlerDrvTmrInstance0(void) { PLIB_OC_PulseWidth32BitSet(OC_ID_2, CurrentDuty); PLIB_TMR_Period32BitSet(TMR_ID_2, CurrentPeriod); PLIB_INT_SourceFlagClear(INT_ID_0,INT_SOURCE_TIMER_3); } void __ISR(_INPUT_CAPTURE_2_VECTOR, ipl4AUTO) _IntHandlerDrvICInstance0(void) { CurrentInput = DRV_IC0_Capture32BitDataRead(); if(CurrentInput > PreviousInput) { CurrentPeriod = CurrentInput - PreviousInput; CurrentDuty = CurrentPeriod/PulseWidthScaler; //DRV_TMR0_PeriodValueSet( CurrentPeriod); } PreviousInput = CurrentInput; PLIB_INT_SourceFlagClear(INT_ID_0, INT_SOURCE_INPUT_CAPTURE_2); } |
|
|
|
一旦定时器中断发生,并不意味着定时器保持空闲直到ISR上下文被执行。定时器将再次从零开始计数,并且该时间它选择OCxRS中存在的占空比值(旧值)而不是在定时器ISR中更新的新占空比值。在下一个定时器周期中,这是占空比更新的一种1周期滞后。您可以使用双比较连续脉冲模式来产生PWM,保持OCxR为零以在该周期开始时获得上升沿,并且保持更新PR和OCxRS以适应新的周期和次要比较值。这里有使用OC和定时器ISRS的自由!
以上来自于百度翻译 以下为原文 Once timer interrupt occurs it doesn't mean timer stays idle until ISR context is executed. Timer will start counting from zero again and that time it picks the duty cycle value present in OCxRS( old value) instead of the new duty cycle value updated in the Timer ISR. So your new value will be used in the next timer period, this is a kind of 1 period lag for duty cycle update. You can use Dual Compare continuous pulse mode as well to produce PWM, keep OCxR as zero to get raising edge at the start of the period and keep updating PR and OCxRS for the new period and secondary compare values. You have the freedom of using both OC and Timer ISRs here! |
|
|
|
感谢图腾,我会认真注意你的建议。
以上来自于百度翻译 以下为原文 Thanks Totem, I will be giving serious attention to your suggestion. |
|
|
|
更新:双比较连续模式就在那里,但是在PIC32MX695F512H中,输入捕获和输出比较被卡在相同的定时器2/3上,该定时器2/3将自身复制到ic和oc缓冲器中。这不同于PIC24FV32KA304,其中每个IC和OC都有来自大约8个时钟源之一的单独的定时器。规范是允许输入和输出的.3Hz到100kHz。输入可以在.3Hz捕获,输出将在100kHz时钟,从输入捕获周期乘起来。目前,为了使用双比较连续脉冲模式,输入捕获基于空闲时间计算加载到PRx中的输出比较的周期。运行时钟定时器4/5。因此,输入捕获读取IC2/3缓冲器,但它们是垃圾,因为在输出捕获期间设置了Time2/3。因此,Time4/5被设置为一个自由运行的时钟来捕获周期。这工作,但在100kHz的输出相位变得不稳定,脉冲丢失。我认为,当输入和输出被设置为100kHz时,相位滞后将是一个常数。如果在IC中断内部建立了一个固定的周期和占空比,100kHz和50%,并加载到PRx和OCxRS中,那么输出相位是相当稳定的。因此,对于双比较连续脉冲模式,利用32位缓冲器读取的自由运行定时器不可能在放入PRx的每个完整周期具有变化周期?谢谢你考虑我的问题。
以上来自于百度翻译 以下为原文 Update: The dual compare continuous mode is just about there, however in the PIC32MX695F512H the input capture and the output compare are stuck running from the same timer2/3 which copies itself into the ic and oc buffers. This is different from the PIC24FV32KA304 where each IC and OC have individual timers sourced from one of about 8 clock sources. The specification is to allow .3Hz to 100kHz on either the input and or the output. The input could be capturing at .3Hz and the output would be clocking at 100kHz, multiplied up from the input capture period. Currently, in order to use the dual compare continuous pulse mode the input capture calculates the period for the output compare which is loaded into the PRx, based on a free running clock timer 4/5. So, the input capture reads the IC2/3 buffers but they are garbage as the timer2/3 are set for the period on the output capture. Therefore, the timer4/5 was set up as a free running clock to capture periods. This works but the phase of the output at 100kHz is becoming unstable and pulses are lost. I would think that the phase lag would be a constant when the input and the output are set to match at 100kHz. If a constant period and duty cycle, 100kHz and 50%, are established inside the IC interrupt and loaded into the PRx and OCxRS then the output phase is quite stable. Question: I am thinking about the IC and OC timers correctly, that is are both controlled by Timer2/3? Therefore, a free running timer utilizing the 32 bit buffer read can not exist with a changing period at every completed cycle put into the PRx for dual compare continuous pulse mode? Thank you for your consideration of my problem. Cy |
|
|
|
IC和OC是否从相同的定时器2/3运行,不能从单独的32位定时器运行,例如?IC能从自由运行的4/5位32位定时器运行,并且OC从受控的2/3位32位定时器运行吗?
以上来自于百度翻译 以下为原文 Are the IC and the OC running from the same timers 2/3 and can not be run from separate 32 bit timers, ex.? Can the IC runs from the free running 4/5 32 bit timer and the OC runs from the controlled 2/3 32 bit timer? |
|
|
|
只有小组成员才能发言,加入小组>>
5189 浏览 9 评论
2009 浏览 8 评论
1933 浏览 10 评论
请问是否能把一个ADC值转换成两个字节用来设置PWM占空比?
3181 浏览 3 评论
请问电源和晶体值之间有什么关系吗?PIC在正常条件下运行4MHz需要多少电压?
2232 浏览 5 评论
743浏览 1评论
629浏览 1评论
有偿咨询,关于MPLAB X IPE烧录PIC32MX所遇到的问题
512浏览 1评论
PIC Kit3出现目标设备ID(00000000)与预期的设备ID(02c20000)不匹配。是什么原因
642浏览 0评论
538浏览 0评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-11-30 05:21 , Processed in 1.525611 second(s), Total 82, Slave 72 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号