Program:
/*** @brief Generate PWM on P2.0
* DutyCycle varies from 0-100% and back from 100%- 0%.
*/
#include <lpc17xx.h>
#include "pwm.h"
/* variable to hold dutycycle value */
uint8_t dutyCycle;
int main(void)
{
/* Initialize the PWM Peripheral */
PWM_Init();
/* Infinite loop */
while(1)
{
/* Increase dutycycle for from 0 to 100% */
for(dutyCycle = 0; dutyCycle < 100; dutyCycle++)
{
/* Set the PWM */
PWM_Set_Duty(dutyCycle);
/* set delay */
DELAY_ms(5);
}
for(dutyCycle = 100; dutyCycle > 0; dutyCycle--)
{
/* Set the PWM */
PWM_Set_Duty(dutyCycle);
/* set delay */
DELAY_ms(5);
}
}
}
Hardware Connections:
Connect positive of the CRO to pin P2.0
Connect negative of the CRO to the GND (development board)
Output:
A square wave is seen on CRO who pulse width varies from 0% - 100% and from 100% - 0%
No comments:
Post a Comment