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

📄 ata6824_defs.c

📁 基于Atmel ATMega88+ATA682的应用实例 主要功能包括: 1) PWM输出控制 2) H-Bridge,4 POWER FET 驱动 3) 模拟量比较
💻 C
字号:
/*
**
****************************************************************************
**
**
**             Copyright (c) 2007 - Atmel Corporation
**             Proprietaty Information
**
** Project    	: ATMEGA88 + ATA6824 High Temperature H-bridge System
** Module     	: ATA6824_defs.c
** Description	: High temperature DC motor control.
**                To be used with "High temperature H-bridge System" board
**
** Version :     Date:         Author:      Comment:
**    1.0        05.03.2007    F.G.          Creation 
**
** LICENSE -
**
** ATMEL - 2007
** All software programs are provided 'as is' without warranty of any kind:
** Atmel does not state the suitability of the provided materials for any
** purpose. Atmel hereby disclaim all warranties and conditions with regard
** to the provided software, including all implied warranties, fitness for
** a particular purpose, title and non-infringement.In no event will Atmel
** be liable for any indirect or consequential damages or any damages
** whatsoever resulting from the usage of the software program.
****************************************************************************
**
*/
/*_____ I N C L U D E S ____________________________________________________*/
#include "config.h"
#include "ATA6824_defs.h"
#include "Timer0_PWM.h"   // Generates a time base required by WD refresh routine

/*_____ M A C R O S ________________________________________________________*/

/*_____ D E F I N I T I O N S ______________________________________________*/

/*_____ P R O T O T Y P E S - D E C L A R A T I O N ________________________*/

/*_____ G L O B A L S ______________________________________________________*/

ATA6824_diag_mgt_t  ATA6824_diag_mgt;   //<! Allows to manage failures



/*! @brief refresh_watchdog Refreshes the ATA6824 external watchdog according
 *  to its required refresh period (fixed by an external resistor). 
 *
 *  This routine uses the software time base to generate rising edges on the
 *  WD trigger pin of the ATA6824 during the open window t2 (see datasheet).
 *
 *  @warning : changing Timer 0 overflow period will affect the time base and
 *  so the watchdog refresh period.
 */
void refresh_ATA6824_watchdog(void)
{
  static unsigned int last_count=0;     // remembers the last WD trigger instant
  signed int dif;                   
  
  // Compute elapsed time since the last WD trigger has occured
  dif = last_count - (U16)(time_count_1s.count);
  
  if (dif<0) 
    {dif = dif + ONE_SECOND; };         // take care of time count overflows
  
  // Check the elapsed time since the last WD trigger
  if (dif > WD_TIME_TRIG)
  {
    // Toggle the Watchdog trigger pin when half of the period has elapsed
    TOGGLE_WD_TRIG();                     
    last_count = time_count_1s.count;   // remember the last WD trigger instant
  }
}



/*! @brief Diag_inputs_ISR_init set-up Pin change interrupts on diagnotics inputs
 *  - Enable PCINT14 to 8 mask
 *  - Configure DG1, DG2 and DG3 resp. PCINT10, PCINT11 and PCINT12
 *  to generate interrupts on both rising or falling edges.
 */ 
void Diag_inputs_ISR_init(void)
{
    /*init PCINT1  Pin change interrupt initialisation */
    // PCINT14...8 interrupt pins enabled
  PCICR |= 1 << PCIE1;   
    // PCINT10/11/12 interrupt pin are enabled    
  PCMSK1 |= (1 << PCINT12) | (1 << PCINT11) | (1 << PCINT10);  
}



/*! @brief Diag123_ISR() handles DG1, DG2 and DG3 pin change interrupts
 *  This interrupt subroutine allow to generate interrupt on diagnostic pin
 *  changes. It will latch DG2 and DG3 diagnostic signals (charge pump failure/
 *  undervoltage/overvoltage and Short-ciruit defaults). It will also report the
 *  Over-temperature condition (not latched by software).
 */
#if defined(__ICCAVR__)       //IAR COMPILER USED
#pragma vector= PCINT1_vect   //Pin Change interrupt 10 vector for ATmega88
__interrupt void Diag123_ISR (void)
#elif defined (__AVR__)       // Avr-gcc compiler used
ISR(PCINT1_vect)
#endif
{
  if (GET_DG1_STATUS())
    ATA6824_diag_mgt.dg1 = LATCHED_FAILURE;   // latch Short-circuit failure
  
  if (GET_DG2_STATUS())
    ATA6824_diag_mgt.dg2 = LATCHED_FAILURE;   // latch Charge pump or voltage failure
  
  if (GET_DG3_STATUS())
    ATA6824_diag_mgt.dg3 = WARNING;           // signal Over-temperature warning
  else
    ATA6824_diag_mgt.dg3 = NO_FAILURE;        // Clear Over-temperature warning
}



/*! @brief clear_faults clears software-latched faults
 *  When a failure has been latched and is no more present, unlatch it
 */
void clear_faults(void)
{
  if ( (ATA6824_diag_mgt.dg1 == LATCHED_FAILURE) && (!GET_DG1_STATUS()) )
  { 
    // Unlatch short-cicuit detected if no more present
    ATA6824_diag_mgt.dg1 = NO_FAILURE;  
  }
  
  if ( (ATA6824_diag_mgt.dg2 == LATCHED_FAILURE) && (!GET_DG2_STATUS()) )
  { 
    // Unlatch pump charge failure, undervoltage or overvoltage if no more present
    ATA6824_diag_mgt.dg2 = NO_FAILURE;     
  }
}

⌨️ 快捷键说明

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