// CLIP-Dekoder mit unipolarem A/D-Wandler
#include <avr/io.h>
.extern clipdat
/*
struct CLIPDAT{
word mean; // Gleitender Mittelwert (Hi/Lo)
byte diff;
byte last;
union{
word akk16;
struct{
byte akku
byte det
};
};
byte cnt;
byte stat;
};
*/
.extern isrend
.global clip_adc
// Verfügbare Zeit: 16 × 13 = 208 Takte
// CPU-Frequenz = 2 MHz
clip_adc:
ldi YH,hi8(clipdat)
ldi YL,lo8(clipdat)
in r22,ADCH
// Gleitenden Mittelwert bilden (durchgehend)
clr r1
mov r23,r22
ldd r0,Y+0
ldd ZH,Y+1
sub r23,ZH
add r0,r23
adc ZH,r1
std Y+1,ZH
std Y+0,r0
// Phasen
ldd ZL,Y+7 // stat
cpi ZL,1
brcc 1f
// Phase 0: Initialisierung
std Y+0,r1
std Y+1,r22
std Y+4,r1
std Y+5,r1
std Y+6,r1
rjmp incstat
// Phase 1: Gleichspannungswert finden (256 Zyklen, 3 ms)
1: brne 2f
ldd r0,Y+6
inc r0
std Y+6,r0
breq incstat
rjmp isrend
// Phase 2: Präambel finden (Mindestamplitude)
2: cpi ZL,3
brcc 3f
3:
incstat:
inc ZL
std Y+7,ZL
rjmp isrend
| Detected encoding: UTF-8 | 0
|