How to correctly synchronize timer with ADC
Hello everyone,
I have problem with my univeristy project and I'm trying to find some help.
I'm using Nucleo64 STM32F411RE.
The most important setting in CubeMX:



In ADC every rank have 3 cycles, and Rank 1-4 Channel 10, Rank 5-8 Channel 11, Rank 9-12 Channel 12, Rank 13-16 Channel 14
My code:
Global Variables:
#define length 32768
uint16_t reciver[length];
union u_type
{
uint16_t prepare[(length/4)];
uint8_t sender[(length/2)];
} temp;
uint16_t where1, where2;
//uint8_t sender[(length/8)];
int taskcounter1 = 0;
int taskcounter2 = 0;
int taskcounter3 = 0;int main():
int main(void)
{
HAL_Init();
SystemClock_Config();
MX_GPIO_Init();
MX_DMA_Init();
MX_ADC1_Init();
MX_TIM3_Init();
/* Create the semaphores(s) */
/* definition and creation of myBinarySem01 */
osSemaphoreDef(myBinarySem01);
myBinarySem01Handle = osSemaphoreCreate(osSemaphore(myBinarySem01), 1);
/* definition and creation of myBinarySem02 */
osSemaphoreDef(myBinarySem02);
myBinarySem02Handle = osSemaphoreCreate(osSemaphore(myBinarySem02), 1);
xSemaphoreTake( myBinarySem01Handle, ( TickType_t ) 10 );
xSemaphoreTake( myBinarySem02Handle, ( TickType_t ) 10 );
/* definition and creation of recivedTask */
osThreadDef(recivedTask, StartADCTask, osPriorityNormal, 0, 128);
recivedTaskHandle = osThreadCreate(osThread(recivedTask), NULL);
/* definition and creation of prepareTask */
osThreadDef(prepareTask, StartPrepareTask, osPriorityNormal, 0, 128);
prepareTaskHandle = osThreadCreate(osThread(prepareTask), NULL);
/* definition and creation of sendTask */
osThreadDef(sendTask, StartSendTask, osPriorityNormal, 0, 128);
sendTaskHandle = osThreadCreate(osThread(sendTask), NULL);
osKernelStart();
while (1) {}
}My Reciver Task:
void StartADCTask(void const * argument)
{
for(;;)
{
HAL_ADC_Start_DMA( &hadc1, reciver, length);
HAL_TIM_Base_Start_IT( &htim3 );
}
}Don't worry about another two Task, they work correctly. Logic is that:
1.
a) Recive first interrupt when signals recived from ADC feel reciver[32768] tab in half
b) When interrupt is recived it should free myBinarySem01Handle, but in the same time reciving data from ADC still works
c) Recive secondinterrupt when signals recived from ADC feel reciver[32768] tab in full
d) When interrupt is recived it should free myBinarySem01Handle, but in the same time reciving data from ADC still works
2. Repeat step 1. 12 times in second
3. This should never stop
I have problem only with that:
- How to set up prescaler and counter period for Timer corectly for this scenario?
- How to catch interrupt on half and full tab feel?
Everything else in the project (recalulating recived data, sending it via USB, etc) is done.
I tried to find something in documentation, in The Internet, but without any resoults...
You are my last hope. Can someone help me and explain how it works for future?
Thanks a lot and Best regards,
Bartlomiej