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.

Counting car sensor programming problem

Status
Not open for further replies.

combat cyber

Newbie level 3
Joined
Dec 22, 2009
Messages
4
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Location
Jakarta
Activity points
1,311
Counting car sensor

Hi,
I would like to ask for help
currently, i am building 4 sensors for counting vehicles at the junction of the road
The purpose is to count the vehicle passed the junction . I use 89s52 for the microcontroller and assembly as the language.
Now, I confused about the programming. I'm not able to make the 89s52 gets data from all sensors. I mean when the sensor1,2,3, and 4 is counting, i want 89s52 can receive the counting result from all sensors.
If you don;t mind, please help me
Thank you a lot before
 

what sensor are you using ?? Please post a link to the datasheet.
 

i'm using the Infrared sensor as the transmitter, and photodiode as the receiver.

Added after 9 minutes:

i will upload the schematic tonight

Added after 1 hours 15 minutes:

 

Hi,
I assume that you have on all 4 outputs (same)correct signals-is it right pls?
I dont know your uP, has it digital I/Os, is it not an interrupt priority problem?
K.
 

karesz said:
Hi,
I assume that you have on all 4 outputs (same)correct signals-is it right pls?
I dont know your uP, has it digital I/Os, is it not an interrupt priority problem?
K.

Yes, the output of the sensor will go to port0/A in the µC.
if it is an interupt, what happen to other three if one sensor keeps counting? isn't the others will stop counting?CMIIW
 

One way of solving this issue is to create one common interrupt and connect the outputs from sensors to selected I/O pins so when an interrupt is triggered it can be appropriately dealt with by the microprocessor ..
To do that you’ll need external AND gates and connect them as shown on the attached picture ..
Here is an example of practical realization of the above approach:
**broken link removed**

Whatever you do make sure that the ISR (interrupt service routine) is reasonably short and all other counting is done in the main program ..

Also keep in mind that the time required to service an ISR is in the range of µs, whereas the time that a car uses to pass an intersection is in ms region, so you have plenty of time (well, not exactly you – but the microcontroller) to process data ..

Rgds,
IanP
 

Attachments

  • 8051_and_4_external_interrupts_1126.gif
    8051_and_4_external_interrupts_1126.gif
    17.1 KB · Views: 159

it is like bit masking, am i right?
by the way, can i ask more help?
i got help from my senior. It is the bit masking program.
but, we write it in C program, could anyone write it in assembly, or at least give me hint to write array in assembly
thx
sensor active -> "1" else "0". 8 sensors attached in portA. counter "sensor n" is in count[n]

/* count buffer*/
int count[8];

/* previous switch state */
int state[8];
int i;

void main(void){
init();

/* super loop */
while(1){

/* check sensor */
for(i=0;i<8;i++){
if(PINA & (1 << i)){
if(state == 1){
state = 1;
}
}else{
if(state == 2){
state = 0;
count++;
}
}
}

}


}

void init(void){
for(i=0;i<8;i++){
count = 0;
state = 0;
}
}
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top