找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

帖子
查看: 2355|回復(fù): 1
打印 上一主題 下一主題
收起左側(cè)

求助,PIC32MX系列 AD模塊測試程序的問題

[復(fù)制鏈接]
跳轉(zhuǎn)到指定樓層
樓主
ID:85898 發(fā)表于 2015-7-17 02:59 | 只看該作者 回帖獎(jiǎng)勵(lì) |倒序?yàn)g覽 |閱讀模式
本人最近在用UBW32開發(fā)板,里面是PIC32MX795。 我自己寫了一個(gè)測試AD模塊的程序。大體思想就是想通過函數(shù)發(fā)生器所發(fā)出的方波來控制LED的閃爍。從而實(shí)現(xiàn)測試AD轉(zhuǎn)換是否運(yùn)行正常,大體就是給1就亮,給0就不亮。然而我在運(yùn)行程序時(shí)LED卻一直亮。沒有出現(xiàn)隨著方波頻率變化的情況。我用的是2.2HZ接近3.3V的方波�?傊业某绦蛉缦�。本人菜鳥一枚,各位大神如有懂得請幫我指一條明路!跪謝�。�/*
** ADCLib.c
**
*/

// configuration bit settings, Fcy=72MHz, Fpb=36MHz
#pragma config POSCMOD=XT, FNOSC=PRIPLL
#pragma config FPLLIDIV=DIV_2, FPLLMUL=MUL_18, FPLLODIV=DIV_1
#pragma config FPBDIV=DIV_2, FWDTEN=OFF, CP=OFF, BWP=OFF

#include <p32xxxx.h>

#define POT 5                   // 10k potentiometer on AN5 input
#define AINPUTS 0xffdf          // Analog inputs for POT

// initilaize the ADC for single conversion, select input pins
void initADC( int amask)
{
  AD1PCFG = amask;             // select analog input pins
  AD1CON1 = 0x00E0;            // auto convert after end of sampling
  AD1CSSL = 0;                 // no scanning required
  AD1CON2 = 0;                 // use MUXA, AVss/AVdd used as Vref+/-
  AD1CON3 = 0x1F3F;            // max sample thime = 31Tad
  AD1CON1SET = 0x8000;         // turn on the ADC
} //initADC

int readADC( int ch)
{
  AD1CHSbits.CH0SA = ch;        // select analog input channel
  AD1CON1bits.SAMP = 1;         // start sampling
  while (!AD1CON1bits.DONE);    // wait to complete conversion
  return ADC1BUF0;              // read the conversion result
} // readADC


main()
{
  DDPCONbits.JTAGEN=0;
  TRISB=0x0020;
  initADC( AINPUTS);
  int a;
  a=readADC( POT);
  TRISE=0x0000;                 //PORTE pins are output,and connected to

  while( 1)
  {
     PORTE=a;
  }
}



分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏 分享淘帖 頂 踩
回復(fù)

使用道具 舉報(bào)

沙發(fā)
ID:283322 發(fā)表于 2019-11-17 17:43 | 只看該作者
主函數(shù)里面AD采樣沒有在死循環(huán)內(nèi),另外AD采樣的是電壓值,3.3V采樣電壓得數(shù)值為1024,所以賦值給PORTE不正確。
回復(fù)

使用道具 舉報(bào)

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規(guī)則

小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術(shù)交流QQ群281945664

Powered by 單片機(jī)教程網(wǎng)

快速回復(fù) 返回頂部 返回列表