#include "pwm.h" void pwm_init(void) { // initialize timer 1 for PWM TCCR1A = (1< 0xffff) ? 0xffff : top; // set timer 1 TOP value ICR1 = top; } void pwm_set_duty_cycle(float duty_cycle) { // calculate OCR1A value from duty cycle uint16_t ocr = (uint16_t)(duty_cycle * ICR1); ocr = (ocr > ICR1) ? ICR1 : ocr; // set OCR1A value OCR1A = ocr; }