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

📄 timer0_pwm.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     	: Timer0_PWM.c
** Description	: High temperature DC motor control. Timer0 generates PWM
**                To be used with "High temperature H-bridge System" board
**
** Version :     Date:         Author:      Comment:
**    1.0        26.01.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 "Timer0_PWM.h"

/*_____ 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 ______________________________________________________*/
SoftTimer_t time_count_1s;    //!< variable used to decrement to zero each elapsed second    

/*! @brief Timer0_start configures timer 0 for PWM on Output compare 0 B
 * Configures timer as following:
 *  - Count clock is Fosc/1 (prescaler -> clk/1), 8Mhz
 *  - Fast PWM mode use
 *  - Uses output compare pin OCR0B
 *  - OC0B is set from 0 to OCR0B, then cleared up to timer0 TOP
 *  - Waveform generator configured : Timer 0 top is 0xFF (8 bit count)
 *  - Starts with a 0% PWM ratio
 */
void Timer0_start(void)
{
  // clear output compare pin at OCR0B compare match, set at TOP (0xFF) 
  TCCR0A = (1<<COM0B1) | (1<<WGM01) | (1<<WGM00);   
  // Set Fast PWM mode with output compare : Wave form generation Fast PWM, 
  // top counter value 0xFF, clk/1 prescaler -> Overflow (PWM) period = 32祍
  TCCR0B = (1<<CS00);
  // PWM ratio set to zero
  TIMER0_SET_OC0B_PWM (0x00);
}



/*! @brief manage_time_base Should be executed in background to generate
 * a non critical time base.
 * Time base counter should be decremented each 32祍 on Timer0 overflow.
 * When Time base counter reaches 0, one second has elapsed. A flag is set and 
 * counter is set again to its init value.
 */
void manage_time_base(void)
{
  if (TIFR0 & (1<<TOV0))          // Has Timer 0 overflowed ?
  {
    if (time_count_1s.count > 0)
      time_count_1s.count--;
    else
    {
      time_count_1s.count = ONE_SECOND;  // 31250 * 32祍 --> 1s period counter
      time_count_1s.ovf = true;
    }
    TIFR0 |= (1<<TOV0);           // Clear Timer 0 overflow flag bit
  }
}


⌨️ 快捷键说明

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