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.

multiple inputs simultaneously

Status
Not open for further replies.
like

Code:
a=1;
b=2;

if(portc.f1==1)		
{
	portd.f1=1;                       //100% Brightness        
	
}
else    		
{
	portd.f1=1;                     //pwm=50%
	delay_ms(a);
	portd.f1=0;
	delay_ms(b);
}

I want to build code that is independant of the direction of the object cutting the sensor.
 

You can try


Code C - [expand]
1
2
3
4
5
6
7
input_state = portc; // store the input value
portd |= input_state  // set to high the outputs that represent an input that has 1
 
portd ^= ~input_state;   // invert the portd bits when the same bit in input_state is 0 , leaves bits with 1 in input_state unchanged
delay_ms(a);
portd ^= ~input_state;  // invert the portd bits when the same bit in input_state is 0 
delay_ms(b);



I didn't try it but I think it will work but note that the input polling will be executed after both delays have finished.
 
  • Like
Reactions: varunme

    varunme

    Points: 2
    Helpful Answer Positive Rating
yes, its working

but i really want is the LED has to be 100% until a nearby sensor is intercepted, may it be previous or a next one, can it be possible ?
 

Let me get this right , by default all leds are dimmed, then when a sensor triggers then the led goes 100% and keeps this state until the previous or the next sensor are triggered?

What about the first and last sensor , they only have a sensor in one side (N1 has N2 and N7 has N6), so if N2 doesn't trigger N1 led will be 100% for ever?
 

Let me get this right , by default all leds are dimmed, then when a sensor triggers then the led goes 100% and keeps this state until the previous or the next sensor are triggered?
yes

What about the first and last sensor , they only have a sensor in one side (N1 has N2 and N7 has N6), so if N2 doesn't trigger N1 led will be 100% for ever?
yes

S1 L1
S2 L2
S3 L3
S4 L4
S5 L5


yes
once the S1 is activated then , the L1 goes 100% until S2 is activated and the sequence goes on

for one side problem of first and last sensors , we may avoid the S1 and S5(if it can also be used, then better)
 

Why not use an external interrupt, all sensor inputs are OR'd and input into RB0, when ever the external interrupt is triggered, the new state of of the PORT sensor inputs is stored. By comparing the new state with the previous state the LEDs can be updated as per an algorithm of your choice.

BigDog
 
  • Like
Reactions: varunme

    varunme

    Points: 2
    Helpful Answer Positive Rating
By comparing the new state with the previous state the LEDs can be updated as per an algorithm of your choice.
BigDog
how can it be implemented ?
can u provide one example ?

I am short of time for the project , so I am asking
 
Last edited:

How to do a comparison like in a below scenario

oldstate=0b01001100;
nwstate=0b10010100;

when two objects moved away to B and one object remained there.

anyone having helping hand ?
 

What are the maximum number of objects within this sensor network?

Is it three or can there be more?

Can more than one object at a time reside in a sensor's scope? If so then you have considerably complicated matters.

I assume any sensor triggered will result in a new state be recorded. Is this not a correct assumption?

A bitwise AND with detect any object remaining stationary, Bs = 0b00000100. The mask produced from this operation can then be used to remove all stationary objects from the field.

The resulting bit fields, Bos = 0b01001000 and Bns = 0b10010000, can then be compared and analyzed to determine directionality of movement of the remaining two objects.

You can then take Bos, left shift by one and then bitwise AND with Bns, which will result in a bit field of the objects which moved to the left, Bl = 0b10010000.

You can then take Bos, right shift by one and then bitwise AND with Bns, which will result in a bit field of the objects which moved to the right, Br = 0b00000000.

BigDog
 
  • Like
Reactions: varunme

    varunme

    Points: 2
    Helpful Answer Positive Rating
Yes, by implementing the algorithms I have provided above.

I would also recommend implementing a reasonable delay to minimize the lights from unnecessary restarts.

BigDog
 

Yes, by implementing the algorithms I have provided above.
BigDog

using

Use an external interrupt, all sensor inputs are OR'd and input into RB0, when ever the external interrupt is triggered, the new state of of the PORT sensor inputs is stored. By comparing the new state with the previous state the LEDs can be updated as per an algorithm of your choice.
BigDog

and

A bitwise AND with detect any object remaining stationary, Bs = 0b00000100. The mask produced from this operation can then be used to remove all stationary objects from the field.

The resulting bit fields, Bos = 0b01001000 and Bns = 0b10010000, can then be compared and analyzed to determine directionality of movement of the remaining two objects.

You can then take Bos, left shift by one and then bitwise AND with Bns, which will result in a bit field of the objects which moved to the left, Bl = 0b10010000.

You can then take Bos, right shift by one and then bitwise AND with Bns, which will result in a bit field of the objects which moved to the right, Br = 0b00000000.

BigDog

?
 

Due to the nature of the sensor array and object traffic, polling would be a more viable solution in this case, rather external hardware interrupts.

However, the algorithms presented should provide you the desired results. The major issuing being the type of sensor employed and its range of field coverage.

BigDog
 
  • Like
Reactions: varunme

    varunme

    Points: 2
    Helpful Answer Positive Rating
Due to the nature of the sensor array and object traffic, polling would be a more viable solution in this case, rather external hardware interrupts.
BigDog
so polling should be like

if(RB1==1)
{
portd=result; // code
}

?


i am doing only prototyping only for the moment, so as a dummy , i am using IR sensor (photodiodes) , in actual implementation, we look for other ones.
 

A better solution would be:

Code:
while(1)
{
    if(PORTB != BNS)     // Test PORTB against the latest new state
    {
         BOS = BNS;      // Copy new state to old state
         BNS = PORTB;   // Copy entire PORTB to new state

         Analyze();       // Analyze traffic movement
    }
}

BigDog
 
  • Like
Reactions: varunme

    varunme

    Points: 2
    Helpful Answer Positive Rating
You can then take Bos, left shift by one and then bitwise AND with Bns, which will result in a bit field of the objects which moved to the left, Bl = 0b10010000.

You can then take Bos, right shift by one and then bitwise AND with Bns, which will result in a bit field of the objects which moved to the right, Br = 0b00000000.
BigDog

we should combine these two and output to the output port using or , isnt it ?
 
Last edited:

we should combine these two and output to the output port, isnt it ?

What is the purpose of the output port? Is this output ports purpose to controlling the street lights?

If so, yes you'll need to formulate the "rules" as to which lights are on or off, based on the traffic analysis.

BigDog
 

yes, output port is to control the street lights.
 

Now that you have presented a clearer picture of the final application, you need to clearly define the "rules."

For instance, when a vehicle enters the street under your sensors surveillance, do you turn on all the street lights at once?

Also what about parked vehicles, do you leave the street light on in the vehicles vicinity? Or do you turn it off after a predetermined time?


BigDog
 

The lights that will glow 100%, which is near the sensor , otherwise all lights will be 50%
for parked vehicles, the light will go to 50% after a predetermined time ( better use a timer_interrupt isnt it ?)
Here its not the case of off, it will go to 100% or 50%

varun
 
Last edited:

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top