cancel
Showing results for 
Search instead for 
Did you mean: 

Generate PWM N-Pulses with each different Pulse width

TShet
Associate II

We need to trigger camera by using PWM with different trigger delay for each photo. i.e trigger the camera at 100ms, 120ms, 150ms, 200ms, 210ms, 240ms, 260ms, 280ms, 300ms, 350ms for taking 10 photos at each cycle and this cycle repeats.

Is it possible to generate fixed number of PWD pulses with each different pulse width ?

Any suggestion to achieve my requirement would be greatly appreciated.

7 REPLIES 7
TDK
Guru

There are a few ways to do this. The simplest might be to use an SPI peripheral and use MOSI as the signal to the camera.

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

Which STM32?

The usual way to deal with this is DMA into TIMx_CCR, you'll find examples in Cube.

TDK's idea is interesting, too.

JW

TShet
Associate II

Hello @TDK​  can you explain bit more details about your method ?

Sorry for delayed response, I'm using STM32F733ZE. can you point me with some more details ?

Read Arbitrary waveform generation using timer DMA-burst feature chapter in AN4776 Timer cookbook, and of course the Timer chapter in RM.

JW

You'd have a pattern buffer in memory, loaded via DMA (Memory word to CCRx register on TIM), using trigger sources described for the TIM/DMA

Sure there are diagrams/relationships described in the Reference Manual for the part.

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

Well, if he does not respond...

Consider a typical SPI data transmission

0693W000001rGhQQAU.png

Now ignore everything but the MOSI line. If you send 0b10000110 to a SPI peripheral, you will get the above waveform on the MOSI line. The timing of the signal is determined by the SPI baudrate. If you set the SPI baudrate to 1 kHz (each bit takes 1 ms), and send the following data sequence

{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 96 zero bits
    0x08, 0x00, 0x00, 0x80, 0x00, 0x00, 0x02, ...
// 100 ^            120 ^              150 ^

you would get the beginning of the waveform that you want.

Note that most STM32 series offer a very limited range of possible SPI baudrates. Unless there is a dedicated PLL output for SPI or you are able to slow down the APB clock to a ridiculous frequency (which would slow down all peripherals on that bus), the lower limit of the SPI baudrate is usually 1/1024 of the system clock speed. Which means that on a 100 MHz system you'd need 100 bits data for every ms, 100*350/8 = 4375 bytes prepared for the whole cycle. You might have to send more consecutive 1 bits if the camera requires more time to recognize a trigger.

Also keep in mind that the level of the MOSI line can be high when it is not actively transmitting, so configure the pin initially as GPIO output, and switch to alternate mode only when SPI has started transmitting.