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.

[AVR] Pulse supplied by mcu(C coding in MicroC) is fed to Thryristor Circuit for Triggering

Status
Not open for further replies.

Nusrat Mary

Junior Member level 1
Junior Member level 1
Joined
Mar 16, 2012
Messages
19
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Location
Dhaka, Bangladesh
Visit site
Activity points
1,462
Hi all,


Hope going well.

I'm on a electronic project which is dealing with triggering Single Phase Thyristor Circuit through mcu ATmega16.
For this I have used ATmega16 for controlling the pulses which are fed to Single Phase Thyristor Circuit (four thyristors).
Simulation is done in Proteus 7.8sp2 and the code compiled in MicroC Pro with C Program. The four outputs (pulses) connected to ATmega16 are- PA7, PA6, PA5, PA4 and the input to mcu is with PC2 port. The image of circuit simulation is shown with attachment below.

simulation 3.png

From the above image the four pulses from mcu ports A7, A6, A5, A4 is tested by connecting those in four resistors R7, R6, R5, R4, the (oscilloscope is giving the wave shapes for testing pulses), which are later will be provided to Single Phase Thyristor Circuit for Triggering. The ATmega16 got an input at port C2, which is with the AC input (of 10v ac 50hz) into a pulse, which is HIGH for 10msec and LOW for 10msec (Period is 20msec which is shown as yellow wave shape from oscilloscope view at the last attached figure).

But, my problem is in C coding in MicroC Pro, as far as I have done in coding is as below:

Code:
void main() {

DDC2_bit= 0;//Pin Input

DDA7_bit = 1;//Pin Output
DDA6_bit = 1;//Pin Output
DDA5_bit = 1;//Pin Output
DDA4_bit = 1;//Pin Output


while(1)
{

    if (PORTC2_bit)
     {

      PORTA7_bit = 0;
      PORTA6_bit = 0;
      PORTA5_bit = 0;
      PORTA4_bit = 0;
      delay_ms(3);

      PORTA7_bit = 1;
      PORTA6_bit = 1;
      PORTA5_bit = 0;
      PORTA4_bit = 0;
      delay_ms(4);

      PORTA7_bit = 0;
      PORTA6_bit = 0;
      PORTA5_bit = 0;
      PORTA4_bit = 0;
      delay_ms(6);
      }
          else //if (PORTC2_bit= 0)
          {
           PORTA7_bit = 0,
           PORTA6_bit = 0,
           PORTA5_bit = 0,
           PORTA4_bit = 0;
           delay_ms(3);

           PORTA7_bit = 0;
           PORTA6_bit = 0;
           PORTA5_bit = 1;
           PORTA4_bit = 1;
           delay_ms(1);

           PORTA7_bit = 0;
           PORTA6_bit = 0;
           PORTA5_bit = 0;
           PORTA4_bit = 0;
           delay_ms(6);
          }

}
}

****IM NOT SURE ABOUT THE CODE and ITS NOT WORKING as expected****

I wanted the output after running the simulation is as following figure:

Expected Outputs as a draft:

pulses expected from ATmega16.png

2ports- A7, A6 will be ON after 3msec and will be OFF after 4msec (will give a single pulse only as the above *hand drawing* figure for 1msec) after getting the input from PC2 pin (if PC2 pin is HIGH). Similarly the other 2ports- A5, A4 will be ON after 13msec and turn OFF after 14msec (will give a single pulse only as the above figure for 1msec) after getting the input from PC2 pin (if PC2 pin is LOW). And when input is ON (PC2) during its 10msec period, A7 and A6 ports will give only ONE PULSE of 1msec period, consequently, the other 2ports A5 and A4 will give only ONE PULSE of 1msec period.

According to Simulation:

The output found in the oscilloscope wave shape view is as the following figure:

pulse must n must nt.png

If I load the above code "example_name.hex" file to my simulation at Proteus 7.8sp2, the following issues occurs:

**4points are problems**

1. Simulation is not reading the condition on "if" statement (i.e., the A7 and A6 ports are not giving pulse)
**although compiler says its error less
2. Its only reading the condition on "else" statement (i.e., only the A5 and A4 ports are giving pulse)
3. As a result two ports are working among the four pulses
4. The two ports A5 and A4 are giving pulse when the PC2 pin is HIGH, where its not suppose to give
(A5 and A4 ports giving pulse in place of other two ports's places A7 and A6 as shown in the oscilloscope view)!!


If the four pulses were correctly working, then those pulses will be provided to trigger the Single Phase Thyristor Circuit.

I know the C Pogram is not correct, so can anyone help me on that?

A very thanks in advance. :)
 

Your code is missing any means to detect a rising (or falling) edge of the input signal. So it can't synchronize to it.

If the program has nothing else to do, it can e.g. wait in a loop until a high or low state is detected.

A more complex program can e.g. use input change notification interrupts and possibly timer interrupts,
 

Hi FvM,

Thanks for replying.

Yah, I did not detect any rising (or falling) edges on my code, can you tell me the conditions in "( )"- this of "if" and "else" isn't enough?
Code:
if (PORTC2_bit) {//code}
     
else //if (PORTC2_bit= 0) {//code}

Although dont know how to detect edges, but giving a try on code.
And you mentioned about some complex programs, honestly no idea about that.

Thanks.
 

You have designed the code to achieve a specific purpose.

What I suggest firstly is to check with pencil and paper method what the code actually does. Then correct it if necessary.

An edge is generally spoken a signal that has been e.g. low before and changes to high. I believe you should be able to figure out how to detect it in a C code, without using hardware features like input change notification.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top