deperkin
Member level 2
Hello all,
I am trying to control the speed of an AC motor (i know it is problematic).
Here is the simple code i have thus far:
#include <18F2331.H>
#include <STDLIB.H>
#fuses XT, NOWDT, NOPROTECT, BROWNOUT, NOPUT, NOLVP, NOMCLR
#ocs 500 kHz
int16 fanL, fanspeed;
int8 portB;
#INT_RB
void AC_isr(){
disable_interrupts(int_RB);
portB = input_b()
output_low(PIN_C2); //MOTOR
delay_us(fanL);
output_toggle(PIN_C4); //LED
output_high(PIN_C2); //MOTOR
}
void main() {
SET_TRIS_A(0xFF); //PINS A0-A7 are inputs
SET_TRIS_B(0xFF); //PINS B0-B7 are inputs
while(TRUE){
enable_interrupts(INT_RB);
enable_interrupts(GLOBAL);
fanspeed = 0x0F & input_a();
switch(fanspeed){
case 10:fanL=0;break;
case 9: fanL=58;break;
case 8: fanL=1515;break;
case 7: fanL=2272;break;
case 6: fanL=3030;break;
case 5: fanL=3788;break;
case 4: fanL=4545; break;
case 3: fanL=5303;break;
case 2: fanL=6060;break;
case 1: fanL=6818;break;
case 0: fanL=7576; break;
default: fanL= 0; break;
}
}
}
I am using a solid state relay attached to pin_C2.
On the opposite of the SSR I have AC(L) and the motor.
The motor also has a starting capacitor connected to AC(N).
I have a 1Mohm resistor connected to AC(L) then going to pin_B5.
I am trying to get a good zero-crossing interrupt from this.
The idea is to interrupt-on-change, output to the SSR a low signal for a short period of time, then output high to the SSR for the remaining 1/120th of that second.
(i.e. for a half period = 1/120 sec = 8333.33 usec)
depending on my fanspeed setting (coming from another microcontroller on port A), i take this 8333 microseconds and split it up. (e.g. at a lower speed setting I output_low to the SSR for almost the whole 1/120 sec. and at full speed I output_low to the SSR for zero seconds).
My problem is that I do not get a zero-crossing interrupts, and my speeds for the AC motor are not consistently changing (not really variable).
Any help would greatly be appreciate as always.
Thank you.
I am trying to control the speed of an AC motor (i know it is problematic).
Here is the simple code i have thus far:
#include <18F2331.H>
#include <STDLIB.H>
#fuses XT, NOWDT, NOPROTECT, BROWNOUT, NOPUT, NOLVP, NOMCLR
#ocs 500 kHz
int16 fanL, fanspeed;
int8 portB;
#INT_RB
void AC_isr(){
disable_interrupts(int_RB);
portB = input_b()
output_low(PIN_C2); //MOTOR
delay_us(fanL);
output_toggle(PIN_C4); //LED
output_high(PIN_C2); //MOTOR
}
void main() {
SET_TRIS_A(0xFF); //PINS A0-A7 are inputs
SET_TRIS_B(0xFF); //PINS B0-B7 are inputs
while(TRUE){
enable_interrupts(INT_RB);
enable_interrupts(GLOBAL);
fanspeed = 0x0F & input_a();
switch(fanspeed){
case 10:fanL=0;break;
case 9: fanL=58;break;
case 8: fanL=1515;break;
case 7: fanL=2272;break;
case 6: fanL=3030;break;
case 5: fanL=3788;break;
case 4: fanL=4545; break;
case 3: fanL=5303;break;
case 2: fanL=6060;break;
case 1: fanL=6818;break;
case 0: fanL=7576; break;
default: fanL= 0; break;
}
}
}
I am using a solid state relay attached to pin_C2.
On the opposite of the SSR I have AC(L) and the motor.
The motor also has a starting capacitor connected to AC(N).
I have a 1Mohm resistor connected to AC(L) then going to pin_B5.
I am trying to get a good zero-crossing interrupt from this.
The idea is to interrupt-on-change, output to the SSR a low signal for a short period of time, then output high to the SSR for the remaining 1/120th of that second.
(i.e. for a half period = 1/120 sec = 8333.33 usec)
depending on my fanspeed setting (coming from another microcontroller on port A), i take this 8333 microseconds and split it up. (e.g. at a lower speed setting I output_low to the SSR for almost the whole 1/120 sec. and at full speed I output_low to the SSR for zero seconds).
My problem is that I do not get a zero-crossing interrupts, and my speeds for the AC motor are not consistently changing (not really variable).
Any help would greatly be appreciate as always.
Thank you.