Re: Záhada v C

Miroslav Mraz mrazik na volny.cz
Sobota Leden 23 21:21:51 CET 2021


ISR (ADC0_RESRDY_vect) { // 37,1 kHz / 16 ======

         if (adSync) return; // nejaky problem zpracovani

.              static uint8_t     ind=0;
.

.              //adDataRaw[ind]=(uint32_t)ADC0_RES;

.              adDataRaw[ind]=(uint32_t)ind;

.

.              if (++ind>=AD_chCount) ind=0;

.              ADC0_MUXPOS=AD_chFirst+ind;

.

.              adSync=1;

.              ADC0_INTFLAGS=1;

}

Ve funkci cekej je mj. (i je lokální int):

if (adSync==1) { // -------------------------

.              for (i=0; i<AD_chCount; i++) adData[i]=adDataRaw[i];
.
.              adSync=0;   // az zde

}

adSync by mělo být něco jako C ekvivalent std::atomic, nechce se mi to 
hledat.

Mrazík


Dne 23. 01. 21 v 20:14 Pavel Hudecek napsal(a):
> Dobrý den všem,
> 
> ATtiny816, Atmel Studio
> 
> volatile uint32_t               adDataRaw[AD_chCount];
> 
> uint32_t                              adData[AD_chCount];
> 
> ISR (ADC0_RESRDY_vect) { // 37,1 kHz / 16 ======
> 
> .              static uint8_t     ind=0;
> 
> .
> 
> .              //adDataRaw[ind]=(uint32_t)ADC0_RES;
> 
> . *adDataRaw[ind]=(uint32_t)ind;*
> 
> .
> 
> . *if (++ind>=AD_chCount) ind=0;*
> 
> .              ADC0_MUXPOS=AD_chFirst+ind;
> 
> .
> 
> .              adSync=1;
> 
> .              ADC0_INTFLAGS=1;
> 
> }
> 
> Ve funkci cekej je mj. (i je lokální int):
> 
> if (adSync==1) { // -------------------------
> 
> .              adSync=0;
> 
> .
> 
> . *for (i=0; i<AD_chCount; i++) adData[i]=adDataRaw[i];*
> 
> }
> 
> V mainu je while(1) a tam mj. (n je lokální uint32_t):
> 
> cekej(1000);
> 
> for (n=0; n<AD_chCount; n++) {
> 
> .              cislo((uint32_t)adData[n]); text("/");
> 
> .              cislo((uint32_t)adDataRaw[n]); text(" ");
> 
> }
> 
> UART_crlf;
> 
> A z terminálu leze:
> 
> 5/5 6/1 2/2 3/3 4/4 0/5 1/6
> 
> 5/5 6/1 2/2 3/3 4/4 0/5 1/6
> 
> 0/5 6/1 2/2 3/3 4/4 0/5 1/6
> 
> 5/5 1/1 2/2 3/3 4/4 0/5 1/6
> 
> Proč z terminálu neleze
> 
> 0/0 1/1 2/2 3/3 4/4 5/5 6/6
> 
> ???
> 
> Díky,
> 
> PH
> 
> 
> _______________________________________________
> HW-list mailing list  -  sponsored by www.HW.cz
> Hw-list na list.hw.cz
> http://list.hw.cz/mailman/listinfo/hw-list
> 


Další informace o konferenci Hw-list