2014-01-30 11:46 AM
Hello,
I'm trying to sample the PB0 pin on the STM32F103RET6, the mcu is configured to 72MHz. I have an obscure 3.34Mhz clock/data signal I'm trying to capture. I was wondering what the maximum sample rate of the digital input is. I seem to be getting many misreads. #stm322014-01-30 12:14 PM
I'd imagine 8-9 MHz should be achievable.
For maximum sampling consider if you can use DMA, certainly do-able on the F4'sIf you have the clock, or can generate one, consider slave mode SPI for single bit stream, or DCMI for 14-bit?2014-01-30 01:48 PM
Using timer capture to catch the edges, storing the timestamps using DMA?
If you can tell the nature of the signal to be captured, better ideas might come up maybe... JW2014-01-30 02:36 PM
(working together)
the signal is coming from a spartan 2 fpga, with a clock from a 13.56Mhz xtal, then divided down.the frame pulse (Start of message) is about 411khzthe clock is a 3.34Mhz and then 8 bits of data clocked in.this is the clock and data.(having issues with the media uploader)if we set a leading edge interrupt on the frame and toggle another gpio, it is rock solid and the signal matcheif we turn off interrupts and sit in a loop reading the pin and doing the same toggle, it misses about 30% of the timewe're using the stm32 lib, but i changed it to a simple loop that just inlines GPIO_ReadInputDataBit to the one IDR.if in the interrupt, we wait for the falling edge of clock, and the read data, it again misses..DMA was our next thought. Currently reading over the datasheets/examples to set this up.2014-01-30 03:45 PM
8-bits, but shifted serially, Ok wouldn't something like 16-bit SPI Slave mode work? You'd probably have to fish out your data, and re-sync it.
On the F4 you could do TIMx_CHx [TRIGGER] -> DMA2 [GPIO - > MEM], imagine similar method might work on F12014-01-31 06:16 AM
8-bits, but shifted serially, Ok wouldn't something like 16-bit SPI Slave mode work?
Sounds plausible. How long is frame start pulse? Would be perfect if it is high during whole data transmission. Is it? If so - then open collector as inverter on SPI NSS pin, SPI slave mode and you are done. Otherwise you need inverting latch with reset which is still doable. Wild idea - using two transistors and timer with external clock input.2014-02-02 04:09 AM
> if we set a leading edge interrupt on the frame and toggle another gpio, it is rock solid and the signal matche
> > if we turn off interrupts and sit in a loop reading the pin and doing the same toggle, it misses about 30% of the time You need to understand, that these 32-bitters are not microcontrollers built for tight timing control, and definitively not from software. Rather, these are SoC, stitched together from various modules, bound together quite loosely as far as timing goes, with the manufacturers not caring to document these relationships (which are admittedly complex, far beyond a simple description). Think of a traditional control board, built from a processor, memories, various IO ICs, held together with some glue logic - all integrated onto a single piece of silicon. What might happen at you is, that while interrupts have a fairly high latency, the interrupt signalling goes through a path separate from the data bus, i.e. its timing is independent from what happens on that bus, so that there are no conflicts on that bus which would alter the time until the interrupt servicing thus writing to the port happens. In other words, the latency is high, but jitter is low. This all given there is no jitter because of various timing of interrupted instructions (i.e. you run a null loop or similar), because of FLASH wait states/FLASH accellerator/jumpcache issues, other interrupts/DMA influence. In other words, your artificial test case might be unrepresenting of the real-program behaviour, unless you plan to have nothing else running in the mcu just that serial stream capturing. On the other hand, reading from the port in a loop involves traffic through the AHB/APB bus, where there are synchronisation delays depending on the relative state of the two buses at the moment of reading. That might possibly explain some jitter. It's hard to say more without seing the actual code. > we're using the stm32 lib, but i changed it to a simple loop that just inlines > GPIO_ReadInputDataBit to the one IDR. Oh, c'mon. If you want to go down to one-cycle timing level, C is not an option. > DMA was our next thought. Currently reading over the datasheets/examples to set this up. Yes, you want to avoid software as much as possible. OTOH, note, that DMA in itself is not panacea and has its sources of latency/jitter, too. While others suggested here ideas, I would repeat mine, to use some timer's capture and transfer the captured value using DMA. It's hard to be more specific without knowing more of your application. It appears, that the original clock is unavailable, that there is more than only one leading sync pulse and more than 8 bits of data, and that you have already allocated the input pin... ? JW2014-02-02 05:08 AM
Then again there's an FPGA, which offers additional options and flexibility. If the FPGA can deserialize the data, FSMC and the DCMI interface on F2/F4 would permit a parallel access method, which would significantly reduce the loading on the micro-processor, permitting it do other useful work, or processing.