在线时间113 小时
UID3522883
注册时间2018-11-23
NXP金币0
TA的每日心情 | 奋斗 2020-12-31 08:09 |
---|
签到天数: 438 天 连续签到: 1 天 [LV.9]以坛为家II
金牌会员
 
- 积分
- 1673
- 最后登录
- 2020-12-31
|
DEMOAX9S12P128开发板,CodeWarrior5.1,用之前用自己编写的AD工程结果当通道1输入信号,如5V,在通道0寄存器ATDDR0读到了值,不知道是哪里设置问题。然后用full version的Processor Expert生成AD程序,发现ATDDR0~ATDDR7寄存器的值均为0,我的输入是0,0.625,1.25,1.875,2.5,3.125,3.75,4.375V,但是读到的值均为0。请问各位大神是怎么解决的?
工程代码见附件。
AD1.c源代码如下:
/** ###################################################################
** THIS COMPONENT MODULE IS GENERATED BY THE TOOL. DO NOT MODIFY IT.
** Filename : AD1.c
** Project : pe_adc
** Processor : MC9S12P128MQK
** Component : ADC
** Version : Component 01.593, Driver 01.17, CPU db: 3.00.027
** Compiler : CodeWarrior HC12 C Compiler
** Date/Time : 2018/11/28, 16:58
** Abstract :
** This device "ADC" implements an A/D converter,
** its control methods and interrupt/event handling procedure.
** This device is designed for fast A/D conversions.
** Settings :
** AD control register : ATDCTL4 [$0074]
** Interrupt name : Vatd
** Interrupt enable reg. : ATDCTL23 [$0072]
** Priority :
** User handling procedure : AD1_OnEnd
** Number of conversions : 1
** AD resolution : 12-bit
**
** Input pins
**
** Port name : ADL
** Bit number (in port) : 0
** Bit mask of the port : $0001
** Port data register : PT1AD [$0271]
** Port control register : DDR1AD [$0273]
**
** Port name : ADL
** Bit number (in port) : 1
** Bit mask of the port : $0002
** Port data register : PT1AD [$0271]
** Port control register : DDR1AD [$0273]
**
** Port name : ADL
** Bit number (in port) : 2
** Bit mask of the port : $0004
** Port data register : PT1AD [$0271]
** Port control register : DDR1AD [$0273]
**
** Port name : ADL
** Bit number (in port) : 3
** Bit mask of the port : $0008
** Port data register : PT1AD [$0271]
** Port control register : DDR1AD [$0273]
**
** Port name : ADL
** Bit number (in port) : 4
** Bit mask of the port : $0010
** Port data register : PT1AD [$0271]
** Port control register : DDR1AD [$0273]
**
** Port name : ADL
** Bit number (in port) : 5
** Bit mask of the port : $0020
** Port data register : PT1AD [$0271]
** Port control register : DDR1AD [$0273]
**
** Port name : ADL
** Bit number (in port) : 6
** Bit mask of the port : $0040
** Port data register : PT1AD [$0271]
** Port control register : DDR1AD [$0273]
**
** Port name : ADL
** Bit number (in port) : 7
** Bit mask of the port : $0080
** Port data register : PT1AD [$0271]
** Port control register : DDR1AD [$0273]
**
** Initialization:
** Conversion : Enabled
** Event : Enabled
** High speed mode
** Prescaler : divide-by-20
** Contents :
** Measure - byte AD1_Measure(bool WaitForResult);
** GetValue16 - byte AD1_GetValue16(word *Values);
**
** Copyright : 1997 - 2010 Freescale Semiconductor, Inc. All Rights Reserved.
**
** http : www.freescale.com
** mail : support@freescale.com
** ###################################################################*/
/* MODULE AD1. */
#pragma MESSAGE DISABLE C5703 /* Disable warning C5703 " arameter is not referenced" */
#pragma MESSAGE DISABLE C4002 /* Disable warning C4002 "Result not used is ignored" */
#pragma MESSAGE DISABLE C12056 /* Disable warning C12056 "SP debug info incorrect because of optimization or inline assembler" */
#include "Events.h"
#include "AD1.h"
#pragma DATA_SEG AD1_DATA /* Select data segment "AD1_DATA" */
#pragma CODE_SEG AD1_CODE
#pragma CONST_SEG AD1_CONST /* Constant section for this module */
#define STOP 0U /* STOP state */
#define MEASURE 1U /* MESURE state */
#define CONTINUOUS 2U /* CONTINUOUS state */
static bool OutFlg; /* Measurement finish flag */
volatile static byte ModeFlg; /* Current state of device */
/*
** ===================================================================
** Method : AD1_Interrupt (component ADC)
**
** Description :
** The method services the interrupt of the selected peripheral(s)
** and eventually invokes event(s) of the component.
** This method is internal. It is used by Processor Expert only.
** ===================================================================
*/
#pragma CODE_SEG __NEAR_SEG NON_BANKED
ISR(AD1_Interrupt)
{
ATDDR0; /* Dummy read of data register to clear flags */
OutFlg = TRUE; /* Measured values are available */
ModeFlg = STOP; /* Set the device to the stop mode */
AD1_OnEnd(); /* Invoke user event */
}
#pragma CODE_SEG AD1_CODE
/*
** ===================================================================
** Method : AD1_Measure (component ADC)
**
** Description :
** This method performs one measurement on all channels that
** are set in the component inspector. (Note: If the <number of
** conversions> is more than one the conversion of A/D
** channels is performed specified number of times.)
** Parameters :
** NAME - DESCRIPTION
** WaitForResult - Wait for a result
** of a conversion. If the <interrupt
** service> is disabled and a <number of
** conversions> is greater than 1, the
** WaitForResult parameter is ignored and
** the method waits for each result every
** time.
** Returns :
** --- - Error code, possible codes:
** ERR_OK - OK
** ERR_SPEED - This device does not work in
** the active speed mode
** ERR_DISABLED - Device is disabled
** ERR_BUSY - A conversion is already
** running
** ===================================================================
*/
byte AD1_Measure(bool WaitForResult)
{
if (ModeFlg != STOP) { /* Is the device in different mode than "stop"? */
return ERR_BUSY; /* If yes then error */
}
ModeFlg = MEASURE; /* Set state of device to the measure mode */
OutFlg = FALSE; /* Output values aren't available */
/* ATDCTL5: ??=0,SC=0,SCAN=0,MULT=1,CD=0,CC=0,CB=0,CA=0 */
ATDCTL5 = 0x10U; /* Start conversions */
if (WaitForResult) { /* Is WaitForResult TRUE? */
while (ModeFlg == MEASURE) {} /* If yes then wait for end of measurement */
}
return ERR_OK; /* OK */
}
/*
** ===================================================================
** Method : AD1_GetValue16 (component ADC)
**
** Description :
** This method returns the last measured values of all
** channels justified to the left. Compared with <GetValue>
** method this method returns more accurate result if the
** <number of conversions> is greater than 1 and <AD
** resolution> is less than 16 bits. In addition, the user
** code dependency on <AD resolution> is eliminated.
** Parameters :
** NAME - DESCRIPTION
** * Values - Pointer to the array that
** contains the measured data.
** Returns :
** --- - Error code, possible codes:
** ERR_OK - OK
** ERR_SPEED - This device does not work in
** the active speed mode
** ERR_NOTAVAIL - Requested value not
** available
** ERR_OVERRUN - External trigger overrun
** flag was detected after last value(s)
** was obtained (for example by GetValue).
** This error may not be supported on some
** CPUs (see generated code).
** ===================================================================
*/
byte AD1_GetValue16(word *Values)
{
if (!OutFlg) { /* Is measured value(s) available? */
return ERR_NOTAVAIL; /* If no then error */
}
/* Note: Next 8 lines are speed optimized */
*Values++ = ATDDR0; /* Save measured values to the output buffer */
*Values++ = ATDDR1; /* Save measured values to the output buffer */
*Values++ = ATDDR2; /* Save measured values to the output buffer */
*Values++ = ATDDR3; /* Save measured values to the output buffer */
*Values++ = ATDDR4; /* Save measured values to the output buffer */
*Values++ = ATDDR5; /* Save measured values to the output buffer */
*Values++ = ATDDR6; /* Save measured values to the output buffer */
*Values = ATDDR7; /* Save measured values to the output buffer */
return ERR_OK; /* OK */
}
/*
** ===================================================================
** Method : AD1_Init (component ADC)
**
** Description :
** Initializes the associated peripheral(s) and the component's
** internal variables. The method is called automatically as a
** part of the application initialization code.
** This method is internal. It is used by Processor Expert only.
** ===================================================================
*/
void AD1_Init(void)
{
OutFlg = FALSE; /* No measured value */
ModeFlg = STOP; /* Device isn't running */
/* ATDCTL4: SMP2=1,SMP1=1,SMP0=1,PRS4=0,PRS3=1,PRS2=0,PRS1=0,PRS0=1 */
ATDCTL4 = 0xE9U; /* Set sample time and prescaler */
/* ATDCTL3: DJM=0,S8C=1,S4C=0,S2C=0,S1C=0,FIFO=0,FRZ1=0,FRZ0=0 */
ATDCTL3 = 0x40U; /* Set ATD control register 3 */
/* ATDCTL0: ??=0,??=0,??=0,??=0,WRAP3=1,WRAP2=1,WRAP1=1,WRAP0=1 */
ATDCTL0 = 0x0FU; /* Set wrap around */
/* ATDCTL1: ETRIGSEL=0,SRES1=1,SRES0=0,SMP_DIS=1,ETRIGCH3=1,ETRIGCH2=1,ETRIGCH1=1,ETRIGCH0=1 */
ATDCTL1 = 0x5FU; /* Set resolution and discharge */
/* ATDCTL2: ??=0,AFFC=1,ICLKSTP=1,ETRIGLE=0,ETRIGP=0,ETRIGE=0,ASCIE=1,ACMPIE=0 */
ATDCTL2 = 0x62U; /* Set ATD control register 2 */
}
/* END AD1. */
/*
** ###################################################################
**
** This file was created by Processor Expert 3.02 [04.44]
** for the Freescale HCS12 series of microcontrollers.
**
** ###################################################################
*/
|
|