2013-04-24 02:19 AM
Hi,
I'm looking to sample a signal (well, 2 actually - quadrature analog signals) at a fixed sample rate, but I'm baffled by the lack of any example in the Standard Peripheral Library on how to achieve this.I would have thought that this would be a pretty standard example, i.e sample x points of a signal at y kHz and store result in memory location z.Can anyone from ST comment on why such a basic (and imo fundamental) example is missing from the Standard Peripheral Library?Does anybody else have an basic example of how this is achieved? There are various incomplete snippets of code if you search in this forum, but elsewhere on the internet I've been able to find zilch.I suspect I'm going to have to go read the manual in depth to figure this lot out...oh joy!Many thanks.Adrian2015-03-06 10:16 PM
/* need to call this function in DMA2_Stream0_IRQHandler in */
void TM_ADC_DMA_IRQHandler(void) { _INT iAdcTemp = 0; _US i = 0; _UC ucBuff[512] = {0}; //record the interrupt time gusTimer++;if(DMA_GetITStatus(DMA2_Stream0, DMA_IT_TCIF0))
{ gucPosition+=10; TM_ILI9341_Puts(10, gucPosition, ''------------interrupt-----------'', &TM_Font_7x10, ILI9341_COLOR_BLACK, ILI9341_COLOR_ORANGE); if (TM_USB_VCP_GetStatus() == TM_USB_VCP_CONNECTED) { gucPosition+=10; //TM_ILI9341_Puts(10, gucPosition, ''------------2)usb is good-----------'', &TM_Font_7x10, ILI9341_COLOR_BLACK, ILI9341_COLOR_ORANGE); VCP_DataTx(ucBuff, 512);};
}
/* Clear DMA Stream Transfer Complete interrupt pending bit */ DMA_ClearITPendingBit(DMA2_Stream0, DMA_IT_TCIF0); } But if I don't use the debugger and delete all the breakpoint. Only used the LCD for output. There is no information output for statement. ''TM_ILI9341_Puts(10, gucPosition, ''------------interrupt-----------'', &TM_Font_7x10, ILI9341_COLOR_BLACK, ILI9341_COLOR_ORANGE); ''2015-03-06 10:25 PM
My device is discovery F429. The project is use STM32 for AD high speed sampling only use one channel by TIM/DMA/ADC. And I transfer the data to PC by USB.
The VCP of USB for test is OK and can reach 500KB/s. int main(void) { /* System Init */ SystemInit(); /* init for LCD */ TM_ILI9341_Init(); //Rotate LCD for 90 degrees TM_ILI9341_Rotate(TM_ILI9341_Orientation_Landscape_1); //FIll lcd with color TM_ILI9341_Fill(ILI9341_COLOR_MAGENTA); //Put string with black foreground color and red background with 11x18px font gucPosition+=4; TM_ILI9341_Puts(4, gucPosition, ''LCD Init'', &TM_Font_7x10, ILI9341_COLOR_BLACK, ILI9341_COLOR_ORANGE); /* Initialize ADC1 on channel 0, this is pin PA0 */ TM_ADC_Init(ADC1, ADC_Channel_0); /* Initialize USB VCP */ TM_USB_VCP_Init(); while (1) { } }2015-03-06 11:37 PM
2015-03-06 11:39 PM
I modified the code based on yours and Tilen Majerle's. For I will used the ADC and the VCP of USB at the same time.
2015-03-07 04:03 AM
I modified the code based on yours and Tilen Majerle's. For I will used the ADC and the VCP of USB at the same time.
Yeah, not looking very familiar, maybe you should have started a new thread? You seem to be doing an awful lot of processing in the interrupt for the rate you're pulling in samples, and waiting on other interrupts. If you still don't see DMA TC interrupts, then you need to walk back up the dependency list. No DMA Interrupt, check that the DMA is occurring, check that the ADC is firing, check that the TIM is ticking, etc. Lot of code that's not mine, using libraries I'm not using, looks to be hours of fun.2015-03-07 07:10 AM
Maybe you are right. The Interrupt is the problem source.
I will try to find it.2015-04-11 02:09 AM
2015-04-11 02:34 AM
2015-04-11 02:43 AM
But I still have a question. If I want to get the ADC data from buffer ADCOneConvertedValues[DMA_BUFFER] and send to computer by USB, how can I add code in this fuction?
void TM_ADC_DMA_IRQHandler(void) { if(DMA_GetITStatus(DMA2_Stream0, DMA_IT_HTIF0)) { TM_DISCO_LedOff(LED_GREEN); // HalfTransferInterruptComplete Interrupt von DMA2 ist aufgetreten DMA_ClearITPendingBit(DMA2_Stream0, DMA_IT_HTIF0);} else if(DMA_GetITStatus(DMA2_Stream0, DMA_IT_TCIF0)) { TM_DISCO_LedOn(LED_GREEN); // TransferInterruptComplete Interrupt von DMA2 ist aufgetreten DMA_ClearITPendingBit(DMA2_Stream0, DMA_IT_TCIF0); } }
2015-08-30 05:53 AM
Hi clive1. In your example the ADC conversion is completing at frequency 2KHz. i.e:
but you are triggering timer at 200KHz. Please help me understanding this logic. Thanks.