while(1){ if(IT_tick){ IT_tick=0; } } /* END of WHILE */ //==================================================== The programm doesn´t enter never in main if. In debug mode in step by step mode, as soon as the ISR finishes, the program enters again. If it would works ok, it must enter in it. If i have
ADC_CR2.CONT=0 Continuous mode OFF
The programs enters once in the ISR and stop. It enters with out EOC flag(??) It works like it must to do. I tried to start ADC conversion on ISR then but i cant. How could do i that?ADC_SR.STRT=1 // Regular channel Start Flag
ADC_CR1.EOCIE=1 // Interrupt enable for EOC
ADC_CR1.SCAN=1 // Scan mode enabled
ADC_CR2.ADON=1 // A/D Converter ON ADC_CR2.EXTSEL=111 // External Event select for regular group = SWSTART ADC_CR2.EXTRIG=1 // Conversion on external event enabled In this moment NVIC registers are: See RM0008 (Vector table for connectivity line devices) ADC1_2 is position 18NVIC_ISR0.SETENA[18] = 1 // Interrupt ADC1_2 enabled NVIC_ICR0.CLRENA[18] = 1 // Interrupt ADC1_2 enabled. NVIC_IABR0.ACTIVE[18] = 1 // Interrupt ADC1_2 activedNVIC_ICPR0.CLRPEND[18] = 0 // Interrupt ADC1_2 no pending If i have
ADC_CR2.CONT=1 Continuous mode ON
The programs never leaves the ISR (Even step by step in debug mode). It never enters in main If. In normal mode I think it must do it. It enters with EOC flagADC_SR.STRT=1 // Regular channel Start Flag ADC_CR1.EOCIE=1 // Interrupt enable for EOC
ADC_CR1.SCAN=1 // Scan mode enabled
ADC_CR2.CONT=1 // Continuous mode
ADC_CR2.ADON=1 // A/D Converter ON
ADC_CR2.EXTSEL=111 // External Event select for regular group = SWSTARTADC_CR2.EXTRIG=1 // Conversion on external event enabled NVIC_ISR0.SETENA[18] = 1 // Interrupt ADC1_2 enabled NVIC_ICR0.CLRENA[18] = 1 // Interrupt ADC1_2 enabled. NVIC_IABR0.ACTIVE[18] = 1 // Interrupt ADC1_2 activedNVIC_ICPR0.CLRPEND[18] = 1 // Interrupt ADC1_2 pending I´ve tried to clear ADC_SR.EOC( I cant). I´ve tried to set NVIC_ICPR[0].CLRPEND[18]=1 to clear the ADC pending bit but I couldn´t.
If i have ADC_CR2.CONT=1:
I cant write on ADC_SR Register in any way of do it. ADC1->SR = 0x0000001D; ADC1->SR & = 0x0000001D; ADC1->SR &=~ 0x00000002;
It's still only 56 cycles but you should be able toquit isr and jump to main loop. Did you set a trap in main loop to check if itsreally not going into there?. Also try increasing conversion time tocheck if its not really I am to slow in ISR problem.
If you want behavior like in diagram above.
1.
Configure ADC to continuousmode off
2.
Start periodic 20kHz timer
3.
On timer update event start manually conversion ADC_RegularChannelConfig(ADC1,ADC_Channel_15, 1, ADC_SampleTime_1Cycles5);
4.
Wait for conversion by using EOC ISR
5.
When done (ISRevent) setup output compare registers to get desired pulses shape.
Now I see that beginning is just initial condition.
1.
Configure ADC to continuousmode off
2.
Start periodic 20kHz timer
3.
Setup compare registers to trigger interrupt close to end of timer periodand start adc conversion.
4.
On timer updateevent or EOC read analog value and do whatever you want with this probablysetup another compare register to get desired pulse shape.
Even more easy if you don’t need sampling in exactperiods of time. Run ADC in continuous mode forget about EOC flag and readvalue at the beginning of timer update event.
First scenario is also not time accurate too becauseyou need to fire up conversion. As for timers I know there can be made hardwaresynchronization and I bet ADC is able to be externally triggered read docs ifyou need this kind of accuracy.