program shows indifferent behaviour

Go To Last Post
20 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0
void m1_up_op(void)
{
	LCDClear();
	LCDWriteString("  Motor1 in FW");
	PORTD &= 0x0F; // clear upper 4, keep lower 4 
	PORTD |= M1FW;
	m1dn_lt=0;
	while(1)
	{
		if(READ(A,0)==HIGH)
		{
			stop_all_motor();
			break;	
		}
		else if(READ(C,4)==HIGH)
		{
			stop_all_motor();
			m1up_lt=1;
			M1up_limit();
			break;
		}
	}
	stop_all_motor();
	scan_lcd();
}
void m1_dn_op(void)
{
	LCDClear();
	LCDWriteString("  Motor1 in REV");
	PORTD &= 0x0F; // clear upper 4, keep lower 4 
	PORTD |= M1REV;
	m1up_lt=0;

	for(;;)
	{
		if(READ(A,1)==HIGH)
		{
			stop_all_motor();
			break;	
		}
		else if(READ(C,4)==HIGH)
		{
			stop_all_motor();
			m1dn_lt=1;
			M1dn_limit();
			break;
		}
	}
	
	stop_all_motor();
	scan_lcd();
}

void input_scanning(void)
{	
	if(READ(A,0)==LOW)
	{
		while((READ(C,4)==LOW)&(READ(A,0)==LOW))
		{
			m1_up_op();
		}
		stop_all_motor();
		if(READ(C,4)==LOW)
		{	
			M1up_limit();
		}
	}
	else if(READ(A,1)==LOW)
	{
		while((READ(C,4)==LOW)&(READ(A,0)==LOW))
		{
			m1_dn_op();
		}
		stop_all_motor();
		if(READ(C,4)==LOW)
		{
			M1up_limit();
		}
	}
//
//
//
//}
main()
{
init_port();
//
//
while(1)
{
Input_scanning();
}

}

my program is a lengthy one i just p[ost the portion i have faced problem
when i press the button for motor 1 fw(A.0) it run until if the pin C,4 becomes high..
and when i press the button A.1 s/m become hang motor runs continuosly.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

How could anyone help? You haven't shown init_port(). You haven't shown READ() and you haven't shown a number of the called functions (I guess the LCD ones don't matter but anything to do with the motors might).

The very fact that this code has virtually no comments suggests that it may not have been well designed. Do you have flow charts or other form of state diagrams showing the flow of expected operation that would help anyone follow what's supposed to be going on here. (usually the comments might be enough - but there aren't any).

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

That's the Specification. If we had that (what it is intended to do) we could read your program and pretend we were an avr microcontroller and see where the results go wrong.

Imagecraft compiler user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Specification?

Not allowed! You always have to analyze the nonworking code obfuscated by the previous developers and guess what it's supposed to do. You will be flogged based on how well your reproduction simulates previous bugs.

If you don't know my whole story, keep your mouth shut.

If you know my whole story, you're an accomplice. Keep your mouth shut. 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Indifferent to what?
Your pressing of the button?

Four legs good, two legs bad, three legs stable.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The & operator does a bitwise AND of the two ==LOW comparisons, probably not what you intend unless you have intimate knowledge of the way the compiler handles such expressions. Use && for a logical AND, which will also allow the compiler to optimize it to two conditional jumps.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
program shows indifferent behaviour
The apathy of young programs these days astounds me ;)

Regards,
Steve A.

The Board helps those that help themselves.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

what i mean is

if(motor pin == low)
{

if(limitswitch == high)
{
//on mottor
while((motor pin|limitswitch)==low);
}
}
the problem is that while the motor on time it will not stop even if limit switch become high.
i used PORT C for limit switches and disable jtag

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

As Dak664 pointed out:

while((READ(C,4)==LOW)&(READ(A,0)==LOW))

is probably not what you intended

while((READ(C,4)==LOW) && (READ(A,0)==LOW))

& and && are different
& is a bitwise AND
&& is a logical AND

Usually if you see a & or | in a conditional statement, there's most likely an error.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

@kartman
in first i ue like you said &&
but the same problem shows
then i use & even shows the same problem
what is happening is that it works well
motor pin a.0 .and jump over the while condtion
but with limit switch c.4 it does nt read the port c.4
my jtag is disabled.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Reading your code burns my brain. Without comments to tell me what you want to do, I can only guess. I suggest you test your logic using the AVRStudio simulator. If it works there then you might have a hardware issue. Understand that your code is simplistic and does not cope with real world issues like contact bounce and transients.

You were also asked to provide the macros for READ. The point being do you read the PIN register or the PORT register - big difference. You want to read the PIN register.
Give us half the information and you'll get half the answer.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0
#define CLR(port,pin)   (PORT ## port &= ~(1<<pin))
#define SET(port,pin)   (PORT ## port |=  (1<<pin))
#define TOGL(port,pin)   (PORT ## port ^=  (1<<pin))
#define READ(port,pin)   (PIN  ## port &   (1<<pin))
#define OUT(port,pin)   (DDR  ## port |=  (1<<pin))
#define IN(port,pin)   (DDR  ## port &= ~(1<<pin))

avr simulator doesnt read .no hardware problem. i checked many times.
avr studio 4.19

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Well, don't just throw up your hands and do nothing! What have you tried? You have all the tools you need to solve the problem.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Kartman wrote:
Well, don't just throw up your hands and do nothing! What have you tried? You have all the tools you need to solve the problem.

Why not? That's my favorite strategy!

If you don't know my whole story, keep your mouth shut.

If you know my whole story, you're an accomplice. Keep your mouth shut. 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You're doing things like

if(READ(C,4)==HIGH)

if(READ(A,1)==LOW)

That's not going to work.

Try something like this:

if (!!READ(C, 4))

if (!READ(A, 1))

Sid

Life... is a state of mind

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

thank you sid
can you explain why this is not work

Quote:

if(READ(C,4)==HIGH)

if(READ(A,1)==LOW)

That's not going to work.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Let's assume you've defined HIGH as

#define HIGH 1

What will you have when the preprocessor is done with e.g.

if(READ(C,4)==HIGH)

?

This:

if(PINC & (1<<4) == 1)

Now do you see why this will not work?

Why not simply trust the C rule that zero is false and anything non-zero is true?

As of January 15, 2018, Site fix-up work has begun! Now do your part and report any bugs or deficiencies here

No guarantees, but if we don't report problems they won't get much of  a chance to be fixed! Details/discussions at link given just above.

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
Why not simply trust the C rule that zero is false and anything non-zero is true?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Excellent quote - exactly as I wrote it..

As of January 15, 2018, Site fix-up work has begun! Now do your part and report any bugs or deficiencies here

No guarantees, but if we don't report problems they won't get much of  a chance to be fixed! Details/discussions at link given just above.

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

justinjohney wrote:
thank you sid
can you explain why this is not work
Quote:

if(READ(C,4)==HIGH)

if(READ(A,1)==LOW)

That's not going to work.


The problem is that READ() does not return HIGH or LOW, it returns 0, 1, 2, 4, 8, 16, 32, 64 or 128.

When you read PC4, it returns 0 or 16.
When you read PA1, it returns 0 or 2.

Sid

Life... is a state of mind