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


Browsing this Thread:   1 Anonymous Users






Re: 輸入捕捉
#4
初級會員
初級會員


查看用戶資訊
[quote]
Ryang 寫道:

如果待量測的 Period 為 10KHz,那 Capture 的計數頻率就要 10MHz,這樣才可以準到 0.1% 的精度。

Capture 的計數頻率是指FCY 還是timer,

如果是timer要設定哪個暫存器?

可以舉例嗎?

發表於: 2009/4/10 16:27
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: 輸入捕捉
#3
初級會員
初級會員


查看用戶資訊
那他的範例程式該如何修改?

我有試著去改,但一直都改不出來 ==

define __dsPIC30F4011__

#include <p30F4011.h>
#include "C30EVM_LCD.h" // 將函式的原型宣告檔案含入
#include <timer.h>
#include <InCap.h>

#define FCY 7372800 * 2 // 因為使用頻率為將外部 7.3728 MHz * 8 的模式 , 每一指令週期需 4 個 clock
// 所以 FCY = (7.3728 * 8 / 4 ) MHz = 7372800* 2

_FOSC(CSW_FSCM_OFF & XT_PLL8); // XT with 8xPLL oscillator, Failsafe clock off
_FWDT(WDT_OFF); // Watchdog timer disabled
_FBORPOR(PBOR_OFF & MCLR_EN); // Brown-out reset disabled, MCLR reset enabled
_FGS(CODE_PROT_OFF); // Code protect disabled

const char My_String1[]=" Capture" ; // 宣告字串於 Program Memory
const char My_String2[]="Duty Cycle: %" ; // 宣告字串於 Data Memory

void uitoa( unsigned char * , unsigned int ) ;

int Interrupt_Count = 0 , Int_flag;
unsigned int timer_edge[4];
unsigned char phase, phase2, phase3, Convert_Buf[10];

void _ISR _IC7Interrupt(void)
{
Interrupt_Count++;
switch(Interrupt_Count) // 根據輸入捕捉的次數決定執行的動作
{
case(1): // 第一次,儲存訊號的電位狀態
phase = PORTBbits.RB4 ;
break;
case(2): // 第二次,儲存訊號的電位狀態
phase2 = PORTBbits.RB4 ;
break;
case(3):
ReadCapture7(timer_edge); // 第三次,將所有的輸入捕捉暫存器數值讀出
phase3 = PORTBbits.RB4 ; // 並儲存訊號的電位狀態
break;
}
Int_flag = 1;
IFS1bits.IC7IF = 0;
}

int main(void)
{
unsigned int period1, period2;
unsigned int duty;

ADPCFG = 0xffff; // Set All Analog Pins as Digital IO

OpenLCD( ) ; // 使用 OpenLCD( )對 LCD 模組作初始化設定
// 4 bits Data mode
// 5 * 7 Character

setcurLCD(0,0) ; // 使用 setcurLCD( ) 設定游標於 (0,0)
putrsLCD( My_String1 ) ; // 將存在 Program Memory 的字串使用
// putrsLCD( ) 印出至 LCD

setcurLCD(0,1) ;
putrsLCD( My_String2 ) ; // 使用 setcurLCD( ) 設定游標於 (0,1)
// 將存在 Data Memory 的字串使用
// putsLCD( ) 印出至 LCD


T3CON = 0x8000; /* Timer 3 On */
/* Configure the InputCapture in stop in idle mode , Timer
3 as source , interrupt on capture 1, I/C on every edge */
OpenCapture7(IC_IDLE_STOP & IC_TIMER3_SRC & IC_INT_1CAPTURE & IC_EVERY_EDGE);

/* Enable Timer1 Interrupt and Priority to '1' */
ConfigIntCapture7(IC_INT_PRIOR_7 & IC_INT_ON);

Int_flag = 0;

while(1)
{
while(!Int_flag); /* wait here till first capture event */
Int_flag = 0;
while(!Int_flag); /* wait here till next capture event */
Int_flag = 0;
while(!Int_flag); /* wait here till last capture event */
DisableIntIC7;
Int_flag = 0;

/* calculate time count between two capture events */
if( timer_edge[1] >= timer_edge[0])
period1 = timer_edge[1] - timer_edge[0];
else
period1 = 65536 + timer_edge[1] - timer_edge[0];

/* calculate time count between two capture events */
if( timer_edge[2] >= timer_edge[1])
period2 = timer_edge[2] - timer_edge[1];
else
period2 = 65536 + timer_edge[2] - timer_edge[1];

if (phase)
duty = 100*((float)period1/(period1+period2));
else
duty = 100*((float)period2/(period1+period2));

uitoa ( Convert_Buf , duty ) ;
setcurLCD(12,1) ;
putrsLCD( " " ) ;

setcurLCD(12,1) ;
putsLCD( Convert_Buf ) ;

Interrupt_Count = 0;
IFS1bits.IC7IF = 0;
ReadCapture7(timer_edge);
EnableIntIC7;
}
CloseCapture7();
}

void uitoa( unsigned char *ASCII_Buf , unsigned int IntegerValue )
{

unsigned int TempValue ;
unsigned char ZeroDisable ;
unsigned int BaseQty ;
unsigned int Loop ;

ZeroDisable = 1 ;
BaseQty = 10000 ;

for ( Loop = 0 ; Loop < 4 ; Loop ++)
{
TempValue = IntegerValue / BaseQty ;

if ( TempValue > 0)
{
*ASCII_Buf++ = (unsigned char)TempValue + '0' ;
ZeroDisable = 0 ;
}
else if ( ZeroDisable == 0 )
*ASCII_Buf++ = '0' ;
IntegerValue = IntegerValue - ( TempValue * BaseQty ) ;
BaseQty = BaseQty / 10 ;

}
*ASCII_Buf++ = (unsigned char)IntegerValue + '0' ;
*ASCII_Buf = (unsigned char) 0x00 ;

}

發表於: 2009/3/30 18:59
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: 輸入捕捉
#2
版主
版主


查看用戶資訊
基本算數問題,也就是說待量測的輸入訊號的 Period 與 Capture 的計數 Clock 比率要有 1000 的倍率。

如果待量測的 Period 為 10KHz,那 Capture 的計數頻率就要 10MHz,這樣才可以準到 0.1% 的精度。

發表於: 2009/3/30 14:38
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


輸入捕捉
#1
初級會員
初級會員


查看用戶資訊
請問使用輸入捕捉模組

要捕捉到 PWM duty cycle 0.1% 的變化

而且可以顯示到LCD上

該如何寫程式

我使用的是dsPIC30F4011 APP020的板子

我有買曾百由老師寫的書

跑了範例程式

但它沒有顯示到0.1%的變化

我試著改它的程式

但始終改不出來

請問各位高手

我該如何修改呢?

發表於: 2009/3/30 11:11
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... ]

教育訓練中心

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