/* PPWM Generator - BT 4_20_15 */ /* This program is a simple PWM generator */ /* Basically all it is doing is shifting 1s and 0s out of Port B */ /* The realtime delay creates the 80/20 duty cycles waveform */ /* */ #include //standard Atmel include static void PWM_Generator() { uint8_t i; while(1){ for (i = 0; i < 250; i++) { PINB |= (1 << PINB3) | (1 << PINB2) | (1 << PINB1) | (1 << PINB0); //shifting bytes to create a toggle at Pin B "1" delay_us(3000 * 2 / 10); //20% of 3mSec for the "1" part of the pulse PINB |= (1 << PINB3) | (1 << PINB2) | (1 << PINB1) | (1 << PINB0); //shifting bytes to create a toggle at Pin B "0" delay_us(3000 * 8 / 10); //80% of 3mSec for the "0" part of the pulse } for (i = 0; i < 250; i++) { PINB |= (1 << PINB3) | (1 << PINB2) | (1 << PINB1) | (1 << PINB0); //shifting bytes to create a toggle at Pin B "1" delay_us(3000 * 8 / 10); //80% of 3mSec for the "1" part of the pulse PINB |= (1 << PINB3) | (1 << PINB2) | (1 << PINB1) | (1 << PINB0); //shifting bytes to create a toggle at Pin B "0" delay_us(3000 * 2 / 10); //20% of 3mSec for the "0" part of the pulse } }