Hi @fobi123
Have you managed to simulate the circuit/motor?? Can I do anything else to help??
Regards!
Hi @fobi123
Have you managed to simulate the circuit/motor?? Can I do anything else to help??
Regards!
I was thinking of something like this (in my very limited programming experience): Correct me if I'm wrong..
Activate an interrupt to count a change from 0 to 1, of one of the pwm phases, only when the duty cycle gets to a specific low value.
When the value counted gets to an X number of pulses, record the time it needed to get these X pulses. Desactivate the interrupt
Then set the pwm pin for that phase as an INPUT until that recorded time is reached again.
Activate the interrrupt and set that pin to output pwm again..
Does it make sense??
Would I have to connect each PWM output PIN (Pins 9,10 and 11) to three other digital pins, as inputs, and add an interrupt for each of these pins, so they can sense the PWM output pins?
Is it right also?
But... each step of the commutation is called inside on the bldc_move() function. This function is called only when the back-emf zero-cross interrupt occurs... so only when the next phase is going to be called..
Is it also correct?
So... in-between zero-cross events, the pwm duty cycle is fixed, and will only be changed when the next commutation step is going to be called.
So how could this counting/skipping pulses be implemented in this code, to be able to be actively counting/skipping pulses, even when the next zero cross event didn't happen yet?
Ah, I was thinking of your discrete circuit and putting a MOSFET on the the shared circuits of the H-bridges.
When I was playing with the minimumWidth+skipped pulses I tried inhibiting the pulses with the overflow interrupt and the active TCCRnA register, but I didn't leave things properly if the phase changed.
Does this happen with your setup:
You mean that no matter in what sampling time you choose on the virtual scope, always the second line rises a little bit after the first one falls, not in sync like the second line and the third?
My little scope has two channels only, so I can probe two phases at the same time, if it helps, I can test it.
You could test your virtual setup the way I'm running , with fast pwm at 61.5kHz, to see if it changes anything..
// Timer1 module setting: set clock source to 62.5khz / no prescalar // For Timer 1, that means setting WGM12 and WGM10 to 1
TCCR1A = 0b00000001;
TCCR1B = 0b00001001;
// Timer2 module setting: set clock source to 62.5khz / no prescalar // For Timer2, that means setting WGM21 and WGM20 to 1
TCCR2A = 0b00000011;
TCCR2B = 0b00000001;
and change these two below to match:
void AH_BL() {
PORTD &= ~0xA0;
PORTD |= 0x40;
TCCR1A = 0; // turn pin 11 (OC2A) PWM ON (pin 9 & pin 10 OFF)
// TCCR2A = 0x81; // 0b1000 0001 // original 31khz version
TCCR2A = 0x83; // 0b1000 00011 // Fast PWM 61.5khz version
}
void AH_CL() {
PORTD &= ~0xC0;
PORTD |= 0x20;
TCCR1A = 0; // turn pin 11 (OC2A) PWM ON (pin 9 & pin 10 OFF)
// TCCR2A = 0x81; // 0b1000 0001 // original 31khz version
TCCR2A = 0x83; // 0b1000 00011 // Fast PWM 61.5khz version
}
Have you got any updates so far? At 61.5Khz your simulation code looks right at the scope...
Regards, Rodrigo
Ok. I've made a few modifications on my setup to make it easier to implement.
As the three pwm pins (Pin 9 and 10) of Timer 1 and pin 11 of Timer 2 have the same duty and frequency, I changed my hardware and software to this:
I'm using only pin 9 from Timer 1 (could be pin 10) to generate the pwm pulse. The output of this PWM pin goes to the Source of three P-mosfets.
The drains of each mosfet are connected to the three High Inputs of my development board (INH-A, INH-B, and INH-C).
And each gate of each p-mosfet is pulled high through a 10k resistor (to force them off) and connected to a digital pin on the Arduino (Pins 5, 6 and 7)
So when I set any of these digital pins (5, 6 or 7) to LOW, the p-mosfet outputs to the high side Channel of my dev. board (A, B or C ) the same pwm wave that pin 9 is always outputting.
So now I have the same effect of controling the motor, but with only one Timer and one pwm PIN.
I had to change the 6 commutation steps functions to only turn on and off low side and high side pins.
I've been trying to use your MinPulsePWM now, as it uses only timer 1, but I coudn't see any improvement... in the end.. maybe I'm doing something wrong...
I was thinking that skipped pulses would probably worth giving it a try.. Counting the number of pwm pulses and then disabling the pwm (or disabling the output of the channels) after a number of pulses and re-enabling it again after some more pulses or time elapsed...
Could you, or someone help in developing that?
Rodrigo