Ktam3874/pitx software guide – Kontron KTAM3874-pITX User Manual

Page 62

Advertising
background image

KTD-S0057-I

Page 58 Linux® Programming Examples (DebianTM)


KTAM3874/pITX Software Guide


/* Set PWM mode */

write_timer_reg (TCLR, (read_timer_reg (TCLR) &

~(TCLR_GPOCFG | TCLR_PT | TCLR_TRG | TCLR_SCPWM)) |

(TCLR_PT

|

TCLR_TRGOVFLMAT));

return

0;

}


int start_pwm (unsigned long duty_cycle)
{
unsigned

long

val;

/* Check the duty cycle value */

if ((duty_cycle < 0) || (duty_cycle > DUTY_MAX))

return

-1;

/* Set the reload value */

write_timer_reg (TCLR, read_timer_reg (TCLR) | TCLR_AR);

write_timer_reg (TLDR, RELOAD_VAL);

write_timer_reg (TTGR, 0);

/* Set the match value */

write_timer_reg (TCLR, read_timer_reg (TCLR) | TCLR_CE);

val = (FREQ_VAL * duty_cycle) / DUTY_MAX;

write_timer_reg (TMAR, RELOAD_VAL + val);

/* Write the counter value */

write_timer_reg (TCRR, -1);

/* Start the timer */

if (! (read_timer_reg (TCLR) & TCLR_ST))

write_timer_reg (TCLR, read_timer_reg (TCLR) | TCLR_ST);

return

0;

}


int stop_pwm (void)
{
int

i;

if (read_timer_reg (TCLR) & TCLR_ST)

{

/* Stop the timer */

write_timer_reg (TCLR, read_timer_reg (TCLR) & ~TCLR_ST);

/* Check if timer off */

for (i = 0; i < STOP_TIMEOUT; i++)

if (! (read_timer_reg (TCLR) & TCLR_ST)) break;

if (i >= STOP_TIMEOUT)

return

-1;

}

return

0;

}

Advertising
This manual is related to the following products: