2 * C Implementation: pwm
4 * Description: configuration of PWM unit
7 * Author: LAGARRIGUE <glagarri@etud.insa-toulouse.fr>, (C) 2005
9 * Copyright: See COPYING file that comes with this distribution
18 #define MINFREQ (PCLK/(0xFFFFFFFF))
21 * Initializes PWM frequency with match0 register
22 * @param freq frequency in Hz
24 void Init_PWM(int freq
)
26 if ((freq
<= PCLK
) | (freq
>= MINFREQ
))
28 PWMPR
= 0x00000000; //no prescaler
29 PWMMCR
= 0x00000002; // on match with MATCH0 Register, reset the counter
30 PWMMR0
= (int)(PCLK
/(freq
));
37 * Initilizes and sets the duty cycle of the desired pwm channel
38 * @param channel = channel number (1,2,3,4,5,6)
39 * @param duty_cycle = float between 0 and 1
41 void Set_PWM (int channel
, float duty_cycle
)
44 Pwmmatch
= (int) (duty_cycle
* PWMMR0
);
48 //PINSEL0 |= ...; /* Enable P0.7, 8 and P0.9 as alternate PWM outputs functions*/
51 //PWMPCR = ...; /* single edge control only*/
53 //PWMMRX = 0x500; /* set falling edge of PWM channel X */
55 //PWMLER = 0x..; /* enable shadow latch for match 1 - 6 */
66 PINSEL0
|= 0x00000002;
67 PINSEL0
&= 0xFFFFFFFE;
74 PINSEL0
|= 0x00008000;
75 PINSEL0
&= 0xFFFFBFFF;
82 PINSEL0
|= 0x00000008;
83 PINSEL0
&= 0xFFFFFFFB;
89 PINSEL0
|= 0x00020000;
90 PINSEL0
&= 0xFFFEFFFF;
97 PINSEL1
|= 0x00000400;
98 PINSEL1
&= 0xFFFFF7FF;
105 PINSEL0
|= 0x00080000;
106 PINSEL0
&= 0xFFFBFFFF;
116 * Resets the counter and runs the PWM unit
121 PWMTCR
= 0x2; /* Reset counter and prescaler */
122 PWMTCR
= 0x9; /* enable counter and PWM, release counter from reset */
127 * Stops PWM unit and resets the timer
133 for (i
=1 ; i
< 7 ; i
++)