完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
如果有人能给我一些帮助,让我知道如果我的计算/理解是正确的或不正确的,与配置PIC16F628 A PWM信号有关,这将是最有帮助的。我使用一个20MHz振荡器晶体与16F628 A,并试图通过RB3引脚输出PWM信号。在RB3上输出的ACH信号需要64微秒长,我计算为15625Hz((1/64)x 1000000)。前4微秒设置为低/关(TOFF),剩下的60微秒设置为高/开(吨)。因此,我计算TOFF为6.25%和吨为93.75%。1。将PWM周期写入到PR2寄存器:15625Hz脉冲在93.75%占空比周期=[PR2+1] 1×4×ToSc x TMR2预值,这可以被重新排列成:PR2= FoCC--------------------------1 fPultX time2 PrimeX-X4问题1:假设Fosc =实习生Al晶体频率为400 000 HZ问题2:我假设F脉冲=15625HZQuasm 3的脉冲频率:我不理解为什么Time2 PraseL= 4PR2=4000000 --------------- 1=15×15625×4×42)设置CCPR1L:CCP1CON比特和5:4& gt;占空比(吨)占空比=(CCPR1L)可将CCPR1L:CCP1CON位和5:4GT=占空比X FoCC------------------TMR2预置值,其中CCPR1L:CCP1CON/LT;5:4/G.值在CCPR1L寄存器和比特4和BI中。t=5=0.9375=0.00006=93.75%(15625Hz的周期):15625 CCPR1L:CCP1CON/LT;5:4=0.00006×4000000=---------= 60,现在将这个数转换为二进制=0011 1100ccp1CON位4=0,位5=0CCPR1L= 90001111,因此,我的汇编代码是:使用MPLAB 8.92并加载上面的代码,将调试器工具设置为MPLAB SIM,打开模拟器逻辑分析器,并选择PIC16F628 AUPON的PIN RB3作为代码运行的通道,然后检查逻辑分析仪,我测量了X轴上的4个周期的TOFF和X轴上的60个周期的Ton,总共64个循环。问题4:这会产生在15625Hz的PIN RB3上的PWM信号(1/64个周期=15626Hz)。如果不是,请你解释一下我误解了使用的方法(信息是从谷歌搜索得到的)。
以上来自于百度翻译 以下为原文 It would be most helpful if someone could provide me with some help and let me know if my calculations / understandings are correct or incorrect, relating to configuring a PIC16F628A PWM signal. I'm using a 20mhz oscillator crystal with the 16F628A and trying to output a PWM signal via the RB3 pin. Each signal to be outputted on RB3 needs be 64 microseconds long, which i calculate to be 15625hz ((1/64us) x 1000000). The first 4 microseconds set to low/off (Toff) and the remaining 60 microseconds set to high/on (Ton). Therefore, I calculate Toff to be 6.25% and Ton to be 93.75%. 1. Set the PWM period by writing to the PR2 register: 15625hz pulse at a 93.75% duty cycle Period= [PR2 + 1] x 4 x Tosc x TMR2-prescale-value This can be rearranged to: PR2= Fosc --------------------------------- - 1 Fpulse x Timer2-prescale x 4 QUESTION 1: I am assuming Fosc = the internal crystal frequency of 4000000hz QUESTION 2: I am assuming Fpulse = frequency of pulse of 15625hz QUESTIOM 3: I am not understanding why Timer2-prescale = 4 PR2= 4000000 ----------------- - 1 = 15 15625 x 4 x 4 2) Set CCPR1L:CCP1CON bits<5:4> to the duty cycle (Ton) Duty cycle= (CCPR1L:CCP1CON bits<5:4>) x Tosc x TMR2-prescale-value This can be rearranged to: CCPR1L:CCP1CON bits<5:4> = Duty cycle x Fosc -------------------- TMR2-prescale-value Where CCPR1L: CCP1CON<5:4> means- value in CCPR1L register and bit 4 and bit 5 of CCP1CON register Duty cycle = 0.9375 -------- = 0.00006 (93.75% of period of 15625hz) 15625 CCPR1L: CCP1CON<5:4>= 0.00006 x 4000000 ---------------------- = 60 4 Now convert this number to binary = 0011 1100 CCP1CON bit 4= 0, bit 5=0 CCPR1L= 00001111 Therefore, my assembly code is; list p=16F628a #include p16f628a.inc ;****************************************************************************************** __CONFIG _BOREN_OFF & _CP_OFF & _CPD_OFF & _PWRTE_ON & _WDT_OFF & _LVP_OFF & _MCLRE_ON & _HS_OSC ;****************************************************************************************** org 00h ; start address goto START ; start of code org 04h ; start address of interrupt retfie ; start of interrupt code ;****************************************************************************************** START movlw b'00000000' ; Sets inputs and output for PORTA movwf TRISA ; Sets the ports for PORTA banksel TRISA ; Change to the bank with TRISA movlw b'00000000' ; Sets inputs and output for PORTB movwf TRISB ; Sets the ports for PORTB banksel PORTB ;STEP 1: Set the PWM period by writting to the PR2 register ;------------------------------------------------------------------------------- banksel PR2 movlw d'15' movwf PR2 ;STEP 2: Set the PWM duty cycle by writing to CCPR1L & CCP1CON ;-------------------------------------------------------------------------------------------- banksel TMR2 movlw b'00001111' movwf CCPR1L movlw b'00001100' movwf CCP1CON ;Set the TMR2 prescale value and enable TIMER2 by writing to T2CON ;---------------------------------------------------------------------------------------------- movlw b'00000101' ; 01 Bit 0&1 control Prescale (00=1:1, 01=1:4, 1x=1:16 division) ; 1 Bit 2: 1=Timer On, 0=Timer Off ; 0000 Bit 3 to 6 control Postscale (0000=1:1 division) movwf T2CON LOOP goto LOOP end Using MPLAB 8.92 and loading the above code, setting the Debugger tool to MPLAB SIM, opening the Simulator Logic Analyser and selecting the channel as pin RB3 of the PIC16F628A Upon running the code briefly and then examining the logic analyser, I measured the Toff at 4 cycles on the x-axis and Ton at 60 cycles on the x-axis, total 64 cycles. QUESTION 4: Will this produce a PWM signal on pin RB3 of 15625hz (1/64 cycles = 15626hz). If not, could you please try to explain where i have misunderstood the method to use (information has been obtained from Google searching). Many thanks Adrian |
|
相关推荐
2个回答
|
|
1 -非常糟糕的假设。如果你使用的是20MHz晶体,那么Fosc是20MHz,所以ToSc= 50ns。我很好奇你是怎么想到一个20MHz晶体的结果是4MHZ?你把Fosc和指令钟混为一谈了吗?这将是FoCC/4=5MHz,所以TCYC=1/5MHZ=200 NS2 -当然,如果需要的话,您可以定义FPASK为1/PWM周期。我可能会使用FPWM3——如果你想要64个周期,TMR2需要计数64个/200个NS=320,这太高了,所以设置预分频器为4。因此,PR2+ 1=320/4=80,或PR2=794——因为Fosc是计算中使用的频率的5倍,乘以60×5=300的占空比寄存器设置以获得您所需的脉冲形状,我看的方式是-& gt;PR2+1=80,并且从预分频器中使用2个以上的比特来生成10位。所以80×4=每个周期320个时钟。320*(60/64)=300和-t;将值放在占空比寄存器中。祝你们好运。
以上来自于百度翻译 以下为原文 1 - Very bad assumption. If you're using a 20MHz crystal, then Fosc is 20MHz, so Tosc = 50ns. I'm curious how you got the idea a 20MHz crystal results in 4MHz Fosc? Are you confusing Fosc with the instruction clock? That would Fosc/4 = 5MHz so Tcyc = 1/5Mhz = 200ns 2 - Sure, you can define Fpulse as 1/PWM period if you want. I would probably use Fpwm 3 - If you want 64uS period, TMR2 needs to count 64us/200ns = 320 which is too high, so set prescaler to be 4. So PR2+1 = 320/4 = 80, or PR2 = 79 4 - Since Fosc is 5 times the frequency used in your calculations, multiply 60*5 = 300 for duty cycle registers setting to get your desired pulse shape The way I would look at is -> PR2+1=80, and 2more bits are used from the prescaler to make 10bits. So 80*4 = 320 clocks per period. 320 * (60/64) = 300 -> the value to put in the duty cycle registers. Good luck. |
|
|
|
非常感谢你的回复马克。我想我对FoSC/4感到困惑,错误地提出了假设,当使用PWM时,时钟速度将自动设置在4MHz。我会通过你的每一个反应,努力得到期望的结果。
以上来自于百度翻译 以下为原文 Thank you very much for your reply Mark. I think I was confused about the Fosc/4 and wrongly came up with the assumption that when using the PWM the clock speed would automatically be set at 4mhz. I will work through each of your responses and try to get the desired results. Regards Adrian |
|
|
|
只有小组成员才能发言,加入小组>>
5161 浏览 9 评论
1999 浏览 8 评论
1928 浏览 10 评论
请问是否能把一个ADC值转换成两个字节用来设置PWM占空比?
3171 浏览 3 评论
请问电源和晶体值之间有什么关系吗?PIC在正常条件下运行4MHz需要多少电压?
2226 浏览 5 评论
731浏览 1评论
613浏览 1评论
有偿咨询,关于MPLAB X IPE烧录PIC32MX所遇到的问题
503浏览 1评论
PIC Kit3出现目标设备ID(00000000)与预期的设备ID(02c20000)不匹配。是什么原因
629浏览 0评论
527浏览 0评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-11-22 20:17 , Processed in 1.120749 second(s), Total 79, Slave 62 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号