⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 het_pcnt_01.c

📁 tmp470开发板的源程序
💻 C
字号:
//******************************************************************************
//  TMS470 Demo - HET used to determine a pulse width
//
//  Program name : HET_PWM_01.c associated with HET program HET_PWM_01_H.het
//
//  Description; Using the PCNT instruction the HET will determine the width
//  of a Pulse. The pulse is generated by the HET on CC0 and read into the HET
//  on CC2. When the pusle width is valid the HET will trigger an interrupt.
//  At this point the data may be viewed. Pins CC0 and CC2 must be connected.
//  These are HET0 and HET2 on the TMS470R1VFA256 EVM. You may use the jumpers
//  to connect these two pins together. Set a breakpoint on the HETGCR |= ON;
//  instruction in the HET1_Pin0_handler() function and open a watch window and
//  put tmp in the expression location. You may set the format to HEX so you
//  can see 0x2000 in the value window.
//
//  *An external 12Mhz XTAL on OSCIN OSCOUT with proper load caps required*
//
//              TMS-FET470A256
//             -----------------
//         /|\|            OSCIN|-
//          | |                 | 12MHz
//          --|PLLDIS     OSCOUT|-
//            |                 |
//            |            CC0  |---
//            |                 |   |
//            |            CC2  |---
//            |                 |
//
//  John Mangino / Andreas Dannenberg
//  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_PCNT_01_H.h"

volatile unsigned int tmp;
__no_init volatile HETPROGRAM0_UN e_HETPROGRAM0_UN @ 0x00800000;

void MemCopy32(unsigned long *dst, unsigned long *src, int bytes)
{
  for (int i = 0; i < (bytes + 3) / 4; i++)
    *dst++ = *src++;
}

void main(void)
{
  // Set up peripheral registers.
  // First disable interrupts.
  __disable_interrupt();

  PCR = CLKDIV_1;                        // ICLK = SYSCLK/4
  PCR |= PENABLE;                        // enable peripherals

  REQMASK=(1 << CIM_HET1);               // Enable HET Interrupt mask

  // copy HET instructions to HET ram
  MemCopy32((void *) &e_HETPROGRAM0_UN, (void *) HET_INIT0_PST,
            sizeof(HET_INIT0_PST));

  HETGCR = CLK_MASTER + IGNORE_SUSPEND;  //  HET Master Mode, Ignore SW BP
  HETPRY = 0x08;
  HETPFR = 0x0000052b;                   // Set PFR register	

  HETDIR  = 0xFFFFFFFe;                  // Set all HET as GIO outputs
  HETDOUT = 0x813c3dd0;                  // Flash all leds off

  __enable_interrupt();                  // Enable Interrupts
  HETGCR |= ON;                          // Start HET

  while(1);
}

void HET1_Pin0_handler()
{
  HETGCR &= ~ON;
  tmp = HET_L03_0.memory.control_word & 0x000FFFFF;
  HETGCR |= ON;                          // Set breakpoint >>HERE<<
}                                        // and read out 'tmp'

void HET1_irq_handler()
{
  switch ((0xff & HETOFF1)-1)
  {
    case 3  : HET1_Pin0_handler(); break;
  }
}
//------------------------------------------------------------------------------
// TMS470R1A256 Standard Interrupt Handler
//------------------------------------------------------------------------------
#pragma vector = IRQV
__irq __arm void irq_handler(void)
{
  switch ((0xff & IRQIVEC)-1)
  {
    case CIM_HET1  : HET1_irq_handler(); break;
  }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -