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.

Toggle Flip flop implementation in microcontroller. Mistake in this C code.

Status
Not open for further replies.

yourdreamz

Junior Member level 1
Junior Member level 1
Joined
Oct 23, 2008
Messages
17
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Visit site
Activity points
1,465
I'm trying to implement a simple toggle flip-flop in a microcontroller. One pin as an input Pin 'TOGGLE_IN' and another as output 'TOGGLE_OUT'. What is expected is that the output should toggle its state every rising edge of Input pin. The following code that I wrote is not working as expected. What actually happen is that it toggles only once from Low to high and stays there. Doesn't work anymore. Could anybody please help find what am I doing wrong.

Code:
while(1)
	{
		if(lastToggleInStatus != TOGGLE_IN)
		{ 
			if((lastToggleInStatus == OFF) && (TOGGLE_IN == ON))
			{
				Delay(DEBOUNCING_TIME);
				if((lastToggleInStatus == OFF) && (TOGGLE_IN == ON))
				{
					temp = 	TOGGLE_OUT;
					TOGGLE_OUT = ~temp ;
				}
			}
			lastToggleInStatus = TOGGLE_IN;
		}
}
Thanks for the help in advance.
 
Last edited by a moderator:

Part of the code is redundant, and there's also a certain chance that an input edge is missed. But apart from this points, the code is supposed to work. The only reason I can imagine at first sight is that the high state of TOGGLE_OUT isn't sensed which might happen if it's an output pin with a too low load resistance.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top