cancel
Showing results for 
Search instead for 
Did you mean: 

Scan inputs and drive outputs after delay

XooM
Associate III
31 REPLIES 31
Andrew Neil
Evangelist III

Why do you have three separate timers?

Surely you just need one timer to give you a "tick", and then you do all your sampling and updating on each tick?

 


@XooM wrote:

I have 8 outputs. I read (sic?) them ...


You mean write them?

SofLit
ST Employee

Hello,

I suggest you to test your code in a real HW not in simulation with like Proteus/Labcenter. 

If needed contact them: https://www.labcenter.com/

To give better visibility on the answered topics, please click on "Accept as Solution" on the reply which solved your issue or answered your question.
SofLit
ST Employee

As you are not using a real HW, the thread has been moved to Other/Software board.

To give better visibility on the answered topics, please click on "Accept as Solution" on the reply which solved your issue or answered your question.

I don't know. I think I'm doing something wrong.

I use 1 timer to scan 24 LEDs with 2 74hc595.
* When some inputs come, I activate the relevant output.

For example, if (input 1 + input 2 + input 5) comes, I activate the Q1 output.

XooM
Associate III

I'm working on a real circuit.

Ozone
Lead II

I don't quite understand.
> I have 8 outputs. I read them with timer17 at 1ms intervals.

Do you want to read back the output values ?
The schematics is too small to decipher any IC types, This outputs seem to be connected said 8-bit shift register. But as said, I can see if as inputs or outputs.

> I have 14 inputs. I read the inputs with timer2 at 1ms intervals to see if there are any inputs.
> I have 8 outputs. I read them with timer17 at 1ms intervals.

Why not read all at once, in the same routine ?
I would use a SysTick interrupt for that, configured to 1ms.

And if you need to care about timing and consistency, add latches to the input.
Otherwise inputs might change in the middle of the read-out process.

> I need a 500ms time delay in such a system, but unfortunately I cannot create this delay and my whole system is blocked. When I set and use a 500ms time interrupt with timer15, the system is blocked.

Sounds like you want to wait inside a (500ms) timer interrupt handler routine for that timeout.
This is a bad idea, as it blocks other interrupts.

This can be done by counter values (variables) from within the SysTick interrupt as well.
Define a global (volatile) variable, and decrement it by 1 in the SysTick handler when not zero.
When the variable is back to zero, the timeout has expired.

What STM32 are you using? What board are you using? ST? Custom board?

To give better visibility on the answered topics, please click on "Accept as Solution" on the reply which solved your issue or answered your question.

@XooM wrote:

For example, if (input 1 + input 2 + input 5) comes, I activate the Q1 output.


You didn't mention anything about performing logic on the inputs before driving the outputs.

I suggest that you forget about that to start with, and just get the delay working.

I would suggest using a 500-entry circular buffer. Each millisecond:

  1. Read the inputs
  2. Drive the LEDs for the inputs
  3. write the input data to the start of the buffer;
  4. Read the end of the buffer
  5. write that data to the outputs, and associated LEDs.

For testing, use a much shorter ring buffer - then you can easily see the data "walking" through it...

 

https://en.wikipedia.org/wiki/Circular_buffer

XooM
Associate III

I control a total of 24 LEDs on 8 outputs, 3 of which are connected to 1 74hc4094 output.

I am trying to turn on the LED I want by scanning them with a timer.