Skip to content

Commit

Permalink
put outputs in the right order
Browse files Browse the repository at this point in the history
  • Loading branch information
catphish committed Jul 21, 2018
1 parent a1ac313 commit 2a0dd8d
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,44 +35,44 @@ void update_svm(uint32_t phase, uint32_t voltage)
switch(sine_segment) {
case 0:
// 100 -> 110
TIM1->CCR3 = ((voltage+1) * table[sine_angle] - 1) >> 9;
TIM1->CCR1 = ((voltage+1) * table[sine_angle] - 1) >> 9;
TIM1->CCR2 = ((sine_angle + 1) * (voltage+1) * table[sine_angle] - 1) >> 19;
TIM1->CCR1 = 0;
TIM1->CCR3 = 0;
break;

case 1:
// 110 -> 010
TIM1->CCR3 = ((1024 - sine_angle) * (voltage+1) * table[sine_angle] - 1) >> 19;
TIM1->CCR1 = ((1024 - sine_angle) * (voltage+1) * table[sine_angle] - 1) >> 19;
TIM1->CCR2 = ((voltage+1) * table[sine_angle] - 1) >> 9;
TIM1->CCR1 = 0;
TIM1->CCR3 = 0;
break;

case 2:
// 010 -> 011
TIM1->CCR3 = 0;
TIM1->CCR1 = 0;
TIM1->CCR2 = ((voltage+1) * table[sine_angle] - 1) >> 9;
TIM1->CCR1 = ((sine_angle + 1) * (voltage+1) * table[sine_angle] - 1) >> 19;
TIM1->CCR3 = ((sine_angle + 1) * (voltage+1) * table[sine_angle] - 1) >> 19;
break;

case 3:
// 011 -> 001
TIM1->CCR3 = 0;
TIM1->CCR1 = 0;
TIM1->CCR2 = ((1024 - sine_angle) * (voltage+1) * table[sine_angle] - 1) >> 19;
TIM1->CCR1 = ((voltage+1) * table[sine_angle] - 1) >> 9;
TIM1->CCR3 = ((voltage+1) * table[sine_angle] - 1) >> 9;
break;

case 4:
// 001 -> 101
TIM1->CCR3 = ((sine_angle + 1) * (voltage+1) * table[sine_angle] - 1) >> 19;
TIM1->CCR1 = ((sine_angle + 1) * (voltage+1) * table[sine_angle] - 1) >> 19;
TIM1->CCR2 = 0;
TIM1->CCR1 = ((voltage+1) * table[sine_angle] - 1) >> 9;
TIM1->CCR3 = ((voltage+1) * table[sine_angle] - 1) >> 9;
break;

case 5:
// 101 -> 100
TIM1->CCR3 = ((voltage+1) * table[sine_angle] - 1) >> 9;
TIM1->CCR1 = ((voltage+1) * table[sine_angle] - 1) >> 9;
TIM1->CCR2 = 0;
TIM1->CCR1 = ((1024 - sine_angle) * (voltage+1) * table[sine_angle] - 1) >> 19;
TIM1->CCR3 = ((1024 - sine_angle) * (voltage+1) * table[sine_angle] - 1) >> 19;
break;
}
}
Expand Down

0 comments on commit 2a0dd8d

Please sign in to comment.