Hello Alan,
Here is code for generating PWM on your PORTB all pins.
// Define Variables
unsigned char pulse = 0; // Pulse starts at zero, and lengthens
unsigned char duty = 15; // Duty cycle
unsigned char freq = 255; // Frequency
void main() // Main
{
PTBDD_PTBDD = 1; // Define Port B as output port
while( 1 ) // Loop forever...
{
PTBD_PTBD = 1; // Start pulse
for(pulse = 0; pulse < duty; pulse++); // Lengthen pulse if < duty
PTBD_PTBD = 0; // End pulse
for(pulse = 0; pulse < (freq - duty); pulse++); // Continue until frequency
duty++; // Increment Duty cycle
}
}
Thanks and regards,
Robin