############################################################################### # # # IAR Atmel AVR C/C++ Compiler V4.30F/W32 12/Mar/2008 23:01:38 # # Copyright 1996-2007 IAR Systems. All rights reserved. # # # # Source file = C:\home\kevin\pub\src\bc100_cal\IAR\PWM.c # # Command line = C:\home\kevin\pub\src\bc100_cal\IAR\PWM.c --cpu=tiny861 # # -ms -o C:\home\kevin\pub\src\bc100_cal\IAR\Debug\Obj\ # # -lC C:\home\kevin\pub\src\bc100_cal\IAR\Debug\List\ -lB # # C:\home\kevin\pub\src\bc100_cal\IAR\Debug\List\ # # --initializers_in_flash -z2 --no_cse --no_inline # # --no_code_motion --no_cross_call --no_clustering # # --no_tbaa --debug -DENABLE_BIT_DEFINITIONS -e # # --require_prototypes -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 # # List file = C:\home\kevin\pub\src\bc100_cal\IAR\Debug\List\PWM.lst # # Object file = C:\home\kevin\pub\src\bc100_cal\IAR\Debug\Obj\PWM.r90 # # # # # ############################################################################### C:\home\kevin\pub\src\bc100_cal\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 E000 LDI R16, 0 \ 00000006 BD09 OUT 0x29, R16 48 TCCR1A = 0; // Set normal port operation, disable PWM modes. \ 00000008 E000 LDI R16, 0 \ 0000000A BF00 OUT 0x30, R16 49 TCCR1B = 0; // Stop timer/counter1. \ 0000000C E000 LDI R16, 0 \ 0000000E BD0F OUT 0x2F, R16 50 TCCR1C = 0; // Set normal port operation. \ 00000010 E000 LDI R16, 0 \ 00000012 BD07 OUT 0x27, R16 51 TCCR1D = 0; // No fault protection, normal waveform. \ 00000014 E000 LDI R16, 0 \ 00000016 BD06 OUT 0x26, R16 52 OCR1C = 0; // Reset compare. \ 00000018 E000 LDI R16, 0 \ 0000001A BD0B OUT 0x2B, R16 53 OCR1D = 0; // Reset compare. \ 0000001C E000 LDI R16, 0 \ 0000001E BD0A OUT 0x2A, R16 54 DT1 = 0; // No dead time values. \ 00000020 E000 LDI R16, 0 \ 00000022 BD04 OUT 0x24, R16 55 } \ 00000024 9508 RET \ 00000026 REQUIRE _A_TCCR1A \ 00000026 REQUIRE _A_TCCR1B \ 00000026 REQUIRE _A_OCR1B \ 00000026 REQUIRE _A_OCR1C \ 00000026 REQUIRE _A_OCR1D \ 00000026 REQUIRE _A_PLLCSR \ 00000026 REQUIRE _A_TCCR1C \ 00000026 REQUIRE _A_TCCR1D \ 00000026 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 3001 CPI R16, 1 \ 00000004 F028 BRCS ??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 38 PWM_Start 90 PWM_IncrementDutyCycle 20 PWM_DecrementDutyCycle 20 12 bytes in segment ABSOLUTE 168 bytes in segment CODE 168 bytes of CODE memory 0 bytes of DATA memory (+ 12 bytes shared) Errors: none Warnings: none