Forum: Compiler & IDEs AT91SAM7A3 PWM Signal


von -- -. (crolib)


Lesenswert?

Hallo Leute,

ich hoffe jemand kann mir bei der Fehlersuche helfen...
ich habe ein Sam7a3 Board und wollte auf PB16 und PB18 ein PWM
Signal ausgeben.
Leider kommt bei mir nur bei PB16 ein High-Signal heraus und
auf dem PB14 ist kein Signal ...
Hier ist mein Code:
1
#include "Board.h"
2
3
  //Variablendeklaration
4
AT91PS_PIO pPIO;
5
AT91PS_PWMC pPWM;
6
AT91PS_CKGR pCKGR;
7
AT91PS_PMC pPMC;
8
AT91PS_ADC pADC;
9
AT91PS_TC  pTC;
10
11
unsigned int PIO_Enable= 0x1554000;
12
unsigned int PIO_OER= 0x14000;
13
unsigned int PIO_ODR= 0x1540000;
14
unsigned int CID_L= 0x1;
15
unsigned int CID_G= 0x4;
16
unsigned int mode_pwm= 0x200;
17
unsigned int mode_pmc= 0x1;
18
unsigned int period= 0x56E10;
19
unsigned int duty_L= 0x6780;
20
unsigned int duty_G= 0x68F0;
21
unsigned int null= 0x0;
22
unsigned int mode_MCK= 0x1;
23
unsigned int mode_ADC= 0x100;
24
25
26
27
int main()
28
{
29
  //Initialisierung von PORTB
30
  AT91F_PIO_CfgPeriph(pPIO, null , PIO_Enable);
31
  AT91F_PIO_CfgOutput(pPIO,PIO_OER);
32
  AT91F_PIO_CfgInput(pPIO, PIO_ODR);
33
  AT91F_PIO_CfgPullup(pPIO, PIO_OER);
34
35
  //Initialisierung von PWM
36
  AT91F_PWMC_StopChannel(pPWM, 0x5);
37
  pPWM->PWMC_MR=  0x10000;
38
  AT91F_PWMC_CfgChannel(pPWM, CID_L, mode_pwm, period, duty_L);
39
  AT91F_PWMC_CfgChannel(pPWM, CID_G, mode_pwm, period, duty_G);
40
  AT91F_PWMC_StartChannel(pPWM, 0x5);
41
42
  //Initialisierung von ADC
43
  //AT91F_ADC_CfgModeReg(pADC, mode_ADC);
44
45
  //Gas Geben
46
  //duty_G= 0x7148;
47
  //AT91F_PWMC_UpdateChannel(pPWM, CID_G, duty_G);
48
49
50
  return 0;
51
}

Könnte jemand von euch bitte mal drüber schauen und mir sagen wo
das Problem liegt!?
Vielen Dank im voraus!!

MFG
crolib

von Karl (Gast)


Lesenswert?

Takt für Peripherie eingeschaltet?

von -- -. (crolib)


Lesenswert?

Erstmal Danke für deine Antwort!!

