Skip to content

Commit 9212993

Browse files
author
mohamed hassanin
committed
fix: remove the button and use only ADC.
1 parent 7c46336 commit 9212993

File tree

1 file changed

+17
-19
lines changed
  • PWMed 120 conduction 3-phase inverter/PWMed 120 conduction 3-phase inverter

1 file changed

+17
-19
lines changed

PWMed 120 conduction 3-phase inverter/PWMed 120 conduction 3-phase inverter/main.c

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ void init_timers(void){
3030
TCCR4A |= 1 << COM4A1 | 1 << COM4A0 | 1 << COM4B1;
3131

3232
TCCR5A |= 1 << COM5B1;
33+
TIMSK5 |= 1 << TOIE1;
3334

3435
OCR1A = ICR1 * 2 /3 ;
3536
OCR3A = OCR1A; // +1 and -1 to add some dead time between switches
@@ -47,35 +48,30 @@ void init_timers(void){
4748

4849
GTCCR = 0;
4950
}
50-
51+
volatile int curADC, prevADC;
5152
void init_adc(void){ //A0
5253
ADMUX |= (1 << REFS0) ;
5354
ADCSRA |= (1 << ADEN) | (1 << ADPS1) | (1 << ADPS2);
5455
}
5556

56-
void init_int0(void){
57-
EICRA |= (1 << ISC00) | (1 << ISC01);
58-
EIMSK |= (1 << INT0); //21
59-
}
60-
void int0(void);
61-
62-
ISR(INT0_vect){
63-
int0();
64-
}
6557

66-
void int0(void){
67-
GTCCR = (1<<TSM)|(1<<PSRSYNC); // halt all timers
58+
ISR(TIMER5_OVF_vect){
59+
//ADSC
60+
ADCSRA |= (1<<ADSC);
61+
while( ADCSRA & (1<<ADSC) );
62+
curADC = ADC;
63+
if (!((curADC < (prevADC + 5)) && (curADC > (prevADC - 5)))){
64+
prevADC = curADC;
65+
66+
GTCCR = (1<<TSM)|(1<<PSRSYNC); // halt all timers
6867
TCNT1 = ICR1/3; //shift left //initial value 50% shift
6968
TCNT3 = 0; //stationary
7069
TCNT4 = -1 * TCNT1; //shift right the same amount
7170

71+
OCR5B = (ICR5 - 1) * (prevADC / 1023.0);
7272

73-
ADCSRA |= (1<<ADSC);
74-
while( ADCSRA & (1<<ADSC) ){};
75-
adc10 = ADC;
76-
OCR5B = (ICR5 - 1) * (adc10 / 1023.0);
77-
78-
GTCCR=0;
73+
GTCCR=0;
74+
}
7975
}
8076

8177
int main(void)
@@ -87,7 +83,9 @@ int main(void)
8783
DDRH |= 1 << PINH3 | 1 << PINH4;
8884
DDRL |= 1 << PINL4;
8985
init_adc();
90-
init_int0();
86+
ADCSRA |= (1<<ADSC);
87+
while( ADCSRA & (1<<ADSC) );
88+
prevADC = ADC;
9189
init_timers();
9290
sei();
9391
while (1)

0 commit comments

Comments
 (0)