// CPU frequency 9.6MHz // Temperature sensor (TMP36) on ADC3 (PB3) // MosFet output on OC0A (PB0) int main(void) { int16_t t; ADMUX = 0x43; // internal reference, right adjust, ADC3 ADCSRA = 0x87; // ADC enable, prescaler to 128 (175us/conv.) TCCR0A = 0x83; // fast pwm on OC0A TCCR0B = 0x01; // prescaler to 1 => f=37.5kHz while(1) { ADCSRA |= 0x40; // start conversion while(ADCSRA & 0x40); // wait for completion t = ADC - 665; t *= 49; // approx. t /= 32; // 1.6451 if(t < 0) t = 0; // limits if(t > 255) t = 255; // OCR0A = t; } return 0; }