So I’m in a really bad mood since I tried so hard to make this work and it literally blew up in my face (I’m fine, just pissed).
I bought THIS:
…and fed it the code from THIS:
unsigned int index = 0;
boolean flag = true;
unsigned int duties[] = {
15,
31,
47,
63,
79,
95,
111,
127,
143,
159,
175,
191,
207,
223,
239,
255,
255,
239,
223,
207,
191,
175,
159,
143,
127,
111,
95,
79,
63,
47,
31,
15
};
unsigned int timestamps[] = {
434,
898,
1366,
1839,
2321,
2813,
3318,
3841,
4386,
4961,
5573,
6238,
6979,
7843,
8950,
11574,
9470,
7322,
6417,
5710,
5104,
4559,
4059,
3589,
3143,
2715,
2301,
1899,
1505,
1118,
734,
355
};
void setup() {
// This 8 bit timer2 code is for the 60Hz sine wave generation
DDRB |= (1 << PB3); // Pin 11
DDRD |= (1 << PD3); // Pin 3
DDRB |= (1 << PB1); // Pin 9 output
DDRB |= (1 << PB2); // Pin 10 output
cli();
TCCR2A = 0;
TCCR2B = 0;
TCNT2 = 0;
OCR2A = 255; // Channel A duty
OCR2B = 255; // Channel B duty
TCCR2A |= (1 << WGM20); // Mode 7
// TCCR2A |= (1 << WGM21);
// TCCR2B |= (1 << WGM22);
// TCCR2A |= (1 << COM2A0); // Non-Inverting Mode on Pin A
TCCR2A |= (1 << COM2A1);
// TCCR2A |= (1 << COM2B1);
TCCR2B |= (1 << CS20); // Prescaler 1
// TIMSK2 |= (1 << OCIE2A);
// TIMSK2 |= (1 << OCIE2B);
// TIMSK2 |= (1 << TOIE2);
// This 16 bit timer1 code is so we can count and keep track of when to change the duty on Timer2
TCCR1A = 0; // Clear register
TCCR1B = 0; // Clear register
TCNT1 = 0;
OCR1A = 0; // Define OCRA for timekeeping. This will be modulated by Timer2.
TCCR1A |= (1 << WGM10);
TCCR1A |= (1 << WGM11); // Mode 15, Fast PWM with OCR TOP
TCCR1B |= (1 << WGM12);
TCCR1B |= (1 << WGM13);
TCCR1A |= (1 << COM1A1); // Non-inverting on A pin
TCCR1B |= (1 << CS10); // Prescaler 1
sei();
}
void loop() {
}
ISR (TIMER1_COMPA_vect) {
index++; // Increment the index
if(index > 31) { // Check if the end of the array has been reached
index = 0; // If so, immediately go back to the first entry
// TCCR2A ^= (1 << COM2A1); // A should start generating a waveform while B shuts off and vice versa
// TCCR2A ^= (1 << COM2B1); // When Sine is +, channel A will produce only positive pulses, when Sine is - channel B will produce only negative pulses
}
OCR1A = timestamps[index]; // Update the time interval till the next duty change
OCR2A = duties[index]; // Update the duty of Channel A
// OCR2B = duties[index]; // Update the duty of Channel B
}
I scoped it in advance many times and the output looked good.
First I connected the output of the driver to the primary coil of my transformer. Then I connected the 24V battery. Then I connected the GND signal pin to the GND on my nano, the PWM pin to high and the DIRECTION pin to pin 11 which was sending out the pulses. As soon as put power to the nano board, the motor driver violently exploded… 4 times, just for emphasis. So wtf did I do wrong? Was it that I connected things in the wrong order or was it the code or something else? I just bought 2 more boards so I don’t have to wait another 2 weeks after the next explosion but this is more than just a little annoying. Thanks for your patience.