############################################################################### # # # IAR Atmel AVR C/C++ Compiler V4.30F/W32 13/Mar/2008 04:52:01 # # Copyright 1996-2007 IAR Systems. All rights reserved. # # # # Source file = C:\home\kevin\pub\src\bc100\IAR\PWM.c # # Command line = C:\home\kevin\pub\src\bc100\IAR\PWM.c # # --cpu=tiny861 -ms -o C:\home\kevin\pub\src\bc10 # # 0\IAR\Release\Obj\ -D NDEBUG -lCN # # C:\home\kevin\pub\src\bc100\IAR\Release\List\ # # -lB C:\home\kevin\pub\src\bc100\IAR\Release\Lis # # t\ --initializers_in_flash -s9 --no_cross_call # # --no_tbaa -DENABLE_BIT_DEFINITIONS -e -I # # "C:\Program Files\IAR Systems\Embedded # # Workbench 4.0\avr\INC\" -I "C:\Program # # Files\IAR Systems\Embedded Workbench # # 4.0\avr\INC\CLIB\" --eeprom_size 512 # # --misrac=5-9,11-12,14,16-17,19-21,24-26,29-32, # # 34-35,38-39,42-43,46,50,52-54,56-59,61-62, # # 64-65,68-80,83-84,87-91,94-95,98-100,103-110, # # 112-126 # # Enabled MISRA C rules = 5-9,11-12,14,16-17,19-21,24-26,29-32,34-35, # # 38-39,42-43,46,50,52-54,56-59,61-62,64-65, # # 68-80,83-84,87-91,94-95,98-100,103-110,112-126 # # Checked = 5,7-9,11-12,14,17,19-21,24,29-32,34-35,38-39, # # 42,46,50,52-54,56-59,61-62,64,68-69,71-80, # # 83-84,87-89,91,94-95,98,100,104-105,108-109, # # 112-115,118-126 # # Not checked = 6,16,25-26,43,65,70,90,99,103,106-107,110, # # 116-117 # # List file = C:\home\kevin\pub\src\bc100\IAR\Release\List\PW # # M.lst # # Object file = C:\home\kevin\pub\src\bc100\IAR\Release\Obj\PWM # # .r90 # # # # # ############################################################################### C:\home\kevin\pub\src\bc100\IAR\PWM.c 1 /* This file has been prepared for Doxygen automatic documentation generation.*/ 2 /*! \file ********************************************************************* 3 * 4 * \brief 5 * Functions for use of PWM 6 * 7 * Contains functions for initializing and controlling PWM output. 8 * 9 * \par Application note: 10 * AVR458: Charging Li-Ion Batteries with BC100\n 11 * AVR463: Charging NiMH Batteries with BC100 12 * 13 * \par Documentation 14 * For comprehensive code documentation, supported compilers, compiler 15 * settings and supported devices see readme.html 16 * 17 * \author 18 * Atmel Corporation: http://www.atmel.com \n 19 * Support email: avr@atmel.com 20 * 21 * 22 * $Name$ 23 * $Revision: 2299 $ 24 * $RCSfile$ 25 * $URL: http://svn.norway.atmel.com/AppsAVR8/avr458_Charging_Li-Ion_Batteries_with_BC100/tag/20070904_release_1.0/code/IAR/PWM.c $ 26 * $Date: 2007-08-23 12:55:51 +0200 (to, 23 aug 2007) $\n 27 ******************************************************************************/ 28 29 #include \ In segment ABSOLUTE, at 0x50 \ volatile __io _A_TCCR1A \ _A_TCCR1A: \ 00000000 DS 1 \ In segment ABSOLUTE, at 0x4f \ volatile __io _A_TCCR1B \ _A_TCCR1B: \ 00000000 DS 1 \ In segment ABSOLUTE, at 0x4d \ volatile __io _A_OCR1A \ _A_OCR1A: \ 00000000 DS 1 \ In segment ABSOLUTE, at 0x4c \ volatile __io _A_OCR1B \ _A_OCR1B: \ 00000000 DS 1 \ In segment ABSOLUTE, at 0x4b \ volatile __io _A_OCR1C \ _A_OCR1C: \ 00000000 DS 1 \ In segment ABSOLUTE, at 0x4a \ volatile __io _A_OCR1D \ _A_OCR1D: \ 00000000 DS 1 \ In segment ABSOLUTE, at 0x49 \ volatile __io _A_PLLCSR \ _A_PLLCSR: \ 00000000 DS 1 \ In segment ABSOLUTE, at 0x47 \ volatile __io _A_TCCR1C \ _A_TCCR1C: \ 00000000 DS 1 \ In segment ABSOLUTE, at 0x46 \ volatile __io _A_TCCR1D \ _A_TCCR1D: \ 00000000 DS 1 \ In segment ABSOLUTE, at 0x44 \ volatile __io _A_DT1 \ _A_DT1: \ 00000000 DS 1 \ In segment ABSOLUTE, at 0x37 \ volatile __io _A_DDRB \ _A_DDRB: \ 00000000 DS 1 \ In segment ABSOLUTE, at 0x20 \ volatile __io _A_TCCR1E \ _A_TCCR1E: \ 00000000 DS 1 30 31 #include "enums.h" 32 33 #include "main.h" 34 #include "PWM.h" 35 #include "time.h" 36 37 38 //****************************************************************************** 39 // Functions 40 //****************************************************************************** 41 /*! \brief Stops PWM output 42 * 43 */ \ In segment CODE, align 2, keep-with-next 44 void PWM_Stop(void) \ PWM_Stop: 45 { 46 OCR1B = 0; // Reset compare level. \ 00000000 E000 LDI R16, 0 \ 00000002 BD0C OUT 0x2C, R16 47 PLLCSR = 0; // Disable PLL, switch to synchronous CLK mode. \ 00000004 BD09 OUT 0x29, R16 48 TCCR1A = 0; // Set normal port operation, disable PWM modes. \ 00000006 BF00 OUT 0x30, R16 49 TCCR1B = 0; // Stop timer/counter1. \ 00000008 BD0F OUT 0x2F, R16 50 TCCR1C = 0; // Set normal port operation. \ 0000000A BD07 OUT 0x27, R16 51 TCCR1D = 0; // No fault protection, normal waveform. \ 0000000C BD06 OUT 0x26, R16 52 OCR1C = 0; // Reset compare. \ 0000000E BD0B OUT 0x2B, R16 53 OCR1D = 0; // Reset compare. \ 00000010 BD0A OUT 0x2A, R16 54 DT1 = 0; // No dead time values. \ 00000012 BD04 OUT 0x24, R16 55 } \ 00000014 9508 RET \ 00000016 REQUIRE _A_TCCR1A \ 00000016 REQUIRE _A_TCCR1B \ 00000016 REQUIRE _A_OCR1B \ 00000016 REQUIRE _A_OCR1C \ 00000016 REQUIRE _A_OCR1D \ 00000016 REQUIRE _A_PLLCSR \ 00000016 REQUIRE _A_TCCR1C \ 00000016 REQUIRE _A_TCCR1D \ 00000016 REQUIRE _A_DT1 56 57 58 /*! \brief Initializes and starts PWM output 59 * 60 * Initializes timer1 for use as a PWM with a clock rate of 64 MHz.\n 61 * Its comparator is connected to PB3 and will output high until timer1 reaches 62 * the value of OCR1B. It is then dropped to 0.\n 63 * The comparator outputs high again when the counter overflows, which will 64 * happen at a rate of 250 kHz. 65 */ \ In segment CODE, align 2, keep-with-next 66 void PWM_Start(void) \ PWM_Start: 67 { 68 // Clear OC1B on compare match, enable PWM on comparator OCR1B. 69 TCCR1A = (1< 0) { \ 00000000 B50C IN R16, 0x2C \ 00000002 2300 TST R16 \ 00000004 F029 BREQ ??PWM_DecrementDutyCycle_0 145 OCR1B -= 1; \ 00000006 B50C IN R16, 0x2C \ 00000008 950A DEC R16 \ 0000000A BD0C OUT 0x2C, R16 146 return(TRUE); \ 0000000C E001 LDI R16, 1 \ 0000000E 9508 RET 147 } else { 148 return(FALSE); \ ??PWM_DecrementDutyCycle_0: \ 00000010 E000 LDI R16, 0 \ 00000012 9508 RET \ 00000014 REQUIRE _A_OCR1B 149 } 150 } Maximum stack usage in bytes: Function CSTACK RSTACK -------- ------ ------ PWM_DecrementDutyCycle 0 2 PWM_IncrementDutyCycle 0 2 PWM_Start 0 2 -> Time_Set 0 2 -> Time_Left 0 2 PWM_Stop 0 2 Segment part sizes: Function/Label Bytes -------------- ----- _A_TCCR1A 1 _A_TCCR1B 1 _A_OCR1A 1 _A_OCR1B 1 _A_OCR1C 1 _A_OCR1D 1 _A_PLLCSR 1 _A_TCCR1C 1 _A_TCCR1D 1 _A_DT1 1 _A_DDRB 1 _A_TCCR1E 1 PWM_Stop 22 PWM_Start 80 PWM_IncrementDutyCycle 20 PWM_DecrementDutyCycle 20 12 bytes in segment ABSOLUTE 142 bytes in segment CODE 142 bytes of CODE memory 0 bytes of DATA memory (+ 12 bytes shared) Errors: none Warnings: none