• slider image 442
  • slider image 492
  • slider image 493
  • slider image 494
  • slider image 495
  • slider image 496
  • slider image 491
:::


Browsing this Thread:   1 Anonymous Users






Re: AD轉換
#8
中級會員
中級會員


查看用戶資訊
你可以改寫成
if(ADCValue1 > (90 << 2))

或是
if(ADCValue1 > (90*4))

或是
if(ADCValue1 > 360)

其實AD轉換出來的是10bit所以是0~1023
但是put_Num_LCD()這個副程式只能顯示三位數的數字
所以顯示的時候強迫把AD 10bit的解析度降成8bit了

發表於: 2010/2/2 14:55
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: AD轉換
#7
新會員
新會員


查看用戶資訊
應該是這樣,請問要怎麼更改程式才可以讓LCD顯示90時做切換動作呢?

發表於: 2010/2/2 13:43
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: AD轉換
#6
中級會員
中級會員


查看用戶資訊
因為LCM秀出來的值是ADCValue1 >> 2
所以你設定的if(ADCValue1>90)會讓RE0 = 0

就上面的程式是看到LCM顯示22以下的時候LED1就會亮,並不會在90的時候做切換

不知道你的問題是不是在這裡?還是我會錯意

發表於: 2010/2/2 10:58
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: AD轉換
#5
新會員
新會員


查看用戶資訊
以下是所有的程式碼,LED燈不會改變他的狀態,找了兩、三天還是找不到問題


// ***********************************************************************
// File : EX11_4_ADC_Multi_Sim.C
// Purpose : 練習如何叫 Microchip C30 提供的 ADC 函式庫
//
// 使用的函式 :
// ConfigIntTimer1( )
// OpenTimer1( )
// BusyADC10()
// CloseADC10()
// ConfigintADC10()
// ConvertADC10()
// OpenADC10()
// ReadADC10()
// SetChanADC10()
//
// 動作 :
// 將 LCD 初始化成 2 行 5*7 文字模式
// 使用 C30EVM_LCD.c 中的副程式顯示下列字串
//
// Exercise 11- ADC
// VR1:XXX VR2:YYY
//
// 將 Timer 1 規劃成 Period 為 1 ms 的 Timer
// 使用中斷的技巧 , 在 ISR 檢查是否已計時 1 秒
// 若是 , 則進行多通道類比訊號轉換,並將轉換結果顯示於LCD
//
// ADC模組設定:多通道類比轉換,同時採樣、逐次轉換
//
// ***********************************************************************

#define __dsPIC30F4011__

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

#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[]="Exercise 11- ADC" ; // 宣告字串於 Program Memory (因為 const 宣告)
char My_String2[]="VR1: VR2: " ; // 宣告字串於 Data Memory

void Init_ADC(void) ;
void Show_ADC(void) ;

unsigned miliSec = 0 ;
unsigned int ADCValue1,ADCValue2;

union {
unsigned char ByteAccess ;
struct {
unsigned Bit0: 1 ;
unsigned Bit1: 1 ;
unsigned Bit2: 1 ;
unsigned unused : 5 ;
} ;
} SystemFlag ;



#define OneSecond SystemFlag.Bit0

void _ISR _T1Interrupt(void)
{

miliSec += 1 ;

if (miliSec == 1000)
{
OneSecond = 1 ;
miliSec = 0 ;
}
IFS0bits.T1IF = 0 ;

}

int main( void )
{

Init_ADC( ) ; // 將ADC進行初始化設定

OpenLCD( ) ; // 使用 OpenLCD( )對 LCD 模組作初始化設定
// 4 bits Data mode
// 5 * 7 Character
TRISE = 0xFFF0;
LATE = 0xFFFF;
//LATEbits.LATE0 = 0;

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

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

ConfigIntTimer1( T1_INT_PRIOR_7 & T1_INT_ON ) ; // Timer1 的中斷優先等級設 7 (最高)
// Timer1 的中斷 ON

OpenTimer1( T1_ON & T1_IDLE_STOP & T1_GATE_OFF & // Timer1 的 Period 設為每 1ms
T1_PS_1_1 & T1_SYNC_EXT_OFF & T1_SOURCE_INT ,
(FCY/ 1000) ) ;

OneSecond = 0 ;

while(1)
{
if ( OneSecond ) // 詢問 Timer1 的 Period 時間是否已到

{
OneSecond = 0 ;

Show_ADC( ) ; // 將類比轉換結果顯示於 LCD 上

}
}
}

/***********************************************/
// 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>
ENABLE_AN1_ANA ;

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_AUTO & //*Conversion trigger automatically (SSRC)
ADC_SAMPLE_SIMULTANEOUS & //*重要修改:Sample channels simultaneously (SIMSAM)
ADC_AUTO_SAMPLING_OFF & //*重要修改:Sample trigger automatically (ASAM)
ADC_SAMP_OFF ; //

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_CH_0A & // Convert only channel 0 (CHPS)
ADC_SAMPLES_PER_INT_1; //*重要修改:2 samples between interrupt (SMPI)

Adcon3_reg = ADC_SAMPLE_TIME_16 & // 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
// TAD = (ADCS+1)/(2*Fcy) = 169.54ns

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

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

Channel = ADC_CH0_POS_SAMPLEA_AN1 & // //*重要修改:CH0 Pos. : AN6, Neg. : Nominal Vref- Defined in ADCON2
ADC_CH0_NEG_SAMPLEA_NVREF &
ADC_CHX_POS_SAMPLEA_AN0AN1AN2 &
ADC_CHX_NEG_SAMPLEA_NVREF ; // (ADCHS)

SetChanADC10(Channel);

ConfigIntADC10(ADC_INT_DISABLE); // Disable ADC interrupt

}

/***********************************************/
// Subroutine to show Time on LCD

void Show_ADC(void)
{
// unsigned int ADCValue1,ADCValue2;
int Loop ;

ADCValue1 = 0; // clear ADCValue
ADCValue2 = 0;

ADCON1bits.SAMP = 1; // start sampling
for ( Loop = 0 ; Loop < 100 ; Loop ++ ) ; //
ADCON1bits.SAMP = 0; // stop sampling

while (BusyADC10()); // conversion done?

ADCValue1 = ReadADC10(0) ;
if(ADCValue1>90)
{
LATEbits.LATE0 = 0;
}
else
{
LATEbits.LATE0 = 1;
}
setcurLCD(4,1) ; // Set LCD cursor
put_Num_LCD( ADCValue1 >> 2 ) ; // 將類比轉換結果以十進位數字顯示至液晶顯示器


ADCValue2 = ReadADC10(1) ;
setcurLCD(12,1) ; // Set LCD cursor
put_Num_LCD( ADCValue2 >> 2 ) ; // 將類比轉換結果以十進位數字顯示至液晶顯示器

}

發表於: 2010/2/2 10:05
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: AD轉換
#4
中級會員
中級會員


查看用戶資訊
先確定RE0是否設為輸出腳,不然會量不到信號

發表於: 2010/2/2 9:17
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: AD轉換
#3
新會員
新會員


查看用戶資訊
測試時,LCD上的數值會隨著感測器變化而產生不同的數值,BUFFER內應該是有值的吧?

發表於: 2010/1/29 22:24
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: AD轉換
#2
版主
版主


查看用戶資訊
dsPIC30F Peripheral Libraries User's Guide 裡面就有完整的說明。

3.7 ReadADC10



Function Prototype : unsigned int ReadADC10(unsigned char bufIndex);

Include : adc10.h

Description :
This function reads the ADC Buffer register which contains the conversion value.

Arguments :
bufIndex - The ADC buffer number which is to be read.

Return Value: None

Remarks:
This function returns the contents of the ADC Buffer register. You should provide a value between ‘0’ to ‘15’ to ensure a correct read of the ADCBUF0 to ADCBUFF.

Source File:

ReadADC10.c

Code Example :
unsigned int result;
result = ReadADC10(3);

發表於: 2010/1/29 15:24
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


AD轉換
#1
新會員
新會員


查看用戶資訊
使用的是APP020的模擬板,修改dsPIC數位訊號控制器原理與應用的範例程式11-4
想請問ADCValue1 = ReadADC10(0) ;中的ADCValue1是什麼樣的形態?
因為想將轉換出來的數值做程式判別,希望在讀出來的數值大於90與小於90時,可以改變模擬板上LED狀態。
目前無法達成,想請教是哪出了問題?
void Show_ADC(void)
{
// unsigned int ADCValue1,ADCValue2;
int Loop ;

ADCValue1 = 0; // clear ADCValue
ADCValue2 = 0;

ADCON1bits.SAMP = 1; // start sampling
for ( Loop = 0 ; Loop < 100 ; Loop ++ ) ; //
ADCON1bits.SAMP = 0; // stop sampling

while (BusyADC10()); // conversion done?

ADCValue1 = ReadADC10(0) ;
//-------------------------------------------------------------------------------
if(ADCValue1>90)
{
LATEbits.LATE0 = 0;
}
else
{
LATEbits.LATE0 = 1;
}
//-------------------------------------------------------------------------------
setcurLCD(4,1) ; // Set LCD cursor
put_Num_LCD( ADCValue1 >> 2 ) ; // 將類比轉換結果以十進位數字顯示至液晶顯示器


ADCValue2 = ReadADC10(1) ;
setcurLCD(12,1) ; // Set LCD cursor
put_Num_LCD( ADCValue2 >> 2 ) ; // 將類比轉換結果以十進位數字顯示至液晶顯示器

}

發表於: 2010/1/29 14:08
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... ]

教育訓練中心

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