cancel
Showing results for 
Search instead for 
Did you mean: 

How can represent logical gates in software of STM32F429I?

AAbed.1
Associate III

Hi All;

I am working on an STM32F429I timer (PWM-mode1) to obtain two signals then I want to use AND gate inside the program (the input is the two signals come from timer Ch1 &Ch2) and designate one pin to be the final output.

16 REPLIES 16

HAL_GPIO_WritePin(OUT_PORT, OUT_PIN, ( HAL_GPIO_ReadPin(IN_PORT1, IN_PIN1) && HAL_GPIO_ReadPin(IN_PORT2, IN_PIN2)) ? GPIO_PIN_SET : GPIO_PIN_RESET);

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

Where can I put that

inside while(1) (infinite loop)?

There, or some other periodically called function, your call.

Most would just solder a part on the board, or use diodes, to achieve functionality at wire speeds.

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

I don't believe there is a way to do this in hardware. You can do it in software as clive1 says, but there is going to be a delay between when the signal changes and when your output pin changes.

If a delay is okay and your CPU is busy doing other things, one option is to set the two pins as interrupts and within the interrupt, read the value of the two pins and update the output. The delay for this would be around 30 ticks if done efficiently.

If you feel a post has answered your question, please click "Accept as Solution".
turboscrew
Senior III

74C08 has propagation delay 15-20 ns, so using SW is not so bad - relatively speaking...

Edge triggered interrupts (both edges) for both inputs and the interrupt routine (assembly) just reads the inputs and writes the output.

Takes somewhat longer than a logic chip, but not that dramatically.

 We're still talking about tens of nanoseconds.

Newer STM32 models implementation this particular function in the timer, see e.g. 'L4, Combined and Asymmetric modes in timers.

In the 'F4, you could do tricks with DMA or maybe master-slave connection of timers, or simply a different time run with the same period but phase shifted, to achieve a waveform similar to what you desire, whether some of this is suitable depend on the details of the application.

JW

berendi
Principal

When two channels of a timer are in PWM mode 1, then the software equivalent of an AND gate is finding the minimum of the two duty cycle values.

The hardware solution is to configure both pins as open drain outputs with pullups, internal or external, and wire them together.

AAbed.1
Associate III

Thanks for your replays , but Here in this picture, you can find what I want .

So, is that possible to represent NOT and AND gates by Software instead of HW.

Thanks

I will hear from you0693W000001s2U0QAI.jpg

S.Ma
Principal

Why trying to do an "AND"? just generate 2 waveforms using DMA on channel toggle in circular pattern with table length adjust...

There is no smartio, so integrate the burst of pulses in the generation to each channel.