Hello, this is my first post here so if anything is wrong about the title or anything fell free to question, back to the point, i'm trying to drive a 3 phase motor driver with the pico using the c sdk, and i'm porting the code from arduino that uses a timer in CTC mode to call 2 functions, one for changing the phase by one and holding it till the timer is gone and a second for when the timer don't reach its triggering (making a delay) making all the phases float, being only one timer with 800 for wrap and a variable delay using a potentiometer up to 799 for shortening the duty cycle, the problem i find is that the rp2040 only has a interrupt after the wrap and not before, i could be totally wrong about porting this way so im open for solutions, and i once thought to use 6 pwm slices, but that would be madness to control, and alarms are not really useful (at least in my mind) because they need to be cancelled to change the duration and the pot is too finicky to do that reliably because of the pico's adc. The original arduino code is the following
And here are the timer configurations:
EDIT1: After reading a lot of the documentation for the rp2040 i think i can probably change the phase number and control the pwm to the mosfets with 6 slices when the counter wraps, but there is still the problem that i need to put them all to float when it doesnt reach TOP, and it seems much better to bitbang still, just using the timer for creating the signal timing, because the pwm channels can remain on after disabling the channel and cause damage and i need the driver to float, which takes a combination of high and low signals, so it doesnt induce braking.
Here are the original schematic, only with minor resistor changes: https://electronoobs.com/images/Circuit ... /sch_2.png
Code:
// Read ADC TimeISR(ADC_vect) { int x = ADCH; // read 8 bit value from ADC OCR1B = map(x,0,255,1,799); // Sets how big is the delay 1 LOWEST 799c on 799 HIGHEST 1c on}// Change Phases Timer// Intersects at the topISR(TIMER1_COMPA_vect) { switch (stepstate) { case 1: PORTD = B00100000; PORTB = B00000001; break; case 2: PORTB = B00000011; break; case 3: PORTB = B01000000; PORTD = B00000010; break; case 4: PORTB = B11000000; break; case 5: PORTB = B10000000; PORTD = B00000100; break; case 6: PORTD = B00100000; PORTB = B00000100; break; }}// Sleep Time// Intesect at the bottomISR(TIMER1_COMPB_vect) { PORTD = B01000000; PORTB = B00000101;}
Code:
TCCR1A = 0; TCCR1B = 0; TCCR1B |= (1 << WGM12) | (1 << CS10); //CTC Mode, Prescaler 1 TCNT1 = 0; OCR1A = 800; // Top of the timer OCR1B = 0; // Bottom of the timer TIMSK1 = 0; TIMSK1 |= (1 << OCIE1B) | (1 << OCIE1A);
Here are the original schematic, only with minor resistor changes: https://electronoobs.com/images/Circuit ... /sch_2.png
Statistics: Posted by pedrohcs8 — Fri Jul 26, 2024 5:53 pm