Meinst du mit Takt den Master (MCK) Clock?
falls ja, der wurde von uns schon in einer Datei initialisiert.
1
// The following functions must be write in ARM mode this function called directly
2
// by exception vector
3
extern void AT91F_Spurious_handler(void);
4
extern void AT91F_Default_IRQ_handler(void);
5
extern void AT91F_Default_FIQ_handler(void);
6
7
//*----------------------------------------------------------------------------
8
//* \fn    AT91F_LowLevelInit
9
//* \brief This function performs very low level HW initialization
10
//*        this function can be use a Stack, depending the compilation
11
//*        optimization mode
12
//*----------------------------------------------------------------------------
13
void AT91F_LowLevelInit( void) @ "ICODE"
14
{
15
 int            i;
16
 AT91PS_PMC     pPMC = AT91C_BASE_PMC;
17
    //* Set Flash Waite sate
18
  //  Single Cycle Access at Up to 30 MHz, or 40
19
  //  if MCK = 47923200 I have 50 Cycle for 1 usecond ( flied MC_FMR->FMCN
20
      AT91C_BASE_MC->MC_FMR = ((AT91C_MC_FMCN)&(48 <<16)) | AT91C_MC_FWS_1FWS ;
21
22
    //* Watchdog Disable
23
        AT91C_BASE_WDTC->WDTC_WDMR= AT91C_WDTC_WDDIS;
24
25
  //* Set MCK at 47 923 200
26
    // 1 Enabling the Main Oscillator:
27
        // SCK = 1/32768 = 30.51 uSecond
28
      // Start up time = 8 * 6 / SCK = 56 * 30.51 = 1,46484375 ms
29
       pPMC->PMC_MOR = (( AT91C_CKGR_OSCOUNT & (0x0 <<8) | AT91C_CKGR_MOSCEN ));
30
        // Wait the startup time
31
        while(!(pPMC->PMC_SR & AT91C_PMC_MOSCS));
32
  // 2 Checking the Main Oscillator Frequency (Optional)
33
  // 3 Setting PLL and divider:
34
    // - div by 5 Fin = 3,6864 =(18,432 / 5)
35
    // - Mul 25+1: Fout =  95,8464 =(3,6864 *26)
36
    // for 96 MHz the erroe is 0.16%
37
    // Field out NOT USED = 0
38
    // PLLCOUNT pll startup time estimate at : 0.844 ms
39
    // PLLCOUNT 28 = 0.000844 /(1/32768)
40
       pPMC->PMC_PLLR = ((AT91C_CKGR_DIV & 0x01) |
41
                         (AT91C_CKGR_PLLCOUNT & (28<<8)) |
42
                         (AT91C_CKGR_MUL & (25<<16)));
43
44
        // Wait the startup time
45
        while(!(pPMC->PMC_SR & AT91C_PMC_LOCK));
46
        while(!(pPMC->PMC_SR & AT91C_PMC_MCKRDY));
47
   // 4. Selection of Master Clock and Processor Clock
48
   // select the PLL clock divided by 2
49
       pPMC->PMC_MCKR =  AT91C_PMC_PRES_CLK ;
50
       while(!(pPMC->PMC_SR & AT91C_PMC_MCKRDY));
51
52
       pPMC->PMC_MCKR |= AT91C_PMC_CSS_MAIN_CLK ;
53
       while(!(pPMC->PMC_SR & AT91C_PMC_MCKRDY));
54
55
  // Set up the default interrupts handler vectors
56
  AT91C_BASE_AIC->AIC_SVR[0] = (int) AT91F_Default_FIQ_handler ;
57
  for (i=1;i < 31; i++)
58
  {
59
      AT91C_BASE_AIC->AIC_SVR[i] = (int) AT91F_Default_IRQ_handler ;
60
  }
61
  AT91C_BASE_AIC->AIC_SPU  = (int) AT91F_Spurious_handler ;
62
63
}

Sollte das nicht der Takt sein, dann sag mir bitte welchen du meinst.
Danke im voraus!

MFG
crolib

von Karl (Gast)


Lesenswert?

Nein, ich meine nicht den MC, sondern den Takt für die Peripherie. Die 
AT91 versorgen nach einem Reset ihre Peripherie nicht mit einem Takt um 
Strom zu sparen. Folglich musst du den Takt für die entsprechende 
Peripherie aktivieren, wenn du sie verwenden willst. Dazu steht einiges 
im Datenblatt. Es existieren in der AT91 Bibliothek auch Funktionen 
dafür.

von -- -. (crolib)


Lesenswert?

Ich habe nur noch einen einzigen Takt gefunden der es sein Könnte und 
das ist der PIT. Ist es der den du meinst?
Falls nicht dann sag mir bitte welcher das ist und wie er genau heißt. 
Würde mir echt sehr weiterhelfen.

Danke im voraus

Gruß

Crolib

von Karl (Gast)


Lesenswert?

Mann, Mann, Mann. Wenn du mit µC etwas Erfolg haben willst, sollte das 
schon alleine gehen. Steht definitiv alles im Datenblatt. Ich bin 
selbst schon wieder eine ganze weile raus aus den AT91. Normalerweise 
hast du nur ein banales "Lies gefälligst das Datenblatt" verdient. Na 
gut, machen wir mal eine Ausnahme. Datenblatt runterlad

38,7 Sekunden später:
S. 156 24.5
S. 168 24.9.4
S. 29  11.
S. 392 32.4.2
S. 393: "Caution: Before using the PWM macrocell, the programmer must 
first enable the PWM clock in the Power Management Controller (PMC)."

Mehr gibts nicht von mir. Ich ärgere mich sowieso fast schon wieder über 
mangelnde Eigeninitiative, deshalb nochmal: Lies das verdammte 
Datenblatt, ohne gehts nicht.

Bitte melde dich an um einen Beitrag zu schreiben. Anmeldung ist kostenlos und dauert nur eine Minute.
Bestehender Account
Schon ein Account bei Google/GoogleMail? Keine Anmeldung erforderlich!
Mit Google-Account einloggen
Noch kein Account? Hier anmelden.