Archiv verlassen und diese Seite im Standarddesign anzeigen : XMega Punktschreibweise
guenter1604
01.04.2010, 23:29
Hallo,
für den ADC-Empfang möchte ich eine Funktion schreiben:
static uint16_t get_adcb(uint8_t channel)
{
	ADCB.CH1.CTRL |= 0x80;
	while(!(ADCB.CH1.INTFLAGS && 0x01)); 
	return ADCB.CH1.RES;
	ADCB.CH1.INTFLAGS = 0x01;
}
mit channel soll der ADC-Kanal übergeben werden. Wie setzte ich den channel statt CH1 "hübsch" ein?
Günter
Du musst gucken, wie "ADCB" (u. ADCA)  in den  xmega*.h  files deklariert sind. 
Sollte ja eigentlich irgendwie eine "struct" sein, die auf ADCA u. ADCB angewendet wird. (so wie das da aussieht)
Und die übergibst du der Sub  als Pointer , z.B
       CallSub ( (struct ADC*)&ADCA);
       CallSub ( (struct ADC*)&ADCB);
static uint16-t  CallSub (struct ADC* pChann)
{
   pChann->CH1.CTRL |= 0x80; 
etc..
guenter1604
02.04.2010, 12:55
Controller */
#define ADCA    (*(ADC_t *) 0x0200)  /* Analog to Digital Converter A */
#define ADCB    (*(ADC_t *) 0x0240)  /* Analog to Digital Converter B */
Diese Stelle in iox128a1.d habe ich gefunden
Günter
guenter1604
02.04.2010, 13:16
Jetzt habe ich einfach mal &ADCB.CH1 in meinen Code eingetragen und die Fehlermeldung erhalten:
../xmega.c:15: warning: format '%i' expects type 'int', but argument 2 has type 'struct ADC_CH_t *'
guenter1604
02.04.2010, 13:32
So  !?!
static uint16_t get_adc( struct ADC_t* pChan){
pChan->CTRL |= 0x80;
   while(!(pChan->INTFLAGS && 0x01));
   return pChan->RES;
   pChan->INTFLAGS = 0x01;
}
Naja, frag mal den Compiler
Btw:
   while(!(pChan->INTFLAGS && 0x01));      // && ist logisch UND
   return pChan->RES; 
   pChan->INTFLAGS = 0x01;   // nach "return" kommt der da nichtmehr dahin
ist suboptimal. 
Sollte wohl heissen:
   while(!(pChan->INTFLAGS & 0x01));   // & statt &&
   pChan->INTFLAGS = 0x01;               
   return pChan->RES;                        // return als letztes
guenter1604
02.04.2010, 18:59
Wie man sich an einem Feiertag nur so wüst verrennen kann ;-)
Die ADC Channels beim XMega haben nichts mit den PINs zu tun. Diese muß man im Muxregister erst zuweisen. Dann klapps auch mit der Funktion:
static uint16_t get_adcb(uint8_t adc_pin){
	ADCB.CH0.MUXCTRL = 7 + adc_pin;
	ADCB.CH0.CTRL |= 0x80;
   	while(!(ADCB.CH0.INTFLAGS & 0x01));
   	ADCB.CH0.INTFLAGS = 0x01;
	return ADCB.CH0.RES;
}
Aufruf:
wert = get_adcb(3);
holt dann den Wert vom Pin ADC3 ab.
Danke für deine Unterstützung Robert!
Günter
 
Powered by vBulletin® Version 4.2.5 Copyright ©2025 Adduco Digital e.K. und vBulletin Solutions, Inc. Alle Rechte vorbehalten.