Input not Captured.

Go To Last Post
5 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I am monitoring AC mains through opto couplers.

I have declares PortC,2 & C,3 as input by declaring DDRC = 0x00; and pulled up - PORTC = 0xFF.

char AC1_NOK;

void AC1_Volts(void)
{
if((PINC & 0x04) == 1)
{
AC1_NOK = 1;
}
else
AC1_NOK = 1;

}

Similarly goes for PORTC,3
char AC2_NOK;
void AC2_Volts(void)
{
if((PINC & 0x08) == 1)
{
AC2_NOK = 1;
}
else
AC2_NOK = 1;
}

But doesn't seem to work.

I have tried every combination with:
if((PINC & 0x08) xx 1) but it would not budge.

I am monitoring AC1_NOK & AC2_NOK on RS232 but no change of state,while on the CRO it clearly shows 5V or 0V.

I am using WINAVR latest version.

I feel stupid to ask this but no Choice.
Please tell me where the fault is.

Thanks in advance.

K.Chandra mohan

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0
if((PINC & 0x04) == 1) 
{ 
AC1_NOK = 1;  // <---- SAME
} 
else 
AC1_NOK = 1;  // <---- SAME
}

It looks like the if else statement does the same thing for both conditions. It will always set AC1_NOK = 1 regardless of the state of ((PINC & 0x04) == 1)

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

And:

((PINC & 0x08) == 1)

is always false, as (PINC & 0x08) can only equal 8 or 0, neither of which are equal to 1.

if (PINC & 0x08) ...

should do what you want.

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

Sorry, That was a wrong entry by me while posting in the Forum.

After checking out the Data sheet,the second function for these two are JTAG pins in ATMega16 and is to be disabled.

Any way, thanking you again for responding

Regards
K.Chandra mohan

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

Quote:
Sorry, That was a wrong entry by me while posting in the Forum.

Which in why you should always copy and paste your code. We can't help you if the code you are using is not the code that you post.

Regards,
Steve A.

The Board helps those that help themselves.