完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
你好。我使用PIC16F690生成全桥PWM,后者将被滤波以产生正弦波形。问题是P1B、P1C、P1D除P1A外都看不到波形,但是在P1A上只显示PWM而不是有源高波形。代码如下:
以上来自于百度翻译 以下为原文 Hi. I'm using PIC16F690 to generate PWM for full bridge which will be filtered later to create sinusoidal waveform. The problem is I can't see any waveform on it's P1B, P1C, P1D except P1A. However on P1A it is showing PWM instead of active high waveform only. The code is as below, #include #include #include #include #define _XTAL_FREQ 20000000 void init_micro (void); void init_pwm_pos (void); void init_pwm_neg (void); void pwm_dr(unsigned int dr); void gen_sin(void); void init_pdr_array (void); static int pdr, pdr_array[27]; void main (void) { init_micro(); init_pdr_array(); do { init_pwm_pos(); gen_sin(); init_pwm_neg(); gen_sin(); } while(1); } void init_micro (void) { OSCCON= 0b00001000; // EXTERNAL HS OSCILLATOR TRISA = 0b11101111; TRISB = 0b00111111; TRISC = 0b10000011; ANSEL = 0b00010000; ANSELH =0b00001100; PORTC = 0b00000000; } void gen_sin(void) { int i; for(i = 1; i < 25; i++) { pdr = pdr_array; pwm_dr(pdr); __delay_us(204); } for(i = 24; i > 0; i--) { pdr = pdr_array; pwm_dr(pdr); __delay_us(204); } } void init_pdr_array(void) { pdr_array[0] = 0; //[0] INTENTIALLY STOPPED TO OCCURE pdr_array[1] = 66; pdr_array[2] = 131; pdr_array[3] = 196; pdr_array[4] = 261; pdr_array[5] = 324; pdr_array[6] = 386; pdr_array[7] = 446; pdr_array[8] = 504; pdr_array[9] = 560; pdr_array[10] = 614; pdr_array[11] = 666; pdr_array[12] = 714; pdr_array[13] = 760; pdr_array[14] = 803; pdr_array[15] = 842; pdr_array[16] = 878; pdr_array[17] = 910; pdr_array[18] = 938; pdr_array[19] = 962; pdr_array[20] = 983; pdr_array[21] = 999; pdr_array[22] = 1012; pdr_array[23] = 1020; pdr_array[24] = 1024; } void init_pwm_pos (void) { TRISC = 0b10111111; //DISABLE OUTPUT PR2 = 255; CCP1CON = 0b01001100; //ACTIVE HIGH, FULLBRIDGE A & D OUTPUT pdr = 0; pwm_dr(pdr); PIR1 = (PIR1 | 2); T2CON = 0b00000101; //POST SCALER 1:1, PRE 1:4 TIMER ON while(!(PIR1 & 2)); TRISC = 0b10000011; //ENABLE OUTPUT TMR2 = 0; } void init_pwm_neg (void) { TRISC = 0b10111111; //DISABLE OUTPUT PR2 = 255; CCP1CON = 0b11001100; //ACTIVE HIGH, FULLBRIDGE B & C OUTPUT pdr = 0; pwm_dr(pdr); PIR1 = (PIR1 | 2); T2CON = 0b00000101; //POST SCALER 1:1, PRE 1:4 TIMER ON while(!(PIR1 & 2)); TRISC = 0b10000011; //ENABLE OUTPUT TMR2 = 0; } void pwm_dr(unsigned int dr) { CCPR1L = (dr >> 2); CCP1CON = ((CCP1CON & 0xF) + ((dr << 4) & 0x30)); // set bits 4 and 5 } |
|
相关推荐
2个回答
|
|
嗨,在pMMyDR(…)函数中存在一个错误,导致Cp1CON寄存器的P1M字段被擦除。用于保持寄存器的先前内容的掩码值0xf是错误的。您可以这样尝试:那么,当PDRIL数组(24)中的值太大时,导致分配占空比的值为0。CCPR1L。这会在波的峰值处产生2个间隔的毛刺。关于,Mysil。
以上来自于百度翻译 以下为原文 Hi, There is a bug in pwm_dr(...) function causing the P1M field of CCP1CON register to become erased. The mask value 0xF used to keep previous content of the register was wrong. You may try like this: void pwm_dr(unsigned int dr) { CCPR1L = (dr >> 2); CCP1CON = ((CCP1CON & 0xCF) + ((dr << 4) & 0x30)); // set bits 4 and 5 } Then, the value in pdr_array[24] is too large, causing the duty cycle value to be 0, when assigned to CCPR1L. This will cause a glitch for 2 intervals at the peak of the wave. Regards, Mysil |
|
|
|
|
|
|
|
只有小组成员才能发言,加入小组>>
5166 浏览 9 评论
2000 浏览 8 评论
1929 浏览 10 评论
请问是否能把一个ADC值转换成两个字节用来设置PWM占空比?
3175 浏览 3 评论
请问电源和晶体值之间有什么关系吗?PIC在正常条件下运行4MHz需要多少电压?
2227 浏览 5 评论
736浏览 1评论
619浏览 1评论
有偿咨询,关于MPLAB X IPE烧录PIC32MX所遇到的问题
507浏览 1评论
PIC Kit3出现目标设备ID(00000000)与预期的设备ID(02c20000)不匹配。是什么原因
633浏览 0评论
530浏览 0评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-11-25 10:42 , Processed in 1.152431 second(s), Total 83, Slave 65 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号