PWM zFuass  Ver.1.0.
Lukas H.
start.cpp
Go to the documentation of this file.
1 
22 #include <Arduino.h>
23 
24 //#define DEBUG_LCD disable Display for simulation; attention: is very slow so be careful within ISR
25 #include "_debug.h"
26 #define PD6 6
27 #define _MAX 0xF
28 
29 void setup()
30 { TCCR1A=0; // to clear Arduino presets
31  TCCR1B=0;
32  cli();
33  DDRC =0; //ADC0 and PORTC = Input
34  DDRD |= (1<<PD6); //Set PD6 (OC0A) = Output
35 
36  // enable ADU, free running mode, interrupt enable, prescaler=16, start conversion (ADSC)
37  ADCSRA=(1<<ADEN) | (1<<ADSC) | (1<<ADATE) | (0<<ADIF) | (1<<ADIE) | (1<<ADPS2) | (1<<ADPS1) | (1<<ADPS0);
38  // Voltage Reference: AVCC pin, ADLAR ... right/left adjust for 10Bit
39  ADMUX= ((0<<REFS1) | (1<<REFS0) | (0<<ADLAR));
40 
41 
42  TCCR1B |=(1<<WGM11)|(1<<WGM10); //Fast PWM 10Bit
43 
44  TCCR1B |= (1<<CS10); //Prescaler:
45  TIMSK1 |=(1<<OCIE1A)|(1<<TOIE1); //Timer1 comp int enable, overflow int enable
46  sei();
47  OCR1A = _MAX; //Only for simulation use
48 
49 }
50 
51 void loop()
52 {
53 
54 }
55 
56 ISR(ADC_vect){
57  T("ADU complete"); //trace
58  OCR1A = ADC; //Value for the CompareMatch 16bit
59  OCR1A = _MAX; //debug only
60 }
61 ISR(TIMER1_COMPA_vect){
62  T("Compare Match");
63  PORTD |=(1<<PD6); //set
64 }
65 ISR(TIMER1_OVF_vect){
66  T("Timer1 overflow");
67  PORTD &= ~(1<<PD6); //reset
68 }
69 
70