1 ///////////////////////////////////////////////////////////////////////////////
\r
3 // IAR Atmel AVR C/C++ Compiler V4.30F/W32 12/Mar/2008 23:01:38 /
\r
4 // Copyright 1996-2007 IAR Systems. All rights reserved. /
\r
6 // Source file = C:\home\kevin\pub\src\bc100_cal\IAR\PWM.c /
\r
7 // Command line = C:\home\kevin\pub\src\bc100_cal\IAR\PWM.c /
\r
8 // --cpu=tiny861 -ms -o C:\home\kevin\pub\src\bc100_cal\IA /
\r
9 // R\Debug\Obj\ -lC C:\home\kevin\pub\src\bc100_cal\IAR\De /
\r
10 // bug\List\ -lB C:\home\kevin\pub\src\bc100_cal\IAR\Debug /
\r
11 // \List\ --initializers_in_flash -z2 --no_cse /
\r
12 // --no_inline --no_code_motion --no_cross_call /
\r
13 // --no_clustering --no_tbaa --debug /
\r
14 // -DENABLE_BIT_DEFINITIONS -e --require_prototypes -I /
\r
15 // "C:\Program Files\IAR Systems\Embedded Workbench /
\r
16 // 4.0\avr\INC\" -I "C:\Program Files\IAR /
\r
17 // Systems\Embedded Workbench 4.0\avr\INC\CLIB\" /
\r
18 // --eeprom_size 512 /
\r
19 // List file = C:\home\kevin\pub\src\bc100_cal\IAR\Debug\List\PWM.s90 /
\r
22 ///////////////////////////////////////////////////////////////////////////////
\r
26 RSEG CSTACK:DATA:NOROOT(0)
\r
27 RSEG RSTACK:DATA:NOROOT(0)
\r
29 PUBLIC PWM_DecrementDutyCycle
\r
30 PUBLIC PWM_IncrementDutyCycle
\r
53 // C:\home\kevin\pub\src\bc100_cal\IAR\PWM.c
\r
54 // 1 /* This file has been prepared for Doxygen automatic documentation generation.*/
\r
55 // 2 /*! \file *********************************************************************
\r
58 // 5 * Functions for use of PWM
\r
60 // 7 * Contains functions for initializing and controlling PWM output.
\r
62 // 9 * \par Application note:
\r
63 // 10 * AVR458: Charging Li-Ion Batteries with BC100\n
\r
64 // 11 * AVR463: Charging NiMH Batteries with BC100
\r
66 // 13 * \par Documentation
\r
67 // 14 * For comprehensive code documentation, supported compilers, compiler
\r
68 // 15 * settings and supported devices see readme.html
\r
71 // 18 * Atmel Corporation: http://www.atmel.com \n
\r
72 // 19 * Support email: avr@atmel.com
\r
76 // 23 * $Revision: 2299 $
\r
78 // 25 * $URL: http://svn.norway.atmel.com/AppsAVR8/avr458_Charging_Li-Ion_Batteries_with_BC100/tag/20070904_release_1.0/code/IAR/PWM.c $
\r
79 // 26 * $Date: 2007-08-23 12:55:51 +0200 (to, 23 aug 2007) $\n
\r
80 // 27 ******************************************************************************/
\r
82 // 29 #include <ioavr.h>
\r
84 ASEGN ABSOLUTE:DATA:NOROOT,050H
\r
85 // <unnamed> volatile __io _A_TCCR1A
\r
89 ASEGN ABSOLUTE:DATA:NOROOT,04fH
\r
90 // <unnamed> volatile __io _A_TCCR1B
\r
94 ASEGN ABSOLUTE:DATA:NOROOT,04dH
\r
95 // <unnamed> volatile __io _A_OCR1A
\r
99 ASEGN ABSOLUTE:DATA:NOROOT,04cH
\r
100 // <unnamed> volatile __io _A_OCR1B
\r
104 ASEGN ABSOLUTE:DATA:NOROOT,04bH
\r
105 // <unnamed> volatile __io _A_OCR1C
\r
109 ASEGN ABSOLUTE:DATA:NOROOT,04aH
\r
110 // <unnamed> volatile __io _A_OCR1D
\r
114 ASEGN ABSOLUTE:DATA:NOROOT,049H
\r
115 // <unnamed> volatile __io _A_PLLCSR
\r
119 ASEGN ABSOLUTE:DATA:NOROOT,047H
\r
120 // <unnamed> volatile __io _A_TCCR1C
\r
124 ASEGN ABSOLUTE:DATA:NOROOT,046H
\r
125 // <unnamed> volatile __io _A_TCCR1D
\r
129 ASEGN ABSOLUTE:DATA:NOROOT,044H
\r
130 // <unnamed> volatile __io _A_DT1
\r
134 ASEGN ABSOLUTE:DATA:NOROOT,037H
\r
135 // <unnamed> volatile __io _A_DDRB
\r
139 ASEGN ABSOLUTE:DATA:NOROOT,020H
\r
140 // <unnamed> volatile __io _A_TCCR1E
\r
144 // 31 #include "enums.h"
\r
146 // 33 #include "main.h"
\r
147 // 34 #include "PWM.h"
\r
148 // 35 #include "time.h"
\r
151 // 38 //******************************************************************************
\r
153 // 40 //******************************************************************************
\r
154 // 41 /*! \brief Stops PWM output
\r
158 RSEG CODE:CODE:NOROOT(1)
\r
159 // 44 void PWM_Stop(void)
\r
162 // 46 OCR1B = 0; // Reset compare level.
\r
165 // 47 PLLCSR = 0; // Disable PLL, switch to synchronous CLK mode.
\r
168 // 48 TCCR1A = 0; // Set normal port operation, disable PWM modes.
\r
171 // 49 TCCR1B = 0; // Stop timer/counter1.
\r
174 // 50 TCCR1C = 0; // Set normal port operation.
\r
177 // 51 TCCR1D = 0; // No fault protection, normal waveform.
\r
180 // 52 OCR1C = 0; // Reset compare.
\r
183 // 53 OCR1D = 0; // Reset compare.
\r
186 // 54 DT1 = 0; // No dead time values.
\r
202 // 58 /*! \brief Initializes and starts PWM output
\r
204 // 60 * Initializes timer1 for use as a PWM with a clock rate of 64 MHz.\n
\r
205 // 61 * Its comparator is connected to PB3 and will output high until timer1 reaches
\r
206 // 62 * the value of OCR1B. It is then dropped to 0.\n
\r
207 // 63 * The comparator outputs high again when the counter overflows, which will
\r
208 // 64 * happen at a rate of 250 kHz.
\r
211 RSEG CODE:CODE:NOROOT(1)
\r
212 // 66 void PWM_Start(void)
\r
215 // 68 // Clear OC1B on compare match, enable PWM on comparator OCR1B.
\r
216 // 69 TCCR1A = (1<<COM1B1)|(0<<COM1B0)|(1<<PWM1B);
\r
220 // 71 // Non-inverted PWM, T/C stopped.
\r
225 // 74 // Copy shadow bits, disconnect OC1D.
\r
226 // 75 TCCR1C = (TCCR1A & 0xF0);
\r
231 // 77 // No fault protection, use phase & frequency correct PWM.
\r
232 // 78 TCCR1D = (0<<WGM11)|(1<WGM10);
\r
236 // 80 // Does not matter -- PWM6 mode not used.
\r
241 // 83 // Does not matter -- OC1A is disabled.
\r
246 // 86 // Set reset compare level. (Offset is used, or JumperCheck() will fail.)
\r
247 // 87 OCR1B = PWM_OFFSET;
\r
251 // 89 // TOP value for PWM, f(PWM) = 64MHz / 255 = 251kHz.
\r
252 // 90 OCR1C = 0xFF;
\r
256 // 92 // Does not matter -- OC1D is disabled.
\r
261 // 95 // No dead time values.
\r
266 // 98 // Set PWM port pin to output.
\r
267 // 99 DDRB |= (1<<PB3);
\r
270 // 101 // Enable PLL, use full speed mode.
\r
271 // 102 PLLCSR = (0<<LSM) | (1<<PLLE);
\r
275 // 104 // Use general timer and wait 1 ms for PLL lock to settle.
\r
276 // 105 Time_Set(TIMER_GEN,0,0,1);
\r
284 // 107 }while(Time_Left(TIMER_GEN));
\r
291 // 109 // Now wait for PLL to lock.
\r
293 // 111 }while((PLLCSR & (1<<PLOCK)) == 0);
\r
300 // 113 // Use PLL as clock source.
\r
301 // 114 PLLCSR |= (1<<PCKE);
\r
306 // 116 // CLK PCK = 64MHz / 1 = 64MHz.
\r
307 // 117 TCCR1B |= (0<<CS13)|(0<<CS12)|(0<<CS11)|(1<<CS10);
\r
327 // 121 /*! \brief Increments the PWM duty cycle, if not already at max
\r
329 // 123 * \retval TRUE Success, duty cycle could be incremented.
\r
330 // 124 * \retval FALSE Failure, duty cycle already at maximum.
\r
333 RSEG CODE:CODE:NOROOT(1)
\r
334 // 126 unsigned char PWM_IncrementDutyCycle(void){
\r
335 PWM_IncrementDutyCycle:
\r
337 // 128 if (OCR1B < PWM_MAX) {
\r
340 BRCC ??PWM_IncrementDutyCycle_0
\r
345 // 130 return(TRUE);
\r
349 // 132 return(FALSE);
\r
350 ??PWM_IncrementDutyCycle_0:
\r
358 // 137 /*! \brief Decrements the PWM duty cycle, if not already at zero.
\r
360 // 139 * \retval TRUE Success, duty cycle could be decremented.
\r
361 // 140 * \retval FALSE Failure, duty cycle already at zero.
\r
364 RSEG CODE:CODE:NOROOT(1)
\r
365 // 142 unsigned char PWM_DecrementDutyCycle(void){
\r
366 PWM_DecrementDutyCycle:
\r
368 // 144 if (OCR1B > 0) {
\r
371 BRCS ??PWM_DecrementDutyCycle_0
\r
376 // 146 return(TRUE);
\r
380 // 148 return(FALSE);
\r
381 ??PWM_DecrementDutyCycle_0:
\r
388 ASEGN ABSOLUTE:DATA:NOROOT,01cH
\r
391 ASEGN ABSOLUTE:DATA:NOROOT,01dH
\r
394 ASEGN ABSOLUTE:DATA:NOROOT,01eH
\r
397 ASEGN ABSOLUTE:DATA:NOROOT,01fH
\r
402 // 12 bytes in segment ABSOLUTE
\r
403 // 168 bytes in segment CODE
\r
405 // 168 bytes of CODE memory
\r
406 // 0 bytes of DATA memory (+ 12 bytes shared)
\r