標(biāo)題: 求助,PIC32MX系列 AD模塊測(cè)試程序的問(wèn)題 [打印本頁(yè)]

作者: tom102500    時(shí)間: 2015-7-17 02:59
標(biāo)題: 求助,PIC32MX系列 AD模塊測(cè)試程序的問(wèn)題
本人最近在用UBW32開發(fā)板,里面是PIC32MX795。 我自己寫了一個(gè)測(cè)試AD模塊的程序。大體思想就是想通過(guò)函數(shù)發(fā)生器所發(fā)出的方波來(lái)控制LED的閃爍。從而實(shí)現(xiàn)測(cè)試AD轉(zhuǎn)換是否運(yùn)行正常,大體就是給1就亮,給0就不亮。然而我在運(yùn)行程序時(shí)LED卻一直亮。沒有出現(xiàn)隨著方波頻率變化的情況。我用的是2.2HZ接近3.3V的方波?傊业某绦蛉缦。本人菜鳥一枚,各位大神如有懂得請(qǐng)幫我指一條明路!跪謝。/*
** 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;
  }
}




作者: rvanji2018    時(shí)間: 2019-11-17 17:43
主函數(shù)里面AD采樣沒有在死循環(huán)內(nèi),另外AD采樣的是電壓值,3.3V采樣電壓得數(shù)值為1024,所以賦值給PORTE不正確。




歡迎光臨 (http://www.torrancerestoration.com/bbs/) Powered by Discuz! X3.1