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] ATmega8 Zerocross Detection circuit

Status
Not open for further replies.

tahertinu

Member level 4
Joined
Jun 11, 2011
Messages
74
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Location
Ahmedabad
Activity points
1,752
Hi all,
I am working on AC dimmer circuit , for that i have have interfaced the Zero Cross Detection circuit with ATmega16 INT0 pin. INT0 is configured as a rising edge. here i am attaching image which shows the working of Zero cross detection is good. but when i interface its output with ATmega INT0 pin, the Zero Cross Pulsed gets down and nothing happen on INT0 pin. i have tested INT0 code separately which also working as expected. I am not getting where i am doing anything wrong? please somebody help me who has worked with such project ever before
Here is a code snip which gives INT0 routine and Int0 Configuration as rising edge.

Code:
/*
 *  Written in AVR Studio 5 / AVR Studio 6
 *  Compiler: AVR GNU C Compiler (GCC)
 *
 *  Author: AVR Tutorials
 *  Website: www.AVR-Tutorials.com
*/
 
#include <avr/io.h>
#include <avr/interrupt.h>
 
#define F_CPU 16000000UL
#include <util/delay.h>
 
#define DataPort	PORTC	// Using PortC as our Dataport
#define DataDDR		DDRC

//Interrupt Service Routine for INT0
ISR(INT0_vect)
{
	unsigned char i, temp;
	cli();
	//_delay_ms(500); // Software debouncing control
 
	//temp = DataPort;	// Save current value on DataPort
 
	/* This for loop blink LEDs on Dataport 5 times*/
	DataPort = 0x00;
	for(i = 0; i<100; i++)
	{
		
		_delay_us(200);	// Wait 5 seconds
	
		//_delay_us(200);	// Wait 5 seconds
	}
 	DataPort = 0xFF;
	//DataPort = temp;	//Restore old value to DataPort	
	sei();
}	
 
int main(void)
{
	DDRD = 1<<PD2;		// Set PD2 as input (Using for interupt INT0)
	PORTD = 1<<PD2;		// Enable PD2 pull-up resistor
 
	DataDDR = 0xFF;		// Configure Dataport as output
	DataPort = 0xFF;	// Initialise Dataport to 1
	
	GICR = 1<<INT0;					// Enable INT0
	MCUCR = 1<<ISC01 | 1<<ISC00;	// Trigger INT0 on rising edge
 
	sei();				//Enable Global Interrupt 
    while(1)
    {
	/*	if(DataPort >= 0x80)
			DataPort = 1;
		else
			DataPort = DataPort << 1;	// Shift to the left
 
		_delay_ms(500);	// Wait 5 seconds */
		if(!(PIN_1 & (1<<SW_1))) //If switch is pressed
		{
			toggle(LED_PORT,LED_1);
			_delay_ms(1000);
		}
		else if(!(PIN_1 & (1<<SW_2))) //If switch is pressed
		{
		toggle(LED_PORT,LED_2);
		_delay_ms(1000);
		}
    }
}

When i use this Zero Cross Detection pulses as a normal switch its working good, but when i use it with INT0 pin the pulse get destroyed and nothing happens as attached images
1675199400_1404870504.jpg
8512216500_1404870506.jpg
5135125800_1404870507.jpg
 

You are using external interrupt to detect an event that happens every 20ms, and you keep a delay of 20ms inside interrupt? First remove all delays from interrupt and then try again. If you want to do tricks with the LED, try something different, maybe from main().
 
You are using external interrupt to detect an event that happens every 20ms, and you keep a delay of 20ms inside interrupt? First remove all delays from interrupt and then try again. If you want to do tricks with the LED, try something different, maybe from main().

I have removed all unnecessary delays as it was debug code. and i have used
DDRD= 0x00 instead of setting PD0 to high i have kept it on low for input.
code is working in simulation. need to check in real hardware. I am grateful towards your precious response
 

as i am able to work the circuit in Proteus simulation it seems it is correct, but in Proteus i am getting warning. not running in real time due to CPU overload, so what dose it means ? is it something wrong with programming or schematic diagram? here i am attachingProteus SimulationLOG.pngRunnin_ZeroCross.jpg two images of working simulation ans stopped one. pleas guide me somebody to the right way if i am ding some thing wrong with the schematic or program.
Thanks in Advance.
 

As far as I remember the message means exactly what it's saying. The simulation works correctly, however the Proteus stopwatch is not synchronized with your windows clock while you are running the simulation (run at different speed), due to high processing load. So, it should not affect results you're getting from the simulation, however it is the best practice to double-check the timing through your own calculation and real-world testing of the system.
 
As far as I remember the message means exactly what it's saying. The simulation works correctly, however the Proteus stopwatch is not synchronized with your windows clock while you are running the simulation (run at different speed), due to high processing load. So, it should not affect results you're getting from the simulation, however it is the best practice to double-check the timing through your own calculation and real-world testing of the system.
Thanks a lot for your valuable eply Funkehed. :)
 

Hi all.

As I have developed that ZeroCross Detector Circuit and Tested it on CRO but i am getting this kind of wave forms instead of pulse at zero crossing. please let me know what can be the issue in my circuit? IMG-20140725-WA0015.jpg
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top