21.08.2013 Views

Embedded Systems Design with the Atmel AVR Microcontroller Part II

Embedded Systems Design with the Atmel AVR Microcontroller Part II

Embedded Systems Design with the Atmel AVR Microcontroller Part II

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

162 CHAPTER 6. TIMING SUBSYSTEM<br />

Open_Speed_int = ReadADC(0x03);<br />

//Open Speed Setting unsigned int<br />

//Convert to max duty cycle setting<br />

//0 VDC = 50% = 127, 5 VDC = 100% =255<br />

Open_Speed_float = ((float)(Open_Speed_int)/(float)(0x0400));<br />

//Convert volt to PWM constant 127-255<br />

Open_Speed_int = (unsigned int)((Open_Speed_float * 127) + 128.0);<br />

//Configure PWM clock<br />

TCCR1A = 0xA1;<br />

//freq = resonator/510 = 10 MHz/510<br />

//freq = 19.607 kHz<br />

TCCR1B = 0x01; //no clock source division<br />

//Initiate PWM duty cycle variables<br />

PWM_duty_cycle = 0;<br />

OCR1BH = 0x00;<br />

OCR1BL = (unsigned char)(PWM_duty_cycle);//Set PWM duty cycle CH B to 0%<br />

//Ramp up to Open Speed in 1.6s<br />

OCR1BL = (unsigned char)(PWM_duty_cycle);//Set PWM duty cycle CH B<br />

while (PWM_duty_cycle < Open_Speed_int)<br />

{<br />

if(PWM_duty_cycle < Open_Speed_int) //Increment duty cycle<br />

PWM_duty_cycle=PWM_duty_cycle + PWM_open_incr;<br />

OCR1BL = (unsigned char)(PWM_duty_cycle);//Set PWM duty cycle CH B<br />

}<br />

//Gate continues to open at specified upper speed (PA3)<br />

:<br />

:<br />

:<br />

//*************************************************************************

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!