Skip to content

Commit 9a4ded3

Browse files
committed
Merge branch 'dev' of github.com:askuric/Arduino-FOC into dev
2 parents 7ecf1b7 + 7ff3ab8 commit 9a4ded3

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

src/drivers/hardware_specific/atmega/atmega2560_mcu.cpp

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,8 @@ void _writeDutyCycle4PWM(float dc_1a, float dc_1b, float dc_2a, float dc_2b, vo
129129

130130
// function configuring pair of high-low side pwm channels, 32khz frequency and center aligned pwm
131131
// supports Arudino/ATmega2560
132+
// https://ww1.microchip.com/downloads/en/devicedoc/atmel-2549-8-bit-avr-microcontroller-atmega640-1280-1281-2560-2561_datasheet.pdf
133+
// https://docs.arduino.cc/hacking/hardware/PinMapping2560
132134
int _configureComplementaryPair(int pinH, int pinL) {
133135
if( (pinH == 4 && pinL == 13 ) || (pinH == 13 && pinL == 4 ) ){
134136
// configure the pwm phase-corrected mode
@@ -150,6 +152,24 @@ int _configureComplementaryPair(int pinH, int pinL) {
150152
// configure complementary pwm on low side
151153
if(pinH == 10 ) TCCR2A = 0b10110000 | (TCCR2A & 0b00001111) ;
152154
else TCCR2A = 0b11100000 | (TCCR2A & 0b00001111) ;
155+
}else if((pinH == 5 && pinL == 2 ) || (pinH == 2 && pinL == 5 ) ){
156+
// set prescaler to 1 - 32kHz freq
157+
TCCR3B = ((TCCR3B & 0b11111000) | 0x01);
158+
// configure complementary pwm on low side
159+
if(pinH == 5 ) TCCR3A = 0b10110000 | (TCCR3A & 0b00001111) ;
160+
else TCCR3A = 0b11100000 | (TCCR3A & 0b00001111) ;
161+
}else if((pinH == 6 && pinL == 7 ) || (pinH == 7 && pinL == 6 ) ){
162+
// set prescaler to 1 - 32kHz freq
163+
TCCR4B = ((TCCR4B & 0b11111000) | 0x01);
164+
// configure complementary pwm on low side
165+
if(pinH == 6 ) TCCR4A = 0b10110000 | (TCCR4A & 0b00001111) ;
166+
else TCCR4A = 0b11100000 | (TCCR4A & 0b00001111) ;
167+
}else if((pinH == 46 && pinL == 45 ) || (pinH == 45 && pinL == 46 ) ){
168+
// set prescaler to 1 - 32kHz freq
169+
TCCR5B = ((TCCR5B & 0b11111000) | 0x01);
170+
// configure complementary pwm on low side
171+
if(pinH == 46 ) TCCR5A = 0b10110000 | (TCCR5A & 0b00001111) ;
172+
else TCCR5A = 0b11100000 | (TCCR5A & 0b00001111) ;
153173
}else{
154174
return -1;
155175
}
@@ -199,4 +219,4 @@ void _writeDutyCycle6PWM(float dc_a, float dc_b, float dc_c, void* params){
199219
_setPwmPair(((GenericDriverParams*)params)->pins[4], ((GenericDriverParams*)params)->pins[5], dc_c*255.0, ((GenericDriverParams*)params)->dead_zone*255.0);
200220
}
201221

202-
#endif
222+
#endif

0 commit comments

Comments
 (0)