Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

TRIAC firing from PIC MCU

Status
Not open for further replies.

leaveme

Newbie
Newbie level 3
Joined
Oct 28, 2010
Messages
4
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Visit site
Activity points
1,306
Hi,

I'm experimenting a project using PIC to fire the TRIAC. But I do not really understand to setup the TIMER interrupt. I'm using CCS C.
Any help will be appreciated.
Code:
//Compiler: CCS C - v4.14

#include <16F886.h> 

#fuses HS 
#FUSES NOPUT //No Power Up Timer
#FUSES NOPROTECT //Code not protected from reading
#FUSES NOMCLR //Master Clear pin NOT enabled
#FUSES BROWNOUT //Reset when brownout detected

#use delay(clock=20M)


#define DIM_LEVEL 65535
int1 ZC=FALSE; 


#INT_EXT                         //External Interrupt 
void  EXT_isr(void) 
{ 
   output_low(PIN_C0);             //make sure gate is OFF

   set_timer0(DIM_LEVEL);          //preload_time into Timer0
   enable_interrupts(INT_TIMER0);  //start Timer0

   ZC = TRUE;

}

#int_TIMER0 
void  TIMER0_isr(void) 
{ 
     if (ZC)   //execute if zero crossing occures 
     { 
        set_timer0(0);        //stop Timer0
        output_high(PIN_C0);  //turn the gate ON
        delay_uS(100); 
        output_low(PIN_C0);  //turn the gate OFF
        clear_interrupt(INT_TIMER0);  //clear Timer0
        ZC = FALSE; 
     }
} 

void main( void ) { 

   //drive all pins low, except B0, set as input 
   output_b(0); 
   output_c(0); 
   output_float(PIN_B0); 

   setup_timer_0( T0_INTERNAL | T0_DIV_1 ); 

   //ext_int_edge(H_TO_L); //set the falling edge to trigger on the ZC signal
   ext_int_edge(L_TO_H);   //set the rising edge to trigger on the ZC signal 

   clear_interrupt(INT_EXT); 

   enable_interrupts(INT_EXT);
   enable_interrupts(GLOBAL);

  while (1);

}
 

Attachments

  • Image2.png
    Image2.png
    20.5 KB · Views: 95
Last edited:

may u share detail of ur work so that we help according to that or r u feeling problem just in timer interrupt.
 

Can I vary the delay by ADC then?

Yes,you can vary the firing angle with the ADC,see for example here below the codes I found somewhere,me I added only the ADC use which is varied with a variable resistor on AN0, on AN1 I am reading the temperature;see the codes but I don't know how implementing the timer for that you also you can help me because the variation I am getting are insufficient for the good operation.


See the codes:
PHP:
#include"16f877a.h"
#device adc=10
#fuses HS,NOWDT,NOLVP,NODEBUG,NOCPD
#use delay(clock=4M)
#int_ext

//--------------START of variable for Pulse delay definition---------------
int valuet;
unsigned long value1;
unsigned int value3,delaya;

//--------------Ends of variable for Pulse delay definition---------------

//--------------START OF variable for temperature reading---------------
byte const digit[]={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90}; //Changed this as there was error in the previous one

char display[2];
int value;
unsigned long volt;
unsigned int value2;
//--------------END  OF variable for temperature reading---------------

void isrext()
{
output_c(0xff);
delay_ms(1000);
}

void main() 
{
set_tris_a(0xff);
set_tris_b(0x01);
set_tris_c(0x00);
set_tris_d(0x00);

setup_comparator(NC_NC_NC_NC);
setup_adc(ADC_CLOCK_INTERNAL);
setup_adc_ports(ALL_ANALOG);
setup_vref(False);

//int x=0;
enable_interrupts(int_ext);
enable_interrupts(global);
ext_int_edge(H_TO_L);

while(1)
{
//------------------Temperature reading and display
set_adc_channel(0);
delay_us(100);
      //value=read_adc(); //Not required
 read_adc(ADC_START_ONLY);
  delay_us(100);
      value=read_adc(ADC_READ_ONLY);

      //volt=(value*500)/1023; //I changed this part of the code
          volt=(value*500)/1023;
         value2=volt;
   delay_us(1);
      output_high(PIN_D1);
      display[0]=value2/10;      
      output_c(digit[display[0]]);
     output_low(PIN_D0);
      delay_ms(1);

      output_high(PIN_D0);
      display[1]=value2%10;      
      output_c(digit[display[1]]);
   output_low(PIN_D1);
      delay_ms(1);



set_adc_channel(1);
delay_us(20);
read_adc(adc_start_only);
delay_us(20);
valuet=read_adc(adc_read_only);
value1=(valuet*500)/1023;
value3=value1;
delaya=(value3*20)/10;
//delaya=(value3);

output_high(PIN_D3);
delay_ms(delaya);
output_low(PIN_D3);


}
}
Good Luck,you also you help me on the timer for having a variation of voltage at the complete period.

Thanks.
 

if u are working on dimmer u should go with PWM if u r controller support it. because most of dimmer application pwm is very useful for dimmer.

regards.
 

Do you want a pulse train or a single pulse to turn ON the TRIAC..?

If you just need a pulse means

=> Give the ZCD in a ext interrupt
=> when it invokes start a timer whose value is depend on the firing angle
=> in timer Isr Set the output pin
=> also clear all the output pins in ZCD (step 1)
 

I want to create a delay in interrupt which corresponds to the value reads from the variable resistor.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top