/* Example Code for a simple R2R-DA on Port D This example code is in the public domain. */ unsigned char sinus[256]; unsigned char x = 0; unsigned char y = 0; void setup() { // initialize PORT D as output port DDRD = 0xff; // initialize timer1 noInterrupts(); // disable all interrupts TCCR1A = 0; TCCR1B = 0; TCNT1 = 0; OCR1A = 3; // compare match register for timing TCCR1B |= (1 << WGM12); // CTC mode TCCR1B |= (1 << CS11); // CS10 = no prescaler, CS11 = 8, CS12 = 256, CS11|CS10 = 64, CS12||CS10 = 1024 TIMSK1 |= (1 << OCIE1A); // enable timer compare interrupt interrupts(); // enable all interrupts // For some reason, this code must be here or the output will not work for(unsigned char i=0;i<256;i++) sinus[i]=(unsigned char) ((float)sin((2*PI*i)/255) *127.0 + 127.0); } ISR(TIMER1_COMPA_vect) { // DC - for measurement of voltage at specific steps //PORTD = 128; /* // Triangle if(!y) // aufwärts zählen { x++; if(x == 255) y = 1; } else // abwärts { x--; if(x == 0) y = 0; } PORTD = x; */ // Sinus PORTD = sinus[x++]; } void loop() { }