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.

[Moved] managing high value of bits using time interval

Status
Not open for further replies.

varunme

Advanced Member level 3
Joined
Aug 10, 2011
Messages
741
Helped
17
Reputation
36
Reaction score
17
Trophy points
1,318
Activity points
5,764
How can I manage the high value of bits ?
eg :
if portc.f1 is high for 3minitues it should clear and go to low
 

Re: managing high value of bits using time interval

How can I manage the high value of bits ?
eg :
if portc.f1 is high for 3minitues it should clear and go to low

Your question i not very much clear, Do you mean integer with huge value?
 

Re: managing high value of bits using time interval

No, I want to check the bits in the port, the Bits which are high for more than 3minitues then it should go low. )
means the led connected on the bit is " ON " for more than 3minitues, it should go " OFF "

This senario occours from the sensors, if the correspoing sensor didn't able to cut off the LED then as a precaution for error checking i want to use this.
 

Re: managing high value of bits using time interval

This is simple, you need to make a function for a port, in which port is splitting into ports pins bits, make a Timer interrupt for 100ms.

Make an Array of 8 unsigned short int (2 bytes: value from 0 to 65535), which is directly assosiated to ports bin.

unsigned short int portA[8];

so, portA[0] is port A First pin and portA[7] is port A Last pin

At every Timer_ISR (Timer interrupt occur) call that function to check ports pins, if found any bit high than increment 1 to its corrosponding array int and if found any bit Low than Reset that corrosponding Array pin to ZERO.

Cross check array values on every Timer interrupt, if found an array value greater than 300 than set that corrosponding output to LOW.
 
  • Like
Reactions: varunme

    varunme

    Points: 2
    Helpful Answer Positive Rating
Re: managing high value of bits using time interval

can u give the code for spliting the Port into individual bits ?
 

Re: managing high value of bits using time interval

can u give the code for spliting the Port into individual bits ?

Maybe this is compiler dependent. For my compiler the below example code for PORTA works just fine.

Code:
typedef union
{
  volatile unsigned char value;
  struct
  {
    volatile unsigned char pin0 : 1,
                           pin1 : 1,
                           pin2 : 1,
                           pin3 : 1,
                           pin4 : 1,
                           pin5 : 1,
                           pin6 : 1,
                           pin7 : 1;
  };
} _PORT;

#define _PORTA    (*(_PORT *) &PORTA)

And some examples:

Code:
_PORTA.value = 0xFF;  //set all portA pins	
_PORTA.pin0 = 0;  //clear pin A0
_PORTA.pin5 = 1;  //set pin A5


Hope this helps.
 
  • Like
Reactions: varunme

    varunme

    Points: 2
    Helpful Answer Positive Rating
Re: managing high value of bits using time interval

can we access this inside a loop ?

like

for(i=0;i<=7;i++)
{
_PORTA.pin = 1;
delay_ms(100);
}
 

varunme said:
can we access this inside a loop ?
There are a few ways. The following one involves port declaring as well, otherwise you would need more defines for all ports.

Code:
#define _SET_PIN(port,bit)		_PORT##port##.value|=(1<<bit)
#define _CLR_PIN(port,bit)		_PORT##port##.value&=~(1<<bit)
#define _TOG_PIN(port,bit)		_PORT##port##.value^=(1<<bit)


After those defines, try this code and observe from the debugger:

Code:
_PORTA.value = 0;
for(int i = 0; i < 8; i++)
{
  _SET_PIN(A,i);
  _CLR_PIN(A,i);
  _TOG_PIN(A,i);
  _TOG_PIN(A,i);
}

PORTA pins should be toggled 4 times, each for every line inside the for loop. _PORTA.value should start the loop from 0xFF and end the loop with 0.
 
  • Like
Reactions: varunme

    varunme

    Points: 2
    Helpful Answer Positive Rating
You can also use


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
// add this defines
#define SETBIT(ADDRESS,BIT) (ADDRESS |= (1<<BIT)) 
#define CLEARBIT(ADDRESS,BIT) (ADDRESS &= ~(1<<BIT)) 
#define FLIPBIT(ADDRESS,BIT) (ADDRESS ^= (1<<BIT)) 
#define CHECKBIT(ADDRESS,BIT) (ADDRESS & (1<<BIT)) 
#define WRITEBIT(RADDRESS,RBIT,WADDRESS,WBIT) (CHECKBIT(RADDRESS,RBIT) ? SETBIT(WADDRESS,WBIT) : CLEARBIT(WADDRESS,WBIT))
 
// and then you can use
SETBIT(PORTX,2);  // set bit2 of portx (set to 1)
SETBIT(PORTY,0);  // set bit0 of porty
 
CLEARBIT(PORTX,5); // clear bit5 of portx (set to 0)
 
FLIPBIT(PORTX,2);  // invert bit2 of portX, if it was 1 it becomes 0, and if 0 becomes 1
                    // example for portx 0x10101010 the result is 0x10101110
                    
if (CHECKBIT(PORTX,4)) {} else {} // result is true if bit4 of portx is 1, false if it is 0
if (!CHECKBIT(PORTX,4)) {} else {} // result is true if bit4 of portx is 0, false if it is 1
 
 
WRITEBIT(PORTX,0,PORTY,2);   // copy the bit0 of portx to bit2 of porty



Alex
 
  • Like
Reactions: varunme

    varunme

    Points: 2
    Helpful Answer Positive Rating
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top