Re: 60Hz signal on T0CKI
i am connecting a main AC line to a 2 megoohm resistor for a zero-crossing circuit.
This is connected to T0CKI.
I am wondering the best way to go about using this input for a fan speed controller.
I also have this main line connected to port B for a general interrupt-on-change.
does anyone have a recommended way I should proceed on this?
some simple code:
#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;
}
}
}