cancel
Showing results for 
Search instead for 
Did you mean: 

Scan inputs and drive outputs after delay

XooM
Senior
31 REPLIES 31

Well, that was totally missing from your initial post & schematic!

 

So, for each 3-bit pattern that you clock into the right-hand shift register on 'x', you have to clock an 8-bit pattern into  the left-hand shift register on 'DATA' ?

 

What, exactly, are you trying to achieve by that?

It seems excessively complicated!

 

Again, I think you need to take just getting the LEDs to work as a project on its own before doing anything else!

 

Start by drawing a truth table.

Thank you for your answers and interest in the subject.I got stuck while coding the device I wanted to control. and I am struggling with some problems. I think my algorithm is wrong, I am trying to find a solution for this.I made the coding that will control all my LEDs.If information comes from 14 inputs or any of the 8 outputs are active, the LEDs are scanned with a timer and work. I have no problem here.

 

I can't express myself. I couldn't find how to explain the problem. I want to create some delay without interrupting the timers and use it wherever I want.


@XooM wrote:

I got stuck while coding the device


It sounds like you have jumped into coding before you've fully thought-through your design.

The secret to solving big problems is to break them down into smaller problems that you can solve.

 


@XooM wrote:

I couldn't find how to explain the problem.


If you can't even describe the problem, how can you even design a solution to that problem.

Go back and think about what you're trying to achieve - make sure you have that thoroughly understood before leaping into a solution.

4094 require SPI data stream ... start with this. From schematics showed is unreadable ... if DATA and CLK is connected to right SPI pins on MCU.

WARNING your LEDS dont have current limiter and max 4094 is 25mA

This is how I control the LEDs. I don't use SPI.

 

#define SER_PIN GPIO_PIN_4 //  SER_PIN
#define SER_PORT GPIOB

#define SRCLK_PIN GPIO_PIN_12 // (SRCLK)
#define SRCLK_PORT GPIOA

#define RCLK_PIN GPIO_PIN_5 // SRCLK_PIN
#define RCLK_PORT GPIOB



void HC4094write()
{
	 HAL_GPIO_WritePin(RCLK_PORT, RCLK_PIN, GPIO_PIN_RESET);

    for(int i=0; i<16; i++)
    {
        if(currentVal & (1<<i))
        {
            HAL_GPIO_WritePin(SER_PORT, SER_PIN, GPIO_PIN_SET);
        }
        else
        {
            HAL_GPIO_WritePin(SER_PORT, SER_PIN, GPIO_PIN_RESET);
        }
        HAL_GPIO_WritePin(SRCLK_PORT, SRCLK_PIN, GPIO_PIN_RESET);
        HAL_GPIO_WritePin(SRCLK_PORT, SRCLK_PIN, GPIO_PIN_SET);
    }
    //HAL_GPIO_WritePin(RCLK_PORT, RCLK_PIN, GPIO_PIN_RESET);
    HAL_GPIO_WritePin(RCLK_PORT, RCLK_PIN, GPIO_PIN_SET);
}

 

 

 

 

@XooM ,

You still not answering my question:

What STM32 device you are using? what board you are using? and the schematics you shared is it just schematics or you are using it for simulation?

I know that software and tested it and it's not efficient for ARM MCUs.

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 have a special design PCB that I use Stm32f030C6T6 and STM32F100C6T6. There is no design error in the PCB. The PCBs are actively used on a working system. So I can't change the design.

I am trying to reprogram these cards.
I used the Proteus program to explain my problem here.


@XooM wrote:

 The PCBs are actively used on a working system. .


So use the same software that is used in those working systems to do your basic scanning.

Get support from the people already using the boards.

Make a table of tasks, decrement a count in SysTick_Handler(), and when you hit zero call the action function.

Set the count to 500 for your delayed execution.

Or make a table you check in main() loop, where you delta a time stamp off of HAL_GetTick(), and check your trigger point.

You don't need to block, just be aware of time and when the timeout will expire.

Need to move beyond linear/sequential code execution and delays

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

ooM ok this work too , but isnt very effective. Seems you be hero of timers use, but dont use hw SPI ?

Primary show code where you see your point of trouble, Write here 

I have 8 outputs. I read them with timer17 at 1ms intervals. is ... FYI output isnt read but writed...

And how delay you mean HAL_Delay?  If you read docu , you see dont use it in ISR except when you setup priorities for ISR right...