D.A.(Tony)Stewart
Advanced Member level 7
- Joined
- Sep 26, 2007
- Messages
- 9,934
- Helped
- 1,856
- Reputation
- 3,713
- Reaction score
- 2,419
- Trophy points
- 1,413
- Location
- Richmond Hill, ON, Canada
- Activity points
- 63,467
I found no problem with a triac but using delay() function is not providing a very long range for firing angle generation.
I thought I could find reference docs for using timer so that I could get good adjustment with timer0 or timer1 so that my pic could trigger the TRIAC with a good long range.
I would like to find a support for generating that delay using those timers techniques but also using push button or potentiometer.
Please help.
unsigned char FlagReg;
sbit ZC at FlagReg.B0;
void main(void)
{
PORTB=0;
TRISB=0X01;
PORTA=0XFF;
TRISA=0XFF;
PORTC=0;
TRISC=0X00;
ANSELA=0X00;
OPTION_REG.INTEDG=0;//interrupt on falling edge
INTCON.INTF=0; //clear flag bit
INTCON.INTE=1; //Enable external interrupt
INTCON.GIE=1; //Enable Global interrupt
INTCON.PEIE=1; //Enable peripheral interrupt
while(1)
{
if(ZC)
{
if(!PORTA.B1)
{
delay_ms(2);
PORTC.B6=1;
delay_us(250);
PORTC.B6=0;
ZC=0;
}
else if(!PORTA.B2)
{
delay_ms(4);
PORTC.B6=1;
delay_us(250);
PORTC.B6=0;
ZC=0;
}
else if(!PORTA.B3)
{
delay_ms(6);
PORTC.B6=1;
delay_us(250);
PORTC.B6=0;
ZC=0;
}
else
{
delay_ms(2);
PORTC.B6=1;
delay_us(250);
PORTC.B6=0;
ZC=0;
}
}
}
}
void interrupt(void)
{
if(INTCON.INTF==1)
{
ZC=1;
INTCON.INTF=0;
}
}
unsigned char FlagReg;
sbit ZC at FlagReg.B0;
void main(void)
{
PORTB=0;
TRISB=0X01;
PORTA=0XFF;
TRISA=0XFF;
PORTC=0;
TRISC=0X00;
ANSELA=0X00;
OPTION_REG.INTEDG=0;//interrupt on falling edge
INTCON.INTF=0; //clear flag bit
INTCON.INTE=1; //Enable external interrupt
INTCON.GIE=1; //Enable Global interrupt
INTCON.PEIE=1; //Enable peripheral interrupt
while(1)
{
if(ZC!=0)
{
if(!PORTA.B1)
{
delay_ms(2);
PORTC.B6=1;
delay_us(250);
PORTC.B6=0;
ZC=0;
}
else if(!PORTA.B2)
{
delay_ms(4);
PORTC.B6=1;
delay_us(250);
PORTC.B6=0;
ZC=0;
}
else if(!PORTA.B3)
{
delay_ms(6);
PORTC.B6=1;
delay_us(250);
PORTC.B6=0;
ZC=0;
}
else if(!PORTA.B4)
{
delay_ms(8);
PORTC.B6=1;
delay_us(250);
PORTC.B6=0;
ZC=0;
}
}
}
}
void interrupt(void)
{
if(INTCON.INTF==1)
{
ZC=1;
INTCON.INTF=0;
}
}
unsigned char FlagReg;
sbit ZC at FlagReg.B0;
void interrupt()
{
if(INTCON.INTF==1)
{
ZC=1;
INTCON.INTF=0;
}
}
void main()
{
PORTB=0;
TRISB=0x01; //RB0 input for interrupt
PORTC=0;
TRISC=0x00; //portc set as output for driving The TRIAC
ANSELA=0x00; //Cleared for using
OPTION_REG.INTEDG=1;//interrupt on falling edge
INTCON.INTF=0; //clear flag bit
INTCON.INTE=1; //Enable external interrupt
INTCON.GIE=1; //Enable Global interrupt
INTCON.PEIE=1; //Enable peripheral interrupt
while(1)
{
if(ZC){
delay_ms(4);
PORTC.B6=1;
delay_us(450);
PORTC.B6=0;
ZC=0;
}
}
}
/***********************************************************************
controlling AC Fan with single phase AC Motor
MCU: PIc16f877A; X-Tal: 4MHz(External)
***********************************************************************/
// PIN difine...
#define Fan PORTD.B0
#define Zero PORTB.B0
#define Plus_Button PORTC.B2
#define Minus_Button PORTC.B3
#define Buzzer PORTD.B6
// global variables
unsigned int current=5;
unsigned int ch_cnt=0;
// Interrupt ...
void interrupt()
{
while(Zero==0)
{
ch_cnt++;
while(ch_cnt<=105-current)
{
Fan = 0;
break;
}
while(ch_cnt>=105-current)
{
Fan = 1;
break;
}
break;
}
while(Zero==1)
{
Fan = 0;
ch_cnt = 0;
break;
}
// Timer settings
TMR0IF_bit = 0;
TMR0 = 250;
}// interrupt
unsigned int time_delay=0;
void main()
{
//TRISIO = 0b00110001;
TRISD=0XF0;
PORTD=0;
TRISC=0X0F;
OPTION_REG = 0x81;
TMR0 = 220;
INTCON = 0xA0;
TMR0IE_bit = 1;// enable timer0
while(1)
{
while(!Minus_Button)
{
if(current<90)
{
current+=10;
Delay_ms(20);
}
else
{
current = 100;
}
Buzzer = 1;
Delay_ms(80);
Buzzer = 0;
time_delay = 0;
break;
}
while(!Plus_Button)
{
if(current>11)
{
current-=10;
Delay_ms(20);
}
else
{
current = 0;
}
Buzzer = 1;
Delay_ms(80);
Buzzer = 0;
time_delay = 0;
Delay_ms(20);
break;
}
}// While
}// void main
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?