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.
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:
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:
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.