• 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: 為何終端機顯示之VR2電壓值無法停止??
#2
管理員
管理員


查看用戶資訊
你好,
程式中因為在 Timer2 中斷不斷的叫用 Read_VR2() , Show_ADC 以及更新 OCR1. 所以當然停不住啦.

void _ISR _T2Interrupt(void)
{
OC1RS=Read_VR2( );
Show_ADC( ) ; // 將類比轉換結果顯示
OC1R = ADCBUF0<<6 ;
// SetPulseOC1(ADCBUF0<<6, 0x0000) ; // 重新設定OC1波寬

LED1=!LED1;
IFS0bits.T2IF = 0 ;

}

在 main() 中, 程式的最後為 while(1); 你可以將 _T2Interrupt()的動作剪下然後貼到 main() 的最後 .

>> 原本為 while(1) ;
>> 改為
while(1)
{
while( SWn_Status ) ;

OC1RS=Read_VR2( );
Show_ADC( ) ; // 將類比轉換結果顯示
OC1R = ADCBUF0<<6 ;

}
>> 如此就可以按一次鍵就只送一次 , 但你要自己定義 SWn_Status 到底指向哪一個 Input 腳, 而且沒按鍵的話是被 pill-high 的 :)

祝你順利 !!


發表於: 2008/5/8 23:23
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


為何終端機顯示之VR2電壓值無法停止??
#1
新會員
新會員


查看用戶資訊
各位高手您好:
小弟目前使用APP020(MCU為DSPIC30F4011)這塊實驗版上之可變電阻VR2調變PWM訊號之DUTY,而當按下電腦鍵盤上任何一個鍵時便可將VR2上之電壓值顯示電腦上之超級終端機,目前利用VR2改變PWM訊號DUTY之動作OK,但是只要當我ㄧRUN程式時,VR2之電壓值便不斷的顯示於超級終端機上(不斷自動換行顯示VR2之數值),而調整VR2時於終端機上芝VR2會改變,但一樣會不斷重複換行顯示VR2數值,想請問各位高手,是否有辦法當我按下鍵盤時才讓終端機顯示VR2數值一次,而不是一直自動重複顯示而不受鍵盤控制。以下是我的程式內容(有點冗長,還麻煩各位幫我看一下),是否是因為ADC或UART未設定好呢??我已經困擾許久了,拜託各位協助了!!

#include <p30fxxxx.h>
#include <adc10.h> // 將adc10函式的原型宣告檔案含入
#include <timer.h> // 將Timer函式的原型宣告檔案含入
#include <uart.h>
#include <outcompare.h> // 將Compare函式的原型宣告檔案含入

#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[]="\r\nExercise 13 - OC\r\n" ;

#define LED1 LATEbits.LATE0
#define CTRL_LED1 TRISEbits.TRISE0

void Init_ADC(void) ;
void Init_Timer2(void);
void Init_UART(void) ;
void Show_ADC(void) ;
unsigned int Read_VR2(void);
void Init_OC1(void) ;

void _ISR _T2Interrupt(void)
{
OC1RS=Read_VR2( );
Show_ADC( ) ; // 將類比轉換結果顯示
OC1R = ADCBUF0<<6 ;
// SetPulseOC1(ADCBUF0<<6, 0x0000) ; // 重新設定OC1波寬

LED1=!LED1;
IFS0bits.T2IF = 0 ;

}

int main( void )
{
SRbits.IPL=4;

Init_ADC( ) ; // 將ADC進行初始化設定
Init_UART( ) ; // 對 UART 模組作初始化設定

putsUART1( (unsigned int *) My_String1 ) ;
Init_Timer2( );
Init_OC1();
TRISDbits.TRISD0=0;
CTRL_LED1 = 0 ;

while(1);
}

/***********************************************/
// Subroutine to configure the OC module

void Init_OC1(void)
{
CloseOC1();

ConfigIntOC1(OC_INT_OFF & OC_INT_PRIOR_7);
// IEC0bits.OC1IE = 0 ;
// IFS0bits.OC1IF = 0 ;
// IPC0bits.OC1IP = 7 ;

OpenOC1(OC_IDLE_CON & OC_TIMER2_SRC &
OC_PWM_FAULT_PIN_DISABLE, 0, 0);
// OC1CON= 0x0006;
}

/***********************************************/
// Subroutine to configure the A/D module

