/*
	BL17PWM4.C
	
	Use with BL1700 boards.
		
	This program demonstrates how to use pulse width modulation on one output
	using higher level calls.  See sample program bl17pwm3.c for PWM on four
	outputs simultaneously.

	Instructions:
	Connect Bank B output, 0, to an LED or some device to get a visual.
	Install jumper on J8, pins 4-6.
	Compile and run this program.
*/

#use eziobl17.lib
#define OUTCHAN 0		//Bank B output 0

main() {
	auto unsigned dutyCycle;
	auto int ramp;

	eioBrdInit(0);				// initialize board
	_eioSetupAO1st();			//initialize PWM
	dutyCycle = 0;
	ramp = 1;
	
	while (1) {
		eioBrdAO(BankB(OUTCHAN), dutyCycle);	//change the cycle
		if (_eioBrdAORf() == -1)						//check refresh	
			break;
		if (dutyCycle == 256)						//ramp down
			ramp = -1;
		else
			if (dutyCycle == 0)						//ramp up
				ramp = 1;
		dutyCycle = dutyCycle + ramp;
		hitwd();											//hit watchdog
	}
	printf("PWM refresh failed\n");
}


