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.

[moved] IF FOR loop problem getting my resistors burnt

Status
Not open for further replies.

ishtiaqshaheer

Junior Member level 3
Joined
Mar 17, 2017
Messages
26
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Location
India
Activity points
203
(I'm not very much good at coding)

When I'm using this Dimmer Code then its working fine even for a long time and nothing is getting burnt nor heated up.

Code:
/*

AC Voltage dimmer with Zero cross detection
Author: Charith Fernanado <a href="http://www.inmojo.com">  http://www.inmojo.com

</a>
Adapted by DIY_bloke
License: Creative Commons Attribution Share-Alike 3.0 License.
Attach the Zero cross pin of the module to Arduino External Interrupt pin
Select the correct Interrupt # from the below table 
(the Pin numbers are digital pins, NOT physical pins: 
digital pin 2 [INT0]=physical pin 4 and digital pin 3 [INT1]= physical pin 5)
check: <a href="http://arduino.cc/en/Reference/attachInterrupt">  http://www.inmojo.com

</a>

Pin    |  Interrrupt # | Arduino Platform
---------------------------------------
2      |  0            |  All -But it is INT1 on the Leonardo
3      |  1            |  All -But it is INT0 on the Leonardo
18     |  5            |  Arduino Mega Only
19     |  4            |  Arduino Mega Only
20     |  3            |  Arduino Mega Only
21     |  2            |  Arduino Mega Only
0      |  0            |  Leonardo
1      |  3            |  Leonardo
7      |  4            |  Leonardo
The Arduino Due has no standard interrupt pins as an iterrupt can be attached to almosty any pin. 

In the program pin 2 is chosen
*/
int AC_LOAD = 3;    // Output to Opto Triac pin
int dimming = 128;  // Dimming level (0-128)  0 = ON, 128 = OFF

void setup()
{
  pinMode(AC_LOAD, OUTPUT);// Set AC Load pin as output
 // digitalPinToInterrupt(2);
  attachInterrupt(digitalPinToInterrupt(2), zero_crosss_int, RISING);  // Choose the zero cross interrupt # from the table above
}

//the interrupt function must take no parameters and return nothing
void zero_crosss_int()  //function to be fired at the zero crossing to dim the light
{
  // Firing angle calculation : 1 full 50Hz wave =1/50=20ms 
  // Every zerocrossing thus: (50Hz)-> 10ms (1/2 Cycle) 
  // For 60Hz => 8.33ms (10.000/120)
  // 10ms=10000us
  // (10000us - 10us) / 128 = 75 (Approx) For 60Hz =>65

  int dimtime = (75*dimming);    // For 60Hz =>65    
  delayMicroseconds(dimtime);    // Wait till firing the TRIAC    
  digitalWrite(AC_LOAD, HIGH);   // Fire the TRIAC
  delayMicroseconds(10);         // triac On propogation delay 
         // (for 60Hz use 8.33) Some Triacs need a longer period
  digitalWrite(AC_LOAD, LOW);    // No longer trigger the TRIAC (the next zero crossing will swith it off) TRIAC
}

void loop()  {
  for (int i=5; i <= 128; i++){
    dimming=i;
    delay(100);
   }
}

But when I want to run this code when I receive something from I2C then my resistor is getting burnt and the hunch what I have is that keeping the for() loop inside the if() loop is causing me this problem .

Code:
if (x == 243)
  {
    digitalWrite(led1, HIGH);
      for (int a = 5; a <= 128; a++)
  {
    dimming = a;
    delay(100);
  }
  }
  else
    digitalWrite(led1, LOW);
 

Re: IF FOR loop problem getting my resistors burnt

Hi,

I don´t see a schematic with a resistor than can burn..

I don´t see code with I2C communicatoin.

Maybe I´m blind.

Klaus
 

ThankYou.
This is the code I've written where if I get some data say 243 from I2C then it should dim the bulb for 5% and similarly if I get 255 then the should be from 40% etc..

Code:
#include <Wire.h>
int led1 = 4;
int led2 = 5;
//int led3=5;
int DIM_AC_LOAD = 11;
int SC_AC_LOAD = 9;
int dimming = 128;
//int temp=A0;

void dim_zero_crosss_int()
{
  int dimtime = (75 * dimming);
  delayMicroseconds(dimtime);
  digitalWrite(DIM_AC_LOAD, HIGH);
  delayMicroseconds(10);
  digitalWrite(DIM_AC_LOAD, LOW);
}

void sc_zero_crosss_int()
{
  int dimtime = (75 * dimming);
  delayMicroseconds(dimtime);
  digitalWrite(SC_AC_LOAD, HIGH);
  delayMicroseconds(10);
  digitalWrite(SC_AC_LOAD, LOW);
}

void setup()
{
  Wire.begin(8);                // join i2c bus with address #8
  Wire.onReceive(receiveEvent); // register event
  Serial.begin(9600);           // start serial for output
  pinMode(led1, OUTPUT);
  pinMode(led2, OUTPUT);
  //  pinMode(led3, OUTPUT);
  pinMode(DIM_AC_LOAD, OUTPUT);
  pinMode(SC_AC_LOAD, OUTPUT);
  attachInterrupt(digitalPinToInterrupt(2), dim_zero_crosss_int, RISING);
  attachInterrupt(digitalPinToInterrupt(3), sc_zero_crosss_int, RISING);
}

void loop()
{
  delay(100);
}
void receiveEvent(int howMany)
{Serial.print(howMany); 

  int x = Wire.read();    // receive byte as an integer
  Serial.println(x);         // print the integer

  if (x == 243)
  {
    digitalWrite(led1, HIGH);
      for (int a = 5; a <= 128; a++)
  {
    dimming = a;
    delay(100);
  }
  }
  else
    digitalWrite(led1, LOW);

  if (x == 255)
 {   digitalWrite(led2, HIGH);
   for (int a = 5; a <= 128; a++)
  {
    dimming = a;
    delay(100);
  }
}
else
    digitalWrite(led2, LOW);

}

but whenever the code is coming to the if() loop then my resistor is getting burnt.

Any help & hints appreciated
Thanks in advance

Dimmer.jpg
 

Hi,

I still don't know which resistor you are talking about.

Klaus
 

Hi,

What´s it´s exact type and manufacturer? Best: post a link to the datasheet.

***
Either the resistor is not rated for 220V (worst case it is switching at the peak of the 220V sine. It is 305V. Then - only for a short time the voltage is across the resistor)

Or the TRIAC doesn´t trigger.
Maybe casued by the load --> Describe your load exactely.
Or the TRIAC is wrongly connected --> show us the exact connection scheme with all the pin names.
Or you used an non suitable TRIAC --> What´s it´s exact name and manufacturer? Best give a link to the datsheet.

Klaus
 

I = V/R = 230 / 1k = 0.23

P = I^2R = 0.23 * 0.23 * 1000 = 52.9W
 

Hi,

While Okada is correct in the calculation, this is only for a very short time. The resistor doesn´t need to be rated for 53W.

But it needs to be rated for the voltage, to prevent a spark from one pin to the other.

Klaus
 

See when I'm using the code (Dimmer) which I posted in the first thread then its working fine even for a long time and nothing is being burnt ,

but when I'm using code using I2C (thread 3) then at that time when the code enters into if() conditional loop then my resistor is getting burnt.
the hunch what I've is due to interrupts the zero cross detection isn't happening leading to damage of circuit.

The hardware connections, modules, components everything is connected perfectly without any error because I tried it using the dimmer code (1st thread) and nothing went wrong.

Thanks for the reply please lead me to the solution for this.

Components used:
TRIAC - BT138
LOAD - 100W Incandescent Bulb(resistive load) & even Ceiling Fan (inductive load(added snubber circuit too))
 

I don't see how a wrong trigger pattern could cause burning of the 1k resistor in the given post #3 circuit. It's presumed that the resistor has sufficient voltage rating and e.g. 1/4 W power rating, also that the triac is actually the sensitive gate BT138 and not a different type with considerable higher trigger current.

At worst case, a wrong trigger pattern can burn the fan motor by switching only one half wave.
 

So what's the solution for this ?
BT138 is a good one and even resistors are having sufficient voltage rating
and as I said its not hardware problem,its software problem,
when the code enters into if() loop only at that time my resistor burnt 2 times.
so it is due to zero cross detection isn't happening due to interrupts.(since onReceive() is an ISR & even dim_zero_crosss_int is also an ISR)
 

When zero cross doesn't happen then TRIAC is not fired so how can resistor burn ? Only after ZC detection and after required delay the gate is fired.

Zip and post your complete circuit if possible Proteus circuit. I will test your code on hardware here.
 
Last edited:

Thanks , I've uploaded programs as well as proteus circuits too.
Will be waiting for a solution
Thanks in advance
 

Attachments

  • Programs & Proteus designs.zip
    94.2 KB · Views: 74

Hi,

as I said its not hardware problem,its software problem,

I don´t agree.
With the correct hardware it should be impossible to burn this resistor. Independent of what the software does. eg. what firing signal is sent out.

***
But with wrong hardware it may function for a specific situation, but it may fail for another situation.

Klaus
 

I've changed the code and kept all the delay functions inside the loop instead of ISR, but even now its not working fine,I'm receiving the data too slowly. (because I believe that there is also a conflict between the zero cross interrupt and the receive event interrupt. When the code is in the very length receive event block, the other interrupt for zero cross can not be executed.
)
Any solution appreciated
Thanks

Code:
#include <Wire.h>
int led1 = 4;
int led2 = 5;
int DIM_AC_LOAD = 11;
int volatile dimming = 128;
int wireValue;
void dim_zero_crosss_int()
{
int dimtime = (75 * dimming);
delayMicroseconds(dimtime);
digitalWrite(DIM_AC_LOAD, HIGH);
delayMicroseconds(10);
digitalWrite(DIM_AC_LOAD, LOW);
}
void setup()
{
Wire.begin(8);
Wire.onReceive(receiveEvent);
Serial.begin(9600);
pinMode(led1, OUTPUT);
pinMode(led2, OUTPUT);
// pinMode(led3, OUTPUT);
pinMode(DIM_AC_LOAD, OUTPUT);
pinMode(SC_AC_LOAD, OUTPUT);
attachInterrupt(digitalPinToInterrupt(2), dim_zero_crosss_int, RISING);
}
void loop()
{
delay(100);
if ( wireValue != 0 ) {
if (wireValue == 243)
{
digitalWrite(led1, HIGH);
for (int a = 5; a <= 128; a++)
{
dimming = a;
delay(100);
}
}
else
digitalWrite(led1, LOW);
if (wireValue == 255)
{
digitalWrite(led2, HIGH);
for (int a = 5; a <= 128; a++)
{
dimming = a;
delay(100);
}
}
else
digitalWrite(led2, LOW);
}
}
void receiveEvent(int howMany)
{
Serial.print(howMany);
Serial.print('\n');
int x = Wire.read();
Serial.println(x);
wireValue = x;
}
 

Hi,

No wonder that your program is slow. You waste most of the time in a dumb busy delay loop, and this within an ISR.

Both should be avoided.
That's why microcontroller_manufacturers add periferals inside the chip.
Timer/counter, capture, interrupts, waveform generation (PWM)...

In your case ... with high delay value you waste about 100% of processing power, maybe you even run into processing power problems.
The same could be done with the use of periferals with less than 1% processing power.
It's on you ..

Klaus
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top