• 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: 12F675 ADC 使用問題
#6
新會員
新會員


查看用戶資訊
GPIO有没有设定正确,Vref有没有设对。仔细对照datasheet,断点or单步看控制register值是不是设定值。
很可能是GPIO口AN2没有分配好。

發表於: 2009/7/22 17:10
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: 12F675 ADC 使用問題
#5
資深會員
資深會員


查看用戶資訊
四樓的寫法可讀性較佳,不過一樓的寫法編譯執行並沒有問題,只是人類可讀性較差,

如果程式設定都沒問題,建議用電表測一下那隻腳的真正電壓值,看是不是硬體的問題。

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


Re: 12F675 ADC 使用問題
#4
高級會員
高級會員


查看用戶資訊
我很少寫C CODE , 想反問最後那個 while(1) 要不要加 { }

#include <pic12f675.h>
//ADC utilities

void init_a2d(void){
    
ANSEL=0x34;//ADC CLOCK INTERNAL, Analog Select only AN2
    //ADCON0=0x80; // right justify result.
    
ADCON0=0x00// left justify
    
ADON=1// turn on the A2D conversion module
}

//unsigned int read_a2d(unsigned char channel){// for 10bit ADC
unsigned char read_a2d(unsigned char channel){// for 8bit ADC
    
channel&=0x03// truncate channel to 2 bits
    
ADCON0&=0xc3// clear current channel select
    
ADCON0|=(channel<<2); // apply the new channel select
    
GO_DONE=1// initiate conversion on the selected channel
    
while(GO_DONE);
    
//return (ADRESH<<8)+ADRESL; // return ADC value of the result
    
return ADRESH;
}



void main(void)
{


//internal RC oscilator calibration
    
_asm
    bsf STATUS
;Bank 1
    call 3FFh 
;Get the cal value
    movwf OSCCAL 
;Calibrate
    bcf STATUS
;Bank 0
    _endasm
;

    
TRISIO=0x04;// set AN2(GP2) as "input" direction pin
    
CMCON=0x07;
    
init_a2d();

/*
// for debug and test code
while(1)
{
    delay_ms(1000);
    GPIO=GPIO^0x30;
}
*/ 
while(1)  
[
color=0000FF]{ 
    if(
read_a2d(2)>63GP5=1;
    else 
GP5=0;
}[/
color]

}

發表於: 2009/7/21 8:45
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: 12F675 ADC 使用問題
#3
新會員
新會員


查看用戶資訊
ADCON0=0x00;// ADCON0.VCFG=0; Vref=VDD是5V沒錯

發表於: 2009/7/18 13:23
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: 12F675 ADC 使用問題
#2
資深會員
資深會員


查看用戶資訊
10 bits adc = 0~1023

5V =1023 表示 Vref = 5V

1.3V =1023 , Vref = 1.3 V 要確定 Vref 來源是否設對!

可能要仔細看 adc data sheet !

發表於: 2009/7/18 10:15
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


12F675 ADC 使用問題
#1
新會員
新會員


查看用戶資訊
第一次使用 12F675 ADC, 依照手冊設定 MCU SFR後, 若設定無誤, VDD=5V, ANALOG 輸入如果在1.3V以上應該可以得到1024/4以上的 AD值, 可是實際測試卻要接近5V左右, 不知問題出在哪裡
以上, 還請不吝指教
CODE如下

#include <pic12f675.h>
//ADC utilities

void init_a2d(void){
ANSEL=0x34;//ADC CLOCK INTERNAL, Analog Select only AN2
//ADCON0=0x80; // right justify result.
ADCON0=0x00; // left justify
ADON=1; // turn on the A2D conversion module
}

//unsigned int read_a2d(unsigned char channel){// for 10bit ADC
unsigned char read_a2d(unsigned char channel){// for 8bit ADC
channel&=0x03; // truncate channel to 2 bits
ADCON0&=0xc3; // clear current channel select
ADCON0|=(channel<<2); // apply the new channel select
GO_DONE=1; // initiate conversion on the selected channel
while(GO_DONE);
//return (ADRESH<<8)+ADRESL; // return ADC value of the result
return ADRESH;
}



void main(void)
{


//internal RC oscilator calibration
_asm
bsf STATUS, 5 ;Bank 1
call 3FFh ;Get the cal value
movwf OSCCAL ;Calibrate
bcf STATUS, 5 ;Bank 0
_endasm;

TRISIO=0x04;// set AN2(GP2) as "input" direction pin
CMCON=0x07;
init_a2d();

/*
// for debug and test code
while(1)
{
delay_ms(1000);
GPIO=GPIO^0x30;
}
*/
while(1)
if(read_a2d(2)>63) GP5=1;
else GP5=0;

}

發表於: 2009/7/17 15:25
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... ]

教育訓練中心

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