标题: 求助,PIC32MX系列 AD模块测试程序的问题 [打印本页]

作者: tom102500    时间: 2015-7-17 02:59
标题: 求助,PIC32MX系列 AD模块测试程序的问题
本人最近在用UBW32开发板,里面是PIC32MX795。 我自己写了一个测试AD模块的程序。大体思想就是想通过函数发生器所发出的方波来控制LED的闪烁。从而实现测试AD转换是否运行正常,大体就是给1就亮,给0就不亮。然而我在运行程序时LED却一直亮。没有出现随着方波频率变化的情况。我用的是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;
  }
}




作者: rvanji2018    时间: 2019-11-17 17:43
主函数里面AD采样没有在死循环内,另外AD采样的是电压值,3.3V采样电压得数值为1024,所以赋值给PORTE不正确。




欢迎光临 (http://www.51hei.com/bbs/) Powered by Discuz! X3.1