最近在调试adc 的问题。 发现9d92 a1 的adc 不准,但是9d92 a2的还不错。可以设置12bit 的adc , 最大值是 4095 . 无论用外部参考电源还是内部参考都可以。
9b92 只有10位的adc ,最大得出来是1023 . 源代码如下:
/*****************************************************************************
#include "inc/hw_ints.h"
#include "inc/hw_memmap.h"
#include "inc/hw_types.h"
#include "driverlib/gpio.h"
#include "driverlib/interrupt.h"
#include "driverlib/sysctl.h"
#include "driverlib/adc.h"
#include "driverlib/timer.h"
#include "utils/ustdlib.h"
#include "utils/uartstdio.h"
#include "driverlib/sysctl.h"
#include "driverlib/systick.h"
#include "utils/cmdline.h"
int iADC0_read=1; // Indicates if the ADC is ready (1) or busy (0)
unsigned long ulBlinkSpeed = 0; // Timer interrupt frequency (0=low; 1=high)
//************ User Defines ************
//
// 12-bit resolution bit
//
#define ADC_RES_12BIT 0x00
//
// Offset for ADC control register
//
#define ADC_O_CTL 0x38
//*****************************************************************************
// Interrupt handler for the Timer0 interrupt
//*****************************************************************************
void Timer0IntHandler(void)
{
unsigned long ulPinStatus;
// Clear the timer interrupt.
TimerIntClear(TIMER0_BASE, TIMER_TIMA_TIMEOUT);
// Read the current state of the output
ulPinStatus = GPIOPinRead(GPIO_PORTD_BASE, GPIO_PIN_0);
// Toggle Bit 0
ulPinStatus ^= GPIO_PIN_0;
// Write the result back into the GPIO Pin 0 Data Register
GPIOPinWrite(GPIO_PORTD_BASE, GPIO_PIN_0, ulPinStatus);
// Check if the ADC is ready
if (iADC0_read == 1)
{
// Trigger new ADC Conversion using Sample Sequencer 0
ADCProcessorTrigger(ADC0_BASE,3);
// Indicate that the ADC is busy
iADC0_read = 0;
}
}
//*****************************************************************************
// Interrupt handler for the ADC Sample Sequencer 0 (SS0) interrupt
//*****************************************************************************
void ADC3IntHandler(void)
{
unsigned long adc0Value; // Holds the ADC result
char adc0String[4]; // Holds the string-converted ADC result
// Clear the ADC0 interrupt.
ADCIntClear(ADC0_BASE,3);
// Read the data from the Result Buffer of ADC SS0
// We know that we have only one result in the buffer
// If we have more than one result then adc0_value must be an array
ADCSequenceDataGet(ADC0_BASE, 3, &adc0Value);
// Convert the retrieved value to a string
usprintf(adc0String, "%d", adc0Value);
// Display the converted string
// Disable interrupts globally to ensure we don't interrupt communication with the display
IntMasterDisable();
UARTprintf("\n%s",adc0String);
// Display header + some empty spaces to make sure the previous result is erased
// This is important if the new result is shorter than the last one
//RIT128x96x4StringDraw("ADC Ch0 Data : ", 6, 48, 15);
// Display the string-converted ADC value
//RIT128x96x4StringDraw(adc0String, 94, 48, 15);
// Indicate that ADC SS0 has finished conversion and is ready for the next conversion
iADC0_read = 1;
// Re-enable interrupts globally
IntMasterEnable();
}
int main(void)
{
//*****************************************************************************
// Clock Setup
//*****************************************************************************
// Set the clocking to run directly from the crystal.
SysCtlClockSet(SYSCTL_SYSDIV_4| SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ);
// Enable Timer 0, ADC0 and GPIO Block D Peripheral Clocks
SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0);
SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0);
//LED on PD0
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);
// Reset the state of Peripheral ADC0
//
//SysCtlPeripheralReset(SYSCTL_PERIPH_ADC0);
//
// Setup the AIN0 on PE7
//
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
GPIOPinTypeADC(GPIO_PORTB_BASE, GPIO_PIN_4);
// Enable the peripherals used by this example.
//
SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
//Enable PB6 as analog function .
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
GPIOPinTypeADC(GPIO_PORTB_BASE, GPIO_PIN_6);
IntMasterDisable();
//
// Set GPIO A0 and A1 as UART.
//
GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);
//
// Initialize the UART as a console for text I/O.
//
UARTStdioInit(0);
//
// Print hello message to user.
//
UARTprintf("\n\nADC Test Example Program\n");
//*****************************************************************************
// GPIO Setup
//*****************************************************************************
// Set GPIO_F, pin 0 as output (used for the LED)
GPIOPinTypeGPIOOutput(GPIO_PORTD_BASE, GPIO_PIN_0);
/*// For debug popuse
GPIOPinTypeGPIOOutput(GPIO_PORTD_BASE, GPIO_PIN_4|GPIO_PIN_5|GPIO_PIN_6);
GPIOPinWrite(GPIO_PORTD_BASE, GPIO_PIN_4|GPIO_PIN_5|GPIO_PIN_6, 0);
*/
//*****************************************************************************
// Timer 0 Setup
//*****************************************************************************
// Configure Timer0 as 32-bit periodic timer
TimerConfigure(TIMER0_BASE, TIMER_CFG_32_BIT_PER);
// Set Timer0 period as 1/4 of the system clock, i.e. 4 interrupts per second
TimerLoadSet(TIMER0_BASE, TIMER_A, SysCtlClockGet() /4);
// Configure the timer to generate an interrupt on time-out
TimerIntEnable(TIMER0_BASE, TIMER_TIMA_TIMEOUT);
// Enable the TImer Interrupt in the NVIC
IntEnable(INT_TIMER0A);
// Enable the timer
TimerEnable(TIMER0_BASE, TIMER_A);
//
// Set 12-bit resolution
//
HWREG(ADC0_BASE + ADC_O_CTL) = HWREG(ADC0_BASE + ADC_O_CTL) | ADC_RES_12BIT;
//
ADCSequenceConfigure(ADC0_BASE,3, ADC_TRIGGER_PROCESSOR, 0);
// ADCHardwareOversampleConfigure(ADC0_BASE,32);
ADCSequenceStepConfigure(ADC0_BASE, 3, 0, ADC_CTL_CH10|ADC_CTL_IE | ADC_CTL_END );
// Clear the ADC0 interrupt.
ADCIntClear(ADC0_BASE,3);
// Enable Interrupts for SS0
ADCIntEnable(ADC0_BASE, 3);
ADCReferenceSet(ADC0_BASE,ADC_REF_EXT_3V);
//ADCReferenceSet(ADC0_BASE,ADC_REF_INT);
// Enable ADC SS0
ADCSequenceEnable(ADC0_BASE, 3);
// Enable the ADC0 interrupt in the NVIC
IntEnable(INT_ADC3);
// Indicate that ADC SS0 is ready for sampling
iADC0_read = 1;
//*****************************************************************************
// Global Interrupt Enable
//*****************************************************************************
// Enable processor interrupts
IntMasterEnable();
// Loop forever waiting for interrupts
//
// Wait for conversion to be completed
//
//while(!ADCIntStatus(ADC0_BASE, 3, false)){}
while(1)
{
}
}
中断向量:
; <<< Use Configuration Wizard in Context Menu >>>
;******************************************************************************
;
; startup_rvmdk.S - Startup code for use with Keil's uVision.
;
; Copyright (c) 2006-2009 Texas Instruments Incorporated. All rights reserved.
; Software License Agreement
;
; Texas Instruments (TI) is supplying this software for use solely and
; exclusively on TI's microcontroller products. The software is owned by
; TI and/or its suppliers, and is protected under applicable copyright
; laws. You may not combine this software with "viral" open-source
; software in order to form a larger program.
;
; THIS SOFTWARE IS PROVIDED "AS IS" AND WITH ALL FAULTS.
; NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT
; NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
; A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. TI SHALL NOT, UNDER ANY
; CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR CONSEQUENTIAL
; DAMAGES, FOR ANY REASON WHATSOEVER.
;
; This is part of revision 5450 of the EK-LM3S8962 Firmware Package.
;
;******************************************************************************
;******************************************************************************
;
; <o> Stack Size (in Bytes) <0x0-0xFFFFFFFF:8>
;
;******************************************************************************
Stack EQU 0x00000100
;******************************************************************************
;
; <o> Heap Size (in Bytes) <0x0-0xFFFFFFFF:8>
;
;******************************************************************************
Heap EQU 0x00000000
;******************************************************************************
;
; Allocate space for the stack.
;
;******************************************************************************
AREA STACK, NOINIT, READWRITE, ALIGN=3
StackMem
SPACE Stack
__initial_sp
;******************************************************************************
;
; Allocate space for the heap.
;
;******************************************************************************
AREA HEAP, NOINIT, READWRITE, ALIGN=3
__heap_base
HeapMem
SPACE Heap
__heap_limit
;******************************************************************************
;
; Indicate that the code in this file preserves 8-byte alignment of the stack.
;
;******************************************************************************
PRESERVE8
;******************************************************************************
;
; Place code into the reset code section.
;
;******************************************************************************
AREA RESET, CODE, READONLY
THUMB
EXTERN Timer0IntHandler
EXTERN ADC3IntHandler
;******************************************************************************
;
; The vector table.
;
;******************************************************************************
EXPORT __Vectors
__Vectors
DCD StackMem + Stack ; Top of Stack
DCD Reset_Handler ; Reset Handler
DCD NmiSR ; NMI Handler
DCD FaultISR ; Hard Fault Handler
DCD IntDefaultHandler ; The MPU fault handler
DCD IntDefaultHandler ; The bus fault handler
DCD IntDefaultHandler ; The usage fault handler
DCD 0 ; Reserved
DCD 0 ; Reserved
DCD 0 ; Reserved
DCD 0 ; Reserved
DCD IntDefaultHandler ; SVCall handler
DCD IntDefaultHandler ; Debug monitor handler
DCD 0 ; Reserved
DCD IntDefaultHandler ; The PendSV handler
DCD IntDefaultHandler ; The SysTick handler
DCD IntDefaultHandler ; GPIO Port A
DCD IntDefaultHandler ; GPIO Port B
DCD IntDefaultHandler ; GPIO Port C
DCD IntDefaultHandler ; GPIO Port D
DCD IntDefaultHandler ; GPIO Port E
DCD IntDefaultHandler ; UART0 Rx and Tx
DCD IntDefaultHandler ; UART1 Rx and Tx
DCD IntDefaultHandler ; SSI0 Rx and Tx
DCD IntDefaultHandler ; I2C0 Master and Slave
DCD IntDefaultHandler ; PWM Fault
DCD IntDefaultHandler ; PWM Generator 0
DCD IntDefaultHandler ; PWM Generator 1
DCD IntDefaultHandler ; PWM Generator 2
DCD IntDefaultHandler ; Quadrature Encoder 0
DCD IntDefaultHandler ; ADC Sequence 0
DCD IntDefaultHandler ; ADC Sequence 1
DCD IntDefaultHandler ; ADC Sequence 2
DCD ADC3IntHandler ; ADC Sequence 3
DCD IntDefaultHandler ; Watchdog timer
DCD Timer0IntHandler ; Timer 0 subtimer A
DCD IntDefaultHandler ; Timer 0 subtimer B
DCD IntDefaultHandler ; Timer 1 subtimer A
DCD IntDefaultHandler ; Timer 1 subtimer B
DCD IntDefaultHandler ; Timer 2 subtimer A
DCD IntDefaultHandler ; Timer 2 subtimer B
DCD IntDefaultHandler ; Analog Comparator 0
DCD IntDefaultHandler ; Analog Comparator 1
DCD IntDefaultHandler ; Analog Comparator 2
DCD IntDefaultHandler ; System Control (PLL, OSC, BO)
DCD IntDefaultHandler ; FLASH Control
DCD IntDefaultHandler ; GPIO Port F
DCD IntDefaultHandler ; GPIO Port G
DCD IntDefaultHandler ; GPIO Port H
DCD IntDefaultHandler ; UART2 Rx and Tx
DCD IntDefaultHandler ; SSI1 Rx and Tx
DCD IntDefaultHandler ; Timer 3 subtimer A
DCD IntDefaultHandler ; Timer 3 subtimer B
DCD IntDefaultHandler ; I2C1 Master and Slave
DCD IntDefaultHandler ; Quadrature Encoder 1
DCD IntDefaultHandler ; CAN0
DCD IntDefaultHandler ; CAN1
DCD IntDefaultHandler ; CAN2
DCD IntDefaultHandler ; Ethernet
DCD IntDefaultHandler ; Hibernate
;******************************************************************************
;
; This is the code that gets called when the processor first starts execution
; following a reset event.
;
;******************************************************************************
EXPORT Reset_Handler
Reset_Handler
;
; Call the C library enty point that handles startup. This will copy
; the .data section initializers from flash to SRAM and zero fill the
; .bss section.
;
IMPORT __main
B __main
;******************************************************************************
;
; This is the code that gets called when the processor receives a NMI. This
; simply enters an infinite loop, preserving the system state for examination
; by a debugger.
;
;******************************************************************************
NmiSR
B NmiSR
;******************************************************************************
;
; This is the code that gets called when the processor receives a fault
; interrupt. This simply enters an infinite loop, preserving the system state
; for examination by a debugger.
;
;******************************************************************************
FaultISR
B FaultISR
;******************************************************************************
;
; This is the code that gets called when the processor receives an unexpected
; interrupt. This simply enters an infinite loop, preserving the system state
; for examination by a debugger.
;
;******************************************************************************
IntDefaultHandler
B IntDefaultHandler
;******************************************************************************
;
; Make sure the end of this section is aligned.
;
;******************************************************************************
ALIGN
;******************************************************************************
;
; Some code in the normal code section for initializing the heap and stack.
;
;******************************************************************************
AREA |.text|, CODE, READONLY
;******************************************************************************
;
; The function expected of the C library startup code for defining the stack
; and heap memory locations. For the C library version of the startup code,
; provide this function so that the C library initialization code can find out
; the location of the stack and heap.
;
;******************************************************************************
IF :DEF: __MICROLIB
EXPORT __initial_sp
EXPORT __heap_base
EXPORT __heap_limit
ELSE
IMPORT __use_two_region_memory
EXPORT __user_initial_stackheap
__user_initial_stackheap
LDR R0, =HeapMem
LDR R1, =(StackMem + Stack)
LDR R2, =(HeapMem + Heap)
LDR R3, =StackMem
BX LR
ENDIF
;******************************************************************************
;
; Make sure the end of this section is aligned.
;
;******************************************************************************
ALIGN
;******************************************************************************
;
; Tell the assembler that we're done.
;
;******************************************************************************
END |
|