PDA

Archiv verlassen und diese Seite im Standarddesign anzeigen : ATXMEGA16A4 Pulse Width Capture



Che Guevara
17.02.2014, 19:48
Hi,

ich möchte per Input Capture an einem ATXMega16A4 den Duty-Cycle eines PWM-Signals (488Hz) messen. Nur irgendwie ist der Wert des CC Registers immer 0.
Der Timer wird konfiguriert wie folgt:
- Normal Mode
- CCC enabled
- Prescaler = 1

Verwendet wird Timer TCD0, das Signal liegt an PD.2 an (also CC C). Interrupts sind alle aktiviert, obwohl das hier sowieso keine Rolle spielen sollte?!
Die Routine:


void InitPwmInputTimer(void)
{
PwmInputPinConfig;

PORTD.PIN2CTRL = PORT_ISC_FALLING_gc;
EVSYS.CH0MUX = EVSYS_CHMUX_PORTD_PIN2_gc;

PwmInputTimer.CTRLA = 0x01; //Prescaler = 1
PwmInputTimer.CTRLB = 0x40; //CC C enabled , normal mode
PwmInputTimer.CTRLD = 0xC8; //Event = pulse width capture , EventSource = EVSYS_CH0
PwmInputTimer.PER = 0x7FFF;
}


Der Wert wird dann ausgegeben:


while(1)
{
ltoa((int32_t)TCD0_CCC,debug1,10);
SendPCUart(debug1,1);
WaitMs(500);
}


Der Rest des Programms funktioniert einwandfrei, nur eben dieser Teil nicht.
Hab ich was vergessen? Im DB konnte ich zumindest nichts finden, was mir weiterhelfen würde.

Vielen Dank & Gruß
Chris

Wsk8
17.02.2014, 20:35
Bei dir:

PORTD.PIN2CTRL = PORT_ISC_FALLING_gc;

Laut Datenblatt:

Pulse Width Capture
Selecting the pulse width measure event action makes the enabled compare channel perform the input capture action on
falling edge events and the restart action on rising edge events. The counter will then restart on positive edge events,
and the input capture will be performed on the negative edge event. The event source must be an I/O pin, and the sense configuration for the pin must be set to generate an event on both edges. Figure 14-13 on page 159 shows and example
where the pulse width is measured twice for an external signal.

mfg

Che Guevara
18.02.2014, 08:45
Hi,

danke für den Hinweis, habs korrigiert, jedoch besteht der Fehler weiterhin..
Leider hab ich im Netz bis jetzt nur Leute gefunden, die das gleiche Problem haben, aber noch ohne Lösung.

Gruß
Chris

EDIT:
Hab gerade den Fehler gefunden.
DB:


These bits select the event channel source for the timer/counter. For the selected event channel to have any effect, the
event action bits (EVACT) must be set according to Table 14-6 on page 166. When the event action is set to a capture
operation, the selected event channel n will be the event channel source for CC channel A, and event channel (n+1)%8,
(n+2)%8, and (n+3)%8 will be the event channel source for CC channel B, C, and D.

Die EVSEL Bits waren falsch gesetzt, weil ich das nicht gelesen hab.