void Init_ADC(void)
{

unsigned int Channel, PinConfig, Scanselect, Adcon3_reg, Adcon2_reg, Adcon1_reg;

ADCON1bits.ADON = 0; /* turn off ADC */

PinConfig = ENABLE_AN0_ANA; // Select port pins as analog inputs ADPCFG<15:0>

Adcon1_reg = ADC_MODULE_ON & // Turn on A/D module (ADON)
ADC_IDLE_STOP & // ADC turned off during idle (ADSIDL)
ADC_FORMAT_INTG & // Output in integer format (FORM)
ADC_CLK_MANUAL & // Conversion trigger manually (SSRC)
ADC_SAMPLE_INDIVIDUAL & // Sample channels individually (SIMSAM)
ADC_AUTO_SAMPLING_OFF; // Sample trigger manually (ASAM)

Adcon2_reg = ADC_VREF_AVDD_AVSS & // Voltage reference : +AVdd, -AVss (VCFG)
ADC_SCAN_OFF & // Scan off (CSCNA)
ADC_ALT_BUF_OFF & // Use fixed buffer (BUFM)
ADC_ALT_INPUT_OFF & // Does not alternate between MUX A & MUX B (ALTS)
ADC_CONVERT_CH0 & // Convert only channel 0 (CHPS)
ADC_SAMPLES_PER_INT_1; // 1 sample between interrupt (SMPI)

Adcon3_reg = ADC_SAMPLE_TIME_10 & // Auto-Sample time (SAMC)
ADC_CONV_CLK_SYSTEM & // Use system clock (ADRC)
ADC_CONV_CLK_4Tcy; // Conversion clock = 4 Tcy (ADCS)
// ADCS = 2*(154ns)/(1/Fcy)-1 = 3.5416

Scanselect = SCAN_NONE; // ADC scan no channel (ADCSSL)

OpenADC10(Adcon1_reg, Adcon2_reg, Adcon3_reg, PinConfig, Scanselect);

Channel = ADC_CH0_POS_SAMPLEA_AN0 & // CH0 Pos. : AN0, Neg. : Nominal Vref- Defined in ADCON2
ADC_CH0_NEG_SAMPLEA_NVREF ; // (ADCHS)
SetChanADC10(Channel);

ConfigIntADC10(ADC_INT_DISABLE); // Disable ADC interrupt

}

/***********************************************/
// Subroutine to configure the Timer 2

void Init_Timer2(void)
{
ConfigIntTimer2( T2_INT_PRIOR_6 & T2_INT_ON ) ; // Timer2 的中斷優先等級設 6
// Timer2 的中斷 OFF

OpenTimer2( T2_ON & T2_IDLE_STOP & T2_GATE_OFF & // Timer2 的 Period 設為每 64ms
T2_PS_1_1 & T2_32BIT_MODE_OFF &
T2_SOURCE_INT,
1023) ;
}
/***********************************************/
// Subroutine to read analog voltage from VR2

unsigned int Read_VR2(void)
{
unsigned char Loop ;

ADCON1bits.SAMP = 1; // start sampling ...

for ( Loop = 0 ; Loop < 100 ; Loop ++ );

ConvertADC10();
while (BusyADC10()); // conversion done?
return ADCBUF0 ; // get ADC value
}

/***********************************************/
// Subroutine to initialize UART module

void Init_UART(void)
{
/* Holds the value of baud register */
unsigned int baudvalue;
/* Holds the value of uart config reg */
unsigned int U1MODEvalue;
/* Holds the information regarding uart
TX & RX interrupt modes */
unsigned int U1STAvalue;
/* Turn off UART1module */
CloseUART1();
/* Configure uart1 receive and transmit interrupt */
ConfigIntUART1(UART_RX_INT_EN & UART_RX_INT_PR6 &
UART_TX_INT_DIS & UART_TX_INT_PR2);
/* Setup the Buad Rate Generator */
baudvalue = 95; //UxBRG = ( (FCY/Desired Baud Rate)/16) – 1
//UxBRG = ( (7372800*2/9600)/16-1) = 95
/* Configure UART1 module to transmit 8 bit data with one stopbit.
Also Enable loopback mode */
U1MODEvalue = UART_EN & UART_IDLE_CON &
UART_DIS_WAKE & UART_DIS_LOOPBACK &
UART_DIS_ABAUD & UART_NO_PAR_8BIT &
UART_1STOPBIT;
U1STAvalue = UART_INT_TX_BUF_EMPTY &
UART_TX_PIN_NORMAL &
UART_TX_ENABLE & UART_INT_RX_CHAR &
UART_ADR_DETECT_DIS &
UART_RX_OVERRUN_CLEAR;
OpenUART1(U1MODEvalue, U1STAvalue, baudvalue);

return;

}

/***********************************************/
// Subroutine to show ADC on UART

void Show_ADC(void)
{
unsigned char Loop ;
unsigned int ADCValue;
unsigned char TXdata[4];
ADCON1bits.SAMP = 1; // start sampling ...

for ( Loop = 0 ; Loop < 100 ; Loop ++ );

ConvertADC10();
while (BusyADC10()); // conversion done?
ADCValue = (ADCBUF0 >> 2); // get ADC value

sitoa(ADCValue, (unsigned char *)TXdata);

putsUART1( (unsigned int *) "VR2 : ");
putsUART1( (unsigned int *) TXdata ) ;
putsUART1( (unsigned int *) "\r\n" );

}

//***********************************************
// Put a unsigned byte in decimal format
// to UART Module

void sitoa( unsigned char The_Number, unsigned char *buff)
{

unsigned char Temp_Char_100, Temp_Char_10, Temp_Char ;
unsigned char *temp = (unsigned char *)buff ;

Temp_Char_100 = The_Number /100 ; //取百位數的數字
temp[0] = Temp_Char_100 + '0' ; //取百位數的數字
Temp_Char_10 = (The_Number - Temp_Char_100*100) /10 ; //取十位數的數字
temp[1] = Temp_Char_10 + '0' ; //取十位數的數字
Temp_Char = The_Number - ( Temp_Char_100*100 + Temp_Char_10 * 10 ) ; //取個位數的數字
temp[2] = Temp_Char + '0' ; //取個位數的數字
temp[3] = 0 ;
}

發表於: 2008/5/8 22:17
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... ]

教育訓練中心

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