cancel
Showing results for 
Search instead for 
Did you mean: 

control algorithm for LED shift register

XooM
Associate III

Friends, which algorithm do you use to control the LEDs in this structure? I need your ideas. I have prepared a table of the LEDs' turn on order.

ttaa

 

34 REPLIES 34

@unsigned_char_array wrote:


The groups are connected in parallel. So you cannot have:


Ah yes - you're right.

Andrew Neil
Evangelist III

@XooM What is driving you to use this board - which, apparently, has inadequate documentation and no support??

Friends, I will give you the document you want in a moment, but I do not understand how this forum works. In the country where I speak my own language, we can understand what we mean very quickly without giving too much detail. Here, people either have poor electronics knowledge or want to know everything.
I just made a simplified drawing to ask for help from the algorithm.
The missing parts are not relevant to the question I asked.
I assumed that everything was complete and wanted to talk about the algorithm. There is no deficiency or error in the design of the circuit. The circuit is an actively working circuit.
Since every programmer has a different perspective, I asked to learn your perspective on the event.
I will explain the missing parts of the circuit and my own coding in a way you can understand.
I will share it in 30 minutes.


@XooM wrote:

The missing parts are not relevant to the question I asked.


Again, we had no way to know whether the missing parts were simply omitted from the diagram for clarity, or were an actual design error.

 


@XooM wrote:

Friends, I will give you the document you want in a moment, but I do not understand how this forum works. In the country where I speak my own language, we can understand what we mean very quickly without giving too much detail. .


I think the real difference is between when you're discussing with people face-to-face, and when using a forum.

When you discuss face-to-face, people can actually see what you're talking about - it's there in the room with them.

So they have a lot more information & context than just what you say.

When you post on a forum, we can see nothing other than what you put in your posts.

We don't get any of that non-verbal context.

That's why you need to give a lot more detail.

And explain what you've omitted - and why.

Andrew Neil
Evangelist III

I made a spreadsheet to investigate possible combinations of LEDs: 

AndrewNeil_0-1732120072724.png

 

You image in question make more problem as info. Missed transistors is then on right side and left 8bit is connected to LED direct. Then your code need

array uint16_t LEDs[3] = { 0x0080, 0x0040, 0x0020 };

for set leds 0-7 manage

LEDs[0] |= (8bitled) <<8 ; you can manage this all 8 led 

for 8-15

LEDs[1] |=(8bitled) <<8 ;

then your led manager timer every 5ms show one of this

timer 5ms code

 

 

static uint8_t qoutposition=0;
HC4094write(LEDs[qoutposition]);
qoutposition++;
if(qoutposition==3) qoutposition=0;



...
//code for write
void HC4094write(uint16_t data)
{
	 HAL_GPIO_WritePin(RCLK_PORT, RCLK_PIN, GPIO_PIN_RESET);

    for(int i=0; i<16; i++)
    {
        if(data & (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_SET);
}

 

 

 

 

XooM
Associate III

 

 

 

#define SER_PIN GPIO_PIN_4 //  SER_PIN
#define SER_PORT GPIOB

#define SRCLK_PIN GPIO_PIN_12 // SRCLK_PIN
#define SRCLK_PORT GPIOA

#define RCLK_PIN GPIO_PIN_5 // RCLK_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);
}
void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
{
if(htim->Instance==TIM17) // 250us
{
if(input1==0)
{
currentVal=0b1000000010000000; //led1
HC4094write();
}
if(input2==0)
{
currentVal=0b1000000001000000; // led2
HC4094write();
}
if(input3==0)
{
currentVal=0b1000000000100000; //led3
HC4094write();
}
if(input4==0)
{
currentVal=0b0100000010000000;  //led4
HC4094write();
}

}
}

 

 

 

 

No your code isnt ok , because led light if more as one input active only some us . if Only one input is active led light relative ok only one data is send to one led and repeat in time input is selected.

But i mean your real situation not guarantie only one input selected ?

TRY in timer only my code and set values in main based for all 24 leds.

Too your code send into 595 LSB first, but normal logic is MSB first. Then maybe try change

 

if(data & (1<<(15-i)))

and swap bytes in array

uint16_t LEDs[3] = { 0x0100, 0x0200, 0x0400 };

for set leds then 
LEDs[0]|=8leds;...

 


@XooM wrote:

 

 

void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
{
if(htim->Instance==TIM17) // 250us
{
if(input1==0)
{
currentVal=0b1000000010000000; //led1
HC4094write();
}
if(input2==0)
{
currentVal=0b1000000001000000; // led2
HC4094write();
}
if(input3==0)
{
currentVal=0b1000000000100000; //led3
HC4094write();
}
if(input4==0)
{
currentVal=0b0100000010000000;  //led4
HC4094write();
}

}
}

 

 


I haven't checked HC4094write, but I assume it works. I would only change it to not use a global and take a parameter Why are you bitbanging and why aren't you using SPI?

As for your timer function:

  • I don't know what "input1" and "input1", etc. is.
  • I would avoid using any inputs for the moment and just use fixed values, makes it much easier to test. This way you can test inputs and outputs separately.
  • You are not using else-if, so you are overwriting currentVal if multiple "input" variables are non-zero
  • I wouldn't use magic numbers. Use bitshifting instead. So if you want bit 9 set for instance use currentval = 1UL<<9
  • why don't you use the algorithm I gave you?
  •  
Kudo posts if you have the same problem and kudo replies if the solution works.
Click "Accept as Solution" if a reply solved your problem. If no solution was posted please answer with your own.