• slider image 442
  • slider image 483
  • slider image 484
  • slider image 485
  • slider image 486
  • slider image 487
  • slider image 488
  • slider image 491
:::


Browsing this Thread:   1 Anonymous Users






Re: software PWM 問題請教
#6
新會員
新會員


查看用戶資訊
參照:

shpeng 寫道:
參照:

handy 寫道:
「目標是要做到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都蠻痛苦的。>_<




while(1){
PWM1_PIN = (Timer0 <= Duty1)
PWM2_PIN = (Timer0 <= Duty2)
PWM3_PIN = (Timer0 <= Duty3)
}
可以改這樣嗎? 我不懂 C


上面那個只是概念的code
用組語也可以寫得出來。

大概做法就是用一個Timer定時中斷(1/10k = 0.1ms)
在中斷內把所有的IO拉HIGH

主迴圈內就用Polling的方式看Timer的值是不是超過設定的Duty值。
超過了就切LOW。
這樣就是一個軟體的PWM了。
只是頻率低了點、準度差了點(因為負緣是用Polling做出來的)
基本上有幾根OUTPUT PIN就可以做出幾ch的pwm。

不過。以10khz、8bit的條件,對軟體的做法來說,loading是過大了。

發表於: 2009/6/17 12:04
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: software PWM 問題請教
#5
資深會員
資深會員


查看用戶資訊
參照:

handy 寫道:
「目標是要做到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都蠻痛苦的。>_<




while(1){
PWM1_PIN = (Timer0 <= Duty1)
PWM2_PIN = (Timer0 <= Duty2)
PWM3_PIN = (Timer0 <= Duty3)
}
可以改這樣嗎? 我不懂 C

發表於: 2009/6/17 1:36
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: software PWM 問題請教
#4
新會員
新會員


查看用戶資訊
「目標是要做到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
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: software PWM 問題請教
#3
高級會員
高級會員


查看用戶資訊
频率太高了,不好搞.

直接选dspic系列的吧,有多路pwm输出,应该可以.

發表於: 2009/6/16 9:22
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: software PWM 問題請教
#2
資深會員
資深會員


查看用戶資訊
PWM 10KHz * 256階 = 2.56MHz <== 用軟體中斷,不太可能.

只能用 LOOP 硬跑, 要有其它的功能就難了.

SOFTWARE PWM 6CH 用組語也很困難.

===8749組語派===

發表於: 2009/6/15 22:33
少年不知愁滋味,老來方知路難行。
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


software PWM 問題請教
#1
新會員
新會員


查看用戶資訊
請問板上的先進
小弟目前使用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
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部







You can view topic.
不可以 發起新主題
You cannot reply to posts.
You cannot edit your posts.
You cannot delete your posts.
You cannot add new polls.
You cannot vote in polls.
You cannot attach files to posts.
You cannot post without approval.
You cannot use topic type.
You cannot use HTML syntax.
You cannot use signature.
You cannot create PDF files.
You cannot get print page.

[進階搜尋]


:::

Microchip連結

https://www.facebook.com/microchiptechnologytaiwan/
http://www.microchip.com.tw/modules/tad_uploader/index.php?of_cat_sn=13
https://mu.microchip.com/page/tmu
http://elearning.microchip.com.tw/modules/tad_link/index.php?cate_sn=1
https://page.microchip.com/APAC-PrefCenters-TW.html
http://www.microchip.com/
http://www.microchip.com/treelink
http://www.microchipdirect.com/
http://www.microchip.com.cn/newcommunity/index.php?m=Video&a=index&id=103
http://www.microchip.com.tw/modules/tad_uploader/index.php?of_cat_sn=2
http://www.microchip.com.tw/Data_CD/eLearning/index.html
http://www.microchip.com.tw/RTC/RTC_DVD/
https://www.microchip.com/development-tools/
https://www.youtube.com/user/MicrochipTechnology
[ more... ]

教育訓練中心

!開發工具購買
辦法說明 [業界客戶] [教育單位]
----------------------------------
!校園樣品申請
辦法說明 [教師資格] [學生資格]
----------------------------------