Hello guys
I am trying to control the motor of a washing machine, and the problem I encountered is adjusting the RPM precisely compared to the value of the tachometer.
I am using a PIC16F628 microcontroller
C:
void INTERRUPT ()
{
/// ZERO CROSSING FUNCTION ///
if (EXT_INT_FLAG) {
DELAYING_10US (US_DELAY);
TRIAC = ON_TR;
delay_us (100);
TRIAC = OFF_TR;
INT_EDG =~ INT_EDG; /// toggle edge (INT) sensing "RISING, FALLING"///
/// beacause PIC16F628 has no 2 sensing ///
EXT_INT_FLAG = 0;
} /// if (EXT_INT_FLAG)
if (TMR2_FLAG) {
/// using TIMER2 to generate time base "1mS" ///
TMR2_FLAG = 0;
}
} /// void INTERRUPT ()
I am using timer1 to save the number of pulses from the tachometer
C:
/// here take the TMR1 register value then reset it ///
TACHO_RPM = (TMR1H << 8) + TMR1L;
TMR1H = TMR1L = 0;
C:
void main (void)
{
TMR2_1MS ();
TMR1_INIT ();
EXT_INT_INIT ();
CHIP_INIT ();
while (1) {
/// here display TACHO_RPM on 4DIGIT seven segment ///
}
}
When I control the time delay of the triac with the buttons, everything works fine.
But when I change the time delay programmatically, the motor jumps according to the change in time delay.
Of course, I tried to calculate and compare the tachometer pulses in 1 millisecond and more as well
But the engine jumps step by step
If you want, I can share a video to make the problem more clear
Please help and thank you everyone
Generally it's no good idea to use busy waits (delay_us) in an ISR.
The shown cide is not complete.
Thus it's imposiible to find out what happens.
* In your error description you talk about the tacho signal. We see that it controls the TACHO_RPM variable. But we don't see how this variable is used.
* we don't see where the variable US_DELAY comes from and what range it has.
Also we don't see how often the tacho signal comes, nor what mains frequency you have.
Posting your schematic surely is good idea.
Generally I recommend to go through application notes on "triac motor control" with microcontrollers.
I guess Microchip provides good documents. But generally documents from other semiconductor manufacturers are useful, too.
You should have a look o the PID control theory; to solve your problem, perhaps only the 'P' suffice. In short, you will add incremental changes on the output power taking into account the current speed, instead of the binary control as you're doing above.
You should have a look o the PID control theory; to solve your problem, perhaps only the 'P' suffice. In short, you will add incremental changes on the output power taking into account the current speed, instead of the binary control as you're doing above.