Re: software PWM 問題請教
|
||||
---|---|---|---|---|
資深會員
|
參照:
while(1){ PWM1_PIN = (Timer0 <= Duty1) PWM2_PIN = (Timer0 <= Duty2) PWM3_PIN = (Timer0 <= Duty3) } 可以改這樣嗎? 我不懂 C
發表於: 2009/6/17 1:36
|
|||
|
Re: software PWM 問題請教
|
||||
---|---|---|---|---|
新會員
|
「目標是要做到6 channel 的PWM (10khz 8bit)」
既然說是Software PWM了, 那就用Polling的方式來做嚕 不過準度不好就是了。 概念像下面這樣: //------------------------------------------ void Timer0_ISR(void){ PWM1_PIN = HIGH; PWM2_PIN = HIGH; PWM3_PIN = HIGH; PWM4_PIN = HIGH; PWM5_PIN = HIGH; PWM6_PIN = HIGH; RESET_TIMER0(); } //------------------------------------------ void main(void){ Initial(); //...etc. while(1){ if(Timer0 >= Duty1){ PWM1_PIN = LOW; } if(Timer0 >= Duty2){ PWM2_PIN = LOW; } //....etc. } } //======================= ps.這個留言版系統可以把Tab鍵的功能做進來嗎? 沒有Tab,每次看code都蠻痛苦的。>_<
發表於: 2009/6/16 9:50
|
|||
|
Re: software PWM 問題請教
|
||||
---|---|---|---|---|
高級會員
|
频率太高了,不好搞.
直接选dspic系列的吧,有多路pwm输出,应该可以.
發表於: 2009/6/16 9:22
|
|||
|
Re: software PWM 問題請教
|
||||
---|---|---|---|---|
資深會員
|
PWM 10KHz * 256階 = 2.56MHz <== 用軟體中斷,不太可能.
只能用 LOOP 硬跑, 要有其它的功能就難了. SOFTWARE PWM 6CH 用組語也很困難. ===8749組語派===
發表於: 2009/6/15 22:33
|
|||
少年不知愁滋味,老來方知路難行。
|
||||
|
software PWM 問題請教
|
||||
---|---|---|---|---|
新會員
|
請問板上的先進
小弟目前使用PICDEM FS USB的開發板(OSC=20mhz)pic18f4550的timer1中斷,可以加減DUTY這個變數讓他在0-255之間能夠運作 目標是要做到6 channel 的PWM (10khz 8bit) 目前遇到的問題如下: 1.現在只用一個channel判斷式,只能達到1.44khz 2. 設定OSC的地方是system clock[osc1:osc2 src/1][PLL96mhz/2] 可是在man loop下面如果單存用 while(1) RC1^=1; 這樣子看大約只有2Mhz ,如果以設定system clk的96mhz/2=48mhz,不是應該是48/4=12mhz,可是實際上怎麼只有2mhz??不知這樣有錯誤嗎? 3.或是請先進推薦六組pwm的MCU,小弟有看到8ch pwm不過好像都是配合馬達DECORDER的,可以拿來當獨立的PWM嗎? 先謝過各位囉~~~~ //************************************************ //* Function: Initialize Timer1 * //************************************************ void InitializeTMR1(void) { T1CON=0x80; /* we are testing TIMER1 */ T1CKPS1=0; /*update values of prescalar bits*/ T1CKPS0=0; T1OSCEN=0; TMR1IF=0; /* Clear overflow flag*/ TMR1IE=1; /* Enable TIMER1 interrupts */ TMR1=0; /*Load initial value to TIMER1*/ TMR1ON=1; } Timer_Count=10; //***************************************// if (TMR1IF) { Duty_cnt++; if(Duty_cnt>=Duty) RC1=1; else RC1=0; TMR1H = (0xFFFF-Timer_Count)/256; TMR1L = (0xFFFF-Timer_Count)%256; TMR1IF=0; // Clear interrupt flag of Timer 1 }//end timer1 interrupt //***************************************//
發表於: 2009/6/15 15:24
|
|||
|