?? het_int_02.c
字號:
//*****************************************************************************
// TMS470 Demo - HET Interrupt Sample Program
//
// Program name : HET_INT_02.c associated with HET program HET_INT_02_H.het
//
// Description; This program uses the HET to trigger the ADC at 10 ms
// intervals when used with a 12 MHz clock. The result of the ADC is
// averaged 20 times and the result is displayed using the LEDs on the A256 EVM.
//
// *An external 12Mhz XTAL on OSCIN OSCOUT with proper load caps required*
//
// TMS-FET470A256
// -----------------
// /|\| OSCIN|-
// | | | 12MHz
// --|PLLDIS OSCOUT|-
// | |
// >---|ADIN0 HET|---> 10 LEDs
// | |
//
// John Mangino / Lane Westlund
// Texas Instruments, Inc
// May 2005
// Built with IAR Embedded Workbench Version: 4.20A
// A256 EVM
//******************************************************************************
#include <intrinsic.h>
#include "iotms470r1a256.h"
#include "tms470r1a256_bit_definitions.h"
#include "std_het.h"
#include "HET_INT_02_H.h"
void MemCopy32(unsigned long *dst, unsigned long *src, int bytes);
__no_init volatile HETPROGRAM0_UN e_HETPROGRAM0_UN @ 0x00800000;
unsigned int result[20];
unsigned int average;
void main(void)
{
// Set up peripheral registers.
PCR = CLKDIV_1; // ICLK = SYSCLK
PCR |= PENABLE; // enable peripherals
REQMASK = 0; // clear interrupt mask
REQMASK |= (1<<CIM_MIBADCE1); // enable channel 27 (AD1)
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
ADEVTSRC = G1_SRC_INT1 + G1_EDG_SEL + G1_ENA; // enable group 1 and set trigger for low
// to high transition
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
ADBUFST &= ~G1_INT_FLAG; // clear flag
ADBCR3 |= G1_OVR_INT_EN; // enable group 1 FIFO buffer over-run interrupt
ADBCR3 |= G1_BUF_INT_EN; // enable group 1 FIFO buffer interrupt
HETGCR = CLK_MASTER + IGNORE_SUSPEND; // HET Master Mode, Ignore SW BP
// copy HET instructions to HET ram
MemCopy32((void *) &e_HETPROGRAM0_UN, (void *) HET_INIT0_PST, sizeof(HET_INIT0_PST));
HETPFR = 0x00000309; // Set PFR register /8 /10
HETDIR = 0xFFFFFFFF; // Set all HET as GIO outputs
HETDOUT = 0xFFFFFFFF; // Flash all leds off and on and off
HETGCR |= ON; // Start HET
__enable_interrupt(); // enable interrupts
// Loop forever.
while(1){}
}
//------------------------------------------------------------------------------
// This module programms the HET RAM with the HET code
//------------------------------------------------------------------------------
void MemCopy32(unsigned long *dst, unsigned long *src, int bytes)
{
for (int i = 0; i < (bytes + 3) / 4; i++)
*dst++ = *src++;
}
//------------------------------------------------------------------------------
// Display data on the LEDs
//------------------------------------------------------------------------------
void LedSet(unsigned int mask)
{
unsigned int out = 0;
mask ^= 0xFFFFFFFF;
out |= (mask << 16)& 0x80000000;
out |= (mask << 10)& 0x01000000;
out |= (mask << 8) & 0x003c0000;
out |= (mask << 4) & 0x00003c00;
out |= (mask << 3) & 0x000001c0;
out |= (mask << 2) & 0x00000010;
out |= (mask << 1) & 0x00000004;
out |= mask & 0x00000001;
HETDOUT = out;
}
//------------------------------------------------------------------------------
// TMS470R1A256 Standard Interrupt Handler
//------------------------------------------------------------------------------
#pragma vector = IRQV
__irq __arm void irq_handler(void)
{
switch((0xff & IRQIVEC)-1)
{
case CIM_MIBADCE1 : // channel 27 (AD1) interrupt?
if (ADBUFST & 0x0020) // buffer over-run?
{
ADISR1 = 0x0001; // clear buffer
ADTHRG1 = G1THR_16 + G1THR_4; // reset group 1 threshold
}
else
{
unsigned int i;
ADBUFST &= ~G1_INT_FLAG; // clear flag
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);
}
break;
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -