• slider image 442
  • slider image 477
  • slider image 479
  • slider image 480
  • slider image 481
  • slider image 482
:::


Browsing this Thread:   1 Anonymous Users






Re: 請問A/D取多個通道輸入的問題
#5
初級會員
初級會員


查看用戶資訊
請問版主的意思是
直接把
PSPMODE=0;
這樣設定嗎?
我是直接這樣設定,但是RE2那支接腳還是不能使用耶
而ADCON1沒有設錯

發表於: 2005/11/24 16:39
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: 請問A/D取多個通道輸入的問題
#4
版主
版主


查看用戶資訊
檢查一下 TRISE 裡的 PAPMODE 位元是否被設為 1。

檢查 ADCON1 裡的 PCFG0~PCFG3 的設定。

發表於: 2005/11/24 11:18
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: 請問A/D取多個通道輸入的問題
#3
初級會員
初級會員


查看用戶資訊
哈~~萬分感謝版主的回答..
我之前以為那個DELAY是要加在切channel之間~~~
原來如此~~
還有一個問題可以請教一下嗎?

就是為啥我RE2這個輸入接腳在A/D時不能使用呢?

謝謝!

發表於: 2005/11/23 20:14
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: 請問A/D取多個通道輸入的問題
#2
版主
版主


查看用戶資訊
採樣 (充電) 時間不足造成。

正確的AD使用法為:切到新的通道後,要延遲一下,讓內部的SAMPLE&HOLD電容充份充/放電 (即和外部的類比電位一樣高),才能將GO設為1 (即斷開SAMPLE&HOLD電容和外界的連線),開始做ADC的轉換。

發表於: 2005/11/22 21:10
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


請問A/D取多個通道輸入的問題
#1
初級會員
初級會員


查看用戶資訊
各位前輩:
小弟最近想用PIC16F877取多個通道的A/D轉換,我是參考此網站右邊"教材及講義區 ==> WORKSHOP ==> HI-TECH C 講義及實作裡面的lab3";但是此範例是PIC16F877A的範例,且此範例只取一個channel,因此小弟將程式修改如下:

希望各位前輩能夠撥空幫我看看為何,我取單一channel時不會有問題,但是取多channel時卻會有互相干擾的問題?
另外,為何我第8個channel(RE2)不能使用?

拜託各位前輩能給我這個初入門的人解答,萬分感謝!!

#include <pic.h>
#include "MID_LCD.h"


void A2D_0( unsigned char );
void A2D_1( unsigned char );
void A2D_2( unsigned char );
void LCD_ItoA(unsigned int);
unsigned char Set_BCD_ASCII(unsigned char);




unsigned int AD_Temp;
unsigned int AD_Temp_1;
unsigned int AD_Temp_2;
bit DS_Zero_Flag;

union {
int AD_10bit;
struct {
char AD_LSB;
char AD_MSB;
}AD_Byte;
}AD_Int;

union {
int AD_10bit_1;
struct {
char AD_LSB_1;
char AD_MSB_1;
}AD_Byte_1;
}AD_Int_1;

union {
int AD_10bit_2;
struct {
char AD_LSB_2;
char AD_MSB_2;
}AD_Byte_2;
}AD_Int_2;
/*****************************
DELAY FUNCTION
*****************************/

void delay_x_ms(int);
void del_1ms(void);

void delay_x_ms(int N_ms)
{
int Loop_ms;

for(Loop_ms = 0;Loop_ms<N_ms;Loop_ms++)
{
del_1ms();
}
}

void del_1ms(void)
{
int del_1ms;
for(del_1ms = 0;del_1ms<199;del_1ms++)
{
asm("nop");
asm("nop");
}
}

/***********************************
Convert A/D Channel
************************************/

void A2D_0( unsigned char channel )
{
unsigned char temp; // Temp storage
ADCON0=0b10000001;

temp = channel << 3; // Shift channel value three bits left
ADCON0 &= 0b11000111; // Clear channel select bits in ADCON0
ADCON0 |= temp; // Logically OR shifted channel value into place in ADCON0

ADGO = 1; // Initiate conversion on selected channel
while (ADGO) ; // Poll ADGO bit until it clears, indicating conv. done
AD_Int.AD_Byte.AD_MSB=ADRESH;
AD_Int.AD_Byte.AD_LSB=ADRESL;
}

void A2D_1( unsigned char channel_1)
{
unsigned char temp; // Temp storage
ADCON0=0b10001001;

temp = channel_1 << 3; // Shift channel value three bits left
ADCON0 &= 0b11000111; // Clear channel select bits in ADCON0
ADCON0 |= temp; // Logically OR shifted channel value into place in ADCON0

ADGO = 1; // Initiate conversion on selected channel
while (ADGO) ; // Poll ADGO bit until it clears, indicating conv. done
AD_Int_1.AD_Byte_1.AD_MSB_1=ADRESH;
AD_Int_1.AD_Byte_1.AD_LSB_1=ADRESL;
}

void A2D_2( unsigned char channel_2)
{
unsigned char temp; // Temp storage
ADCON0=0b10010001;

temp = channel_2 << 3; // Shift channel value three bits left
ADCON0 &= 0b11000111; // Clear channel select bits in ADCON0
ADCON0 |= temp; // Logically OR shifted channel value into place in ADCON0

ADGO = 1; // Initiate conversion on selected channel
while (ADGO) ; // Poll ADGO bit until it clears, indicating conv. done
AD_Int_2.AD_Byte_2.AD_MSB_2=ADRESH;
AD_Int_2.AD_Byte_2.AD_LSB_2=ADRESL;
}

//***************************************
//* Program Main ( ) *
//***************************************
void main(void)
{
OpenLCD();
ADCON1=0b10000000; //all channel is A/D input and Right justified
TRISA0=1;
TRISA1=1;
TRISA2=1;
TRISA3=1;
TRISA4=1;
TRISA5=1;
TRISE0=1;
TRISE1=1;
TRISE2=1;
TRISC=0x00; // Set PortC for Output
PORTC=0x80; // Initila LED display = 0x80

while(1)
{
A2D_0(0x00); // Get 10-bit A/D result from CH0
LCD_Set_Cursor(0,0);
LCD_ItoA(AD_Int.AD_10bit);
delay_x_ms(100);
A2D_1(0x01); // Get 10-bit A/D result from CH1
LCD_Set_Cursor(6,0);
LCD_ItoA(AD_Int_1.AD_10bit_1);
delay_x_ms(100);
A2D_2(0x02); // Get 10-bit A/D result from CH2
LCD_Set_Cursor(0,1);
LCD_ItoA(AD_Int_2.AD_10bit_2);
delay_x_ms(100);

}

}

void LCD_ItoA(unsigned int AD_Data)
{
AD_Temp=AD_Data;
DS_Zero_Flag=1;

putcLCD(Set_BCD_ASCII(AD_Data/1000)); // 顯示千位數
AD_Temp=AD_Temp%1000; // 取出百位以後的數

putcLCD(Set_BCD_ASCII(AD_Temp/100)); // 顯示百位數
AD_Temp=AD_Temp%100;

putcLCD(Set_BCD_ASCII(AD_Temp/10)); // 顯示十位數
AD_Temp=AD_Temp%10;

putcLCD(AD_Temp+='0'); // 顯示個位數
}


unsigned char Set_BCD_ASCII(unsigned char BCD_Data)
{
if (BCD_Data==0)
{
if (DS_Zero_Flag) return ' '; // 居先零抑制
else return '0'; // 顯示一般的零
}
else
{
DS_Zero_Flag=0; // 取消居先零的抑制
return (BCD_Data +='0'); // 並傳回 ASCII Code
}
}

發表於: 2005/11/21 21:49
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... ]

教育訓練中心

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