/*
	BL17PWM3.C
	
	Use with BL1700 boards.
		
	This program demonstrates how to use pulse width modulation on 4 outputs
	using higher level calls.

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

#define RUNKERNEL 1
#use vdriver.lib
#use srtk.lib
#use ezioBL17.lib

#funcchain _srtk_hightask _eioBrdAORf

#define DELAYCONST 0x1000

main() {
	auto unsigned dim;
	auto unsigned i;

	VdInit();
	eioBrdInit(0);					// initialize board
	_eioSetupAO1st();
	init_srtkernel();
	while (1) {
		for (dim = 2; dim <= 256; dim=dim*3/2) {
			eioBrdAO(BankB(0),dim);
			for (i = 0; i < DELAYCONST; ++i);
		}
		for (dim = 256; dim > 0; dim=dim*2/3) {
			eioBrdAO(BankB(1),dim);
			for (i = 0; i < DELAYCONST; ++i);
		}
		for (dim = 2; dim <= 256; dim=dim*3/2) {
			eioBrdAO(BankB(2),dim);
			for (i = 0; i < DELAYCONST; ++i);
		}
		for (dim = 256; dim > 0; dim=dim*2/3) {
			eioBrdAO(BankB(3),dim);
			for (i = 0; i < DELAYCONST; ++i);
		}
	}
}


