@@ -129,6 +129,8 @@ void _writeDutyCycle4PWM(float dc_1a, float dc_1b, float dc_2a, float dc_2b, vo
129
129
130
130
// function configuring pair of high-low side pwm channels, 32khz frequency and center aligned pwm
131
131
// 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
132
134
int _configureComplementaryPair (int pinH, int pinL) {
133
135
if ( (pinH == 4 && pinL == 13 ) || (pinH == 13 && pinL == 4 ) ){
134
136
// configure the pwm phase-corrected mode
@@ -150,6 +152,24 @@ int _configureComplementaryPair(int pinH, int pinL) {
150
152
// configure complementary pwm on low side
151
153
if (pinH == 10 ) TCCR2A = 0b10110000 | (TCCR2A & 0b00001111 ) ;
152
154
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 ) ;
153
173
}else {
154
174
return -1 ;
155
175
}
@@ -199,4 +219,4 @@ void _writeDutyCycle6PWM(float dc_a, float dc_b, float dc_c, void* params){
199
219
_setPwmPair (((GenericDriverParams*)params)->pins [4 ], ((GenericDriverParams*)params)->pins [5 ], dc_c*255.0 , ((GenericDriverParams*)params)->dead_zone *255.0 );
200
220
}
201
221
202
- #endif
222
+ #endif
0 commit comments