Timer/counter operating Mode

OP #3176879
Lesenswert?
• ▲
▼
Hallo,

ich habe vor kurzem mit dem Programmieren von einem ATMEL AT32UC3C 
32Bits angefangen. Ich habe zur zeit ein Problem und komme nicht wieter. 
er wäre net wen einer helfen kann.

Hier ist meine .c Datei:
1
/*  
2
*
3
*Frequency measurement
4
*Speed measurement
5
*/
6
#include "compiler.h"
7
#include "tc.h"
8
#include "gpio.h"
9
#include "TimerCont.h"
10

11

12
//Initialization of the function exact_geschwindigkeit
13
void exact_geschwindigkeit_init() 
14
{   //brief Configuration functionality on a pin.
15
    
16

17
    //Parameters when initializing a counter in capture mode.
18
    tc_capture_opt_t capture_opt=
19
    {
20
       .channel = TIMER_CONTR_TC_CHANNEL,  // channel selection
21
       .ldra =1,                           // rising edge of TIOA
22
       .ldrb =2,                           // falling edge of TIOA
23
       .etrgedg =0,                         // external Trigger Edge Selection none
24
       .cpctrg =1,                         // RC Compare has no effect on the counter and its clock
25
       .tcclks =1,                         // clock Selection Timer_clok 1
26
       .abetrg =1,                         // TIOA is used as an external trigger
27
       .ldbdis =false,                     // Counter clock disable with RB loading
28
       .ldbstop = false,                   // Counter clock stopped with RB loading
29
    }  ;
30
    //Sets options for counter capture initialization.
31
    tc_init_capture(TIMER_CONTR_TC, &capture_opt);
32

33
    //Starts a counter.
34
    volatile avr32_tc_t *tc=TIMER_CONTR_TC;
35
    tc_start(TIMER_CONTR_TC, TIMER_CONTR_TC_CHANNEL);  
36
    //configuration input PIN
37
    static const gpio_map_t TC_GPIO_MAP =
38
    {
39
      {PIN_FOR_SPEED,AVR32_TC0_A2_3_FUNCTION }
40
      
41
    };
42
    gpio_enable_module(TC_GPIO_MAP, sizeof(TC_GPIO_MAP) / sizeof(TC_GPIO_MAP[0]));
43
}
44
//Function exact_geschwindigkeit
45
exact_geschwindigkeit (float *x,float *ges)
46
{   volatile avr32_tc_t *tc=TIMER_CONTR_TC;
47
   
48
  
49
    //initializing an array
50
    int tab[3]={0,0,0};
51
    //Writing in Register A and Register B
52
    tc_read_tc(TIMER_CONTR_TC,TIMER_CONTR_TC_CHANNEL);
53
    tc_write_ra(TIMER_CONTR_TC, TIMER_CONTR_TC_CHANNEL, tc_read_tc(TIMER_CONTR_TC,TIMER_CONTR_TC_CHANNEL));
54
    tc_write_rb(TIMER_CONTR_TC, TIMER_CONTR_TC_CHANNEL, tc_read_tc(TIMER_CONTR_TC,TIMER_CONTR_TC_CHANNEL));
55
    //filling the array
56
    tab[0]=tc_read_ra(TIMER_CONTR_TC,TIMER_CONTR_TC_CHANNEL);
57
    tab[1]=tc_read_rb(TIMER_CONTR_TC,TIMER_CONTR_TC_CHANNEL);
58
    float Ku=3.0f,Ui=10.0f;
59
    //restart the counter  
60
    //Speed calculation
61
    *ges=Ku*Ui*(tab[1]-tab[0])/(tab[2]-tab[0]);
62
    //reinitialization of the array 
63
    tab[2]=tab[0];
64
    *x=tc_read_tc(TIMER_CONTR_TC,TIMER_CONTR_TC_CHANNEL);
65
}

Hier meine .h DAtei:
1
/*
2
 *
3
 *TimerContr.h
4
 *
5
*/
6
#ifndef _TIMERCONTR_H_
7
#define _TIMERCONTR_H_
8
#define PIN_FOR_SPEED               AVR32_TC0_A2_3_PIN  
9
#define TIMER_CONTR_TC             (&AVR32_TC0)              //defines the counter
10
#define TIMER_CONTR_TC_CHANNEL     2                        //Defines the channel
11

12
extern void exact_geschwindigkeit_init(void) ;              //initialization of the function
13
extern void exact_geschwindigkeit (float *x,float *ges);    //speed calculation
14
#endif

Der Counter startet glaube ich gar nicht. In meiner Main Dater hier 
nicht dabei wird immer eine 0 für x angezeigt. Vieln dank.

Antwort schreiben

Hinweis: der ursprüngliche Beitrag ist mehr als 6 Monate alt. Bitte hier nur auf die ursprüngliche Frage antworten, für neue Fragen einen neuen Beitrag erstellen.

Formatierung
  • [c]C-Code[/c]
  • [code]Code in anderen Sprachen, ASCII-Zeichnungen[/code]
  • [math]Formel in LaTeX-Syntax[/math]
  • [[Titel]] – Link zu einem Artikel
  • Verweis auf einen anderen Beitrag: Rechtsklick auf dessen Beitrags-ID (#8078628), „Adresse kopieren“, in den Text einfügen

Mehr zur Formatierung

Längeren Sourcecode als Anhang, nicht in den Text. JPG nur für Fotos und Scans; Zeichnungen und Screenshots als PNG oder GIF. Siehe Bildformate.

Schon registriert? Anmelden

Wird nicht angezeigt. Wir schicken dir einen Link; sobald du damit bestätigst, erscheint dein Beitrag.

Mit dem Abschicken legst du einen kostenlosen Account an und erkennst die Nutzungsbedingungen und die Datenschutzerklärung an.