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.

What's more efficient method ?

Status
Not open for further replies.

Djsarkar

Member level 3
Joined
Jul 27, 2020
Messages
55
Helped
0
Reputation
0
Reaction score
1
Trophy points
8
Activity points
301
Hi
I am looking advice on project design.

Let's assume we have PIC12F1840, Sensor X and Output device Y.

Task 1 ,When sensor detects object, micro read the output of sensor and finish first job

Task 2, Turn on device Y

Response time of X is 60 ms
Response time of Y is 30 ms

When I started to solve the problems on paper. I have two solutions in my head

IMG_20200809_140859.jpg


I would prefer interrupt method because it's faster then first method.

What's you recommend? What's better and why it would better?

It's just basic question I am not implementing , only purposes to identify the efficient process.
 
Last edited by a moderator:

Interrupts are "normally" used for critical processes that need to be
serviced as a priority over other tasks. Benefit is reduced latency from
the time a critical event is triggered to the time it gets serviced.

An example, suppose a processor is doing some extensive task, like
checking a lot of fire sensors in a large distribution centers building,
that maybe takes secs to a few minutes of CPU time to check them all.
Now suppose a fire starts somewhere in warehouse. Clearly valuable
time could be wasted before that sensor is checked and the fire protection
system is activated if done by polling. Another example is real time
communications where a stream of data is being handled by code. In
both examples polling causes latency.

In interrupt handling one "normally" wants to simply set a flag and exit, and
handle the interrupt in mainline code. This is to avoid calling f()'s inside
interrupt code which causes a lot of stack push causing latency. Especially
if another interrupt occurs, eg. nested interrupts. Note in some designs you
may not have the luxury to not call a f() inside ISR. You have to decide whats
best. In view of HW and coding and system constraints.


Regards, Dana.
 

Hi,

There are many solutions. And many solutions that will do what you want.

But I have some questions:
1) You say: "When sensor detects object, micro read the output of sensor"
How does the microcontroller know that the sensor detects an object?
Isn't it so the the microcontroller in any case needs to read the sensor .... and by processing the sensor dara it decudes whether there is an object or not.
What is this sensor (vendor, type) and what interface does it use?

2) What does "finish 1st job" mean?

A more detailed information could be helpful.

3) Your first drawing shows: "turn ON Y" then, without any other code it goes to "turn OFF Y".
--> With the speed of a microcontroller there is a good chance that Y never really gets acivated.

4) Your interrupt solution:
Let's say timer periodically fires an interrupt. Within this ISR it just "turns ON Y". After that immediately it returns to the MAIN loop, where it "turns OFF Y"
--> Maybe this is right, maybe wrong, we don't know. We have no information when you want to switch OFF Y.

5) you say "it's faster than method 1".
The microcontroller will work in low microseconds, but X and Y reaction time is in the milliseconds range. Thus I see not much speed benefit.

Klaus
 

    Djsarkar

    Points: 2
    Helpful Answer Positive Rating
The main purpose of asking this question is to solve the problems encountered while designing the program.

So I prepared some requirements for myself and was trying to solve them on paper with pen. That is why I have not given detail information of any sensor

1) You say: "When sensor detects object, micro read the output of sensor"
How does the microcontroller know that the sensor detects an object?
I assume when sensor detects object, it becomes high, and microcontroller read the output

A more detailed information could be helpful.

3) Your first drawing shows: "turn ON Y" then, without any other code it goes to "turn OFF Y".
--> With the speed of a microcontroller there is a good chance that Y never really gets acivated.

4) Your interrupt solution:
Let's say timer periodically fires an interrupt. Within this ISR it just "turns ON Y". After that immediately it returns to the MAIN loop, where it "turns OFF Y"
--> Maybe this is right, maybe wrong, we don't know. We have no information when you want to switch OFF Y.

5) you say "it's faster than method 1".
The microcontroller will work in low microseconds, but X and Y reaction time is in the milliseconds range. Thus I see not much speed benefit.

We can use interrupts at any time, but I want the interrupt to be used only when it is needed.
That's why i used timer interrupt in system
 

Hi,

I don't like guessing...
Your sensor has single line digital logic output ... and is connected to microcontroller input? Yes or no?

....
Also I don't know why you use a timer interrupt. Why no "pin change" interrupt at the pin where the sensor is connected?

You should at least provide a hand drawn schematic...

Klaus
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top