firing triac based on adc reading.(phase firing angle)

Discussion in 'Embedded Systems and Microcontrollers' started by bagusdj, Jan 30, 2013.

  1. bagusdj

    Thread Starter New Member

    Jan 30, 2013
    1
    0
    hi guys, i really need assistance for my project. the intention of this project is :
    i need my device to detect sensor reading everytime interupt is conducted. at certain value, the triac fired after delayed for certain period, depends on the sensor reading range desired.

    ex: if interrupt is conducted and the sensor reading is 77, so triac will be fired after being delayed 3mS. interrupt always occured every 10ms because the interrupt source is zero cross detector. by the next interrupt, it will check the sensor reading again.

    i had the LCD+ADC+sensor schematic and code alone, and it works. i had tried to make simple firing triac program, and it works. now i want to combine both of them and it doesn't work.

    here is the code
    Code ( (Unknown Language)):
    1. // Program to interface TGS2600 using ADC 0809. The output of TGS2600 is displayed on LCD. Controller interrupt is used to generate the clock for driving ADC 0808.
    2. #include<reg52.h>
    3. sbit ale=P1^0;  //address latch enable
    4. sbit oe=P1^3;  //output enable
    5. sbit sc=P1^1;  //start conversion
    6. sbit eoc=P1^2;  //end of conversion
    7. sbit clk=P1^7;  // clock
    8. sbit ADD_A=P1^4;  // Address pins for selecting input channels.
    9. sbit ADD_B=P1^5;
    10. sbit ADD_C=P1^6;
    11. sfr lcd_data_pin=0xA0;  //P2 port
    12. sbit rs=P3^7;
    13. sbit rw=P3^1;
    14. sbit en=P3^6;
    15. sbit triac=P3^0;
    16. sfr input_port=0x80;  //P0 port
    17. unsigned int bitvalue,decimal_value,key,left_value,value,number,ascii1,ascii2,ascii3,flag,key1,lastReading;
    18. void cct_init(void);
    19. void initint0(void);
    20.  
    21. void timer0() interrupt 1  // Function to generate clock of frequency 500KHZ using Timer 0 interrupt.
    22. {
    23. clk=~clk;
    24. }
    25.  
    26. void delay(unsigned int count) //delay function in mS
    27. {
    28. unsigned int i;                        
    29.     while(count) {
    30.         i = 115;
    31.                 while(i>0) i--;
    32.         count--;
    33. }}
    34.  
    35. void cct_init(void)
    36.  {
    37.  P3=0x05;       //triac is on when active low. initialy triac is off.
    38.  }
    39.  
    40. void initINT0(void)       //activate int0
    41.  {
    42.  IT0=1;  //interupted when transition from logic 1 to 0 (zero cross detector)
    43.  EX0=1;
    44.  EA=1;
    45.  }
    46.  
    47. void external0_isr(void) interrupt 0 //interrupt routine
    48.  
    49. {
    50. triac=1;
    51.  if((lastReading>=52) && (lastReading<=77))     //1st condition
    52.       {delay(4);
    53.        triac=0;}
    54.  
    55.           else if((lastReading>=77) && (lastReading<=103))      //2nd condition
    56.               {delay(3);
    57.                triac=0;}
    58.  
    59.              else if((lastReading>=103) && (lastReading<=128))  //3rd condition
    60.                {delay(2);
    61.                 triac=0;}
    62.  
    63.                 else if(lastReading>128) //4th condition; full power
    64.                   {triac=0;}
    65.  
    66. delay(1);
    67. triac=1;
    68. EA=0;
    69. EA=1;
    70. }
    71.  
    72.  
    73.  
    74. void lcd_command(unsigned char comm)  //Function to send command to LCD.
    75. {
    76. lcd_data_pin=comm;
    77. en=1;
    78. rs=0;
    79. rw=0;
    80. delay(10);
    81. en=0;
    82. }
    83.  
    84. void lcd_data(unsigned char disp)  //Function to send data to LCD.
    85. {
    86. lcd_data_pin=disp;
    87. en=1;
    88. rs=1;
    89. rw=0;
    90. delay(10);
    91. en=0;
    92. }
    93.  
    94. lcd_dataa(unsigned char *disp)  //Function to send string data to LCD.
    95. {
    96. int x;
    97. for(x=0;disp[x]!=0;x++)
    98. {
    99.   lcd_data(disp[x]);
    100. }
    101. }
    102.  
    103. void lcd_ini()  //Function to inisialize the LCD
    104. {
    105. lcd_command(0x38);
    106. delay(5);
    107. lcd_command(0x0E);
    108. delay(5);
    109. lcd_command(0x80);  //Force cursor to blink at line 1 positon 0
    110. delay(5);
    111. }
    112.  
    113. void BCD()  // Binary to decimal conversion to send the data to LCD
    114. {
    115.   key1++;
    116.   key=0;
    117.   flag=0;
    118.     lastReading=number=input_port;
    119.     number= number*39;
    120.     number= number/100;
    121.     value=number%10;
    122. number=number/10;
    123. ascii1=value+48;
    124. if(number!=0)
    125. {
    126.   value=number%10;
    127.   number=number/10;
    128.   ascii2=value+48;
    129.     flag=1;
    130. }
    131. else
    132. {
    133.    ascii2=48;
    134.    flag=1;
    135. }
    136. if(number!=0)
    137. {
    138.  value=number%10;
    139.     number=number/10;
    140.     ascii3=value+48;
    141.     key=2;
    142. }
    143. else
    144. {
    145.   ascii3=48;
    146.   key=2;
    147. }
    148. if(key==2)
    149. lcd_data(ascii3);
    150. if(flag==1)
    151. lcd_data(ascii2);
    152. lcd_data(ascii1);
    153. if(key1==3)
    154. {
    155. key1=0;
    156. ascii3=0;
    157. ascii2=0;
    158. ascii1=0;
    159. delay(10);
    160. }
    161. }
    162.  
    163.  
    164.  
    165. void adc()  //Function to drive ADC
    166. {
    167. while(1)
    168. {
    169.   ADD_C=0;  // Selecting input channel 2 using address lines
    170.   ADD_B=0;
    171.   ADD_A=1;
    172.   delay(2);
    173.   ale=1;
    174.   delay(2);
    175.   sc=1;
    176.   delay(1);
    177.   ale=0;
    178.   delay(1);
    179.   sc=0;
    180.   while(eoc==1);
    181.   while(eoc==0);
    182.   oe=1;
    183.   BCD();
    184.   lcd_command(0x88);
    185.   delay(2);
    186.   oe=0;
    187.   }
    188. }
    189.  
    190.  
    191. void main()
    192. {
    193. cct_init();
    194. initINT0();
    195. eoc=1;
    196. ale=0;
    197. oe=0;
    198. sc=0;
    199. key1=0;
    200. TMOD=0x02;  //timer0 setting for generating clock of 500KHz using interrupt enable mode.
    201. TH0=0xFD;
    202. IE=0x82;
    203. TR0=1;
    204. lcd_ini();
    205.  
    206. lcd_dataa("PPM : ");
    207. lcd_command(0x88);
    208. adc();
    209. }
    the interrupt seems not checking. my load is a fan (inductive load), adc is 0809, mcu is AT89S52 with keil compiler, sensor is tgs2600,triac driver is moc 3021.

    i am sorry if this code is too long, but i think it is necessary to post it whole.
     
Loading...