?? tms470r1b1m_adc10_06.c
字號(hào):
//******************************************************************************
// TMS470 Demo - MibADC Buffered Sample with polling
//
// Description; the MibADC is used in buffered mode. 20 samples are taken
// in continuous mode from channel 9 and are placed in the group 1 FIFO.
// 20 samples are read and averaged. The average is displayed on the LEDs
// Software sets starts sample and conversion and polls for end of conversion.
//
// Total sample and convert time = 19.6608 MHz/(8*((62+2)+11)) = 32.7KSPS
// SYSCLK = MCLK = ACLK = 8 x 7.3728MHz = 58.9824MHz
// ICLK = SYSCLK / 3 = 19.6608MHz
//
// //*An external 7.3728MHz XTAL with proper load caps is required*//
//
// TMS-FET470B1M
// -----------------
// | OSCIN|-
// +--|PLLDIS | 7.3728MHz
// | | OSCOUT|-
// -+- | |
// | |
// >---|ADIN0 HET|---> Toggle
// | |
//
// L.Westlund / J.Mangino
// Texas Instruments, Inc
// July 29th 2005
// Built with IAR Embedded Workbench Version: 4.30A
//******************************************************************************
#include <intrinsic.h>
#include "iotms470r1b1m.h"
#include "tms470r1b1m_bit_definitions.h"
void LedSet(unsigned int);
unsigned int result[20];
unsigned int average;
void main(void)
{
PCR = CLKDIV_3; // ICLK = SYSCLK / 3
GCR = ZPLL_CLK_DIV_PRE_1; // SYSCLK = 8 x fOSC
PCR |= PENABLE; // Enable peripherals
HETDIR = 0xFFFFFFFF; // HETx Output direction
HETDOUT = 0x00000000;
GIODIRE = 0xFF; // GIO[E] set as outputs
GIODOUTE = 0x00;
ADCR1 |= PS_8; // ADCLK prescaler = 8
ADSAMPEV |= SEN; // ADCSAMP1 controls SW
ADSAMP1 = 62; // SW = 62+2
ADCR1 |= ADC_EN; // Enable ADC
ADISR1 = 0x0001; // group 1 = channel 0
ADCR2 |= G1_MODE; // Continuous Conversion
ADBCR1 |= BUF_EN; // enable buffered mode
ADBCR1 |= BNDA_8; // set RAM boundary between event and group 1
// units of two words from the beginning of buffer
// event group has 8*2 = 16 words for the FIFO
ADBCR1 |= BNDB_16 + BNDB_2; // set RAM boundary between group 1 and 2
// units of two words from the beginning of buffer
// group 1 has (18-8)*2 = 20 words for the FIFO
ADBCR2 |= BNDEND_64; // set RAM buffer end boundary
// 64-word FIFO buffer
// group 2 has 64-(2*18) = 28 words for the FIFO
ADTHRG1 = G1THR_16 + G1THR_4; // group 1 threshold counter = 20, 20 results will be
// placed on the buffer before setting G1 BUF INT FLAG
// Loop forever.
for (;;)
{
while(!(ADBUFST & G1_INT_FLAG)); // wait for conversions to complete
unsigned int i;
average = 0;
for (i=0; i<20; i++)
{
result[i] = ADBUF1; // read FIFO value
average = average + result[i]; // sum values
}
average = (unsigned int) average / 20;// get average
LedSet(average);
ADBUFST &= ~G1_INT_FLAG; // clear flag
}
}
// display binary value on 8 LEDs
void LedSet(unsigned int mask)
{
unsigned int out = 0;
GIODOUTE = mask & 0xFF;
HETDOUT = (mask & 0xFF00)>>8;
}
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -