AT91SAM3X8E und PWM

Gast #5615792
Lesenswert?

Hallo miteinander,

ich möchte ein PWM mit dem AT91SAM3X8E (auf dem Arduino Due) erzeugen, 
aber komme momentan nicht weiter. Ich verwende den Pin PB16 (Arduino 
Due: DAC1), also PWML0.
1
//Clock Register -> CLKA, CLKB = MCK
2
REG_PWM_CLK |= (1<<0) | (1<<16);
3
//Enable PWM Channel 0
4
REG_PWM_ENA |= (1<<0);
5
//Comparison Value
6
REG_PWM_CMPV0 |= (1<<12);
Gast #5615933
Lesenswert?

Lothar M. schrieb:
> hol schrieb:
>> ich möchte ein PWM mit dem AT91SAM3X8E (auf dem Arduino Due) erzeugen,
>> aber komme momentan nicht weiter.
> Wie weit bist du denn schon? Hast du die LED aus dem
> Beitrag "Arduino Due: LED ein- und ausschalten" schon unter Kontrolle?

Ja, das klappt nun. Bin auch beim PWM weitergekommen.
Ich weiß aber noch nicht, wie ich die PWM Clock aktiviere und ob mir 
sonst noch was fehlt
1
 
2
//Enable PIO control
3
REG_PIOB_PER |= (1<<16);
4
//Select Peripheral B function
5
REG_PIOB_ABSR |= (1<<16);
6
  
7
//Enable PWM Clock
8
  
9
  
10
//Clock Register -> CLKA, CLKB = MCK
11
REG_PWM_CLK |= (1<<0) | (1<<16);
12
//Enable PWM Channel 0
13
REG_PWM_ENA |= (1<<0);
14
//Comparison Value
15
REG_PWM_CMPV0 |= (1<<12);
Gast #5620906
Lesenswert?

Hallo zusammen,

ich habe ein Beispiel auf der fogenden Seite gefunden:
http://forum.arduino.cc/index.php?topic=420674.0

Dieses habe ich im AtmelStudio getestet und ein PWM an Pin PC7 messen 
können.
Allerdings erhalte ich nicht eine Frequenz von 1 Hz, sondern von 2,7 Hz.

Habt ihr eine Idee, woran das liegt. Bei diesem Controller kann ich 
unter Tools > Device Programming > Fuse Bits ja nicht die Taktquelle 
verändern (wie beim Atmega2560).
1
 
2
  // PWM Set-up on pin PC7 (Arduino Pin 39): see Datasheet chap. 38.5.1
3
  // Select Instance=PWM; Signal=PWMH2 (channel 2); I/O Line=PC7 (P7, Arduino pine 39, see pinout diagram) ; Peripheral=B
4

5
  PMC->PMC_PCER1 |= PMC_PCER1_PID36;                   // PWM on
6

7
  REG_PIOC_ABSR |= PIO_ABSR_P7;                        // Set PWM pin perhipheral type B
8

9
  REG_PIOC_PDR |= PIO_PDR_P7;                          // Set PWM pin to an output
10

11
  REG_PWM_ENA = PWM_ENA_CHID2;                         // Enable the PWM channel 2 (see datasheet page 973) 
12
 
13
  REG_PWM_CLK = PWM_CLK_PREA(0) | PWM_CLK_DIVA(42);    // Set the PWM clock rate to 2MHz (84MHz/42). Adjust DIVA for the resolution you are looking for
14
                                                      
15
  REG_PWM_CMR2 = PWM_CMR_CALG |PWM_CMR_CPRE_CLKA;      // The period is left aligned, clock source as CLKA on channel 2
16

17
  REG_PWM_CPRD2 = 1000000;                             // Channel 2 : Set the PWM frequency 2MHz/(2 * CPRD) = F ; 1< CPRD < 2exp24  -1 ; here CPRD = 10 exp 6
18

19
  REG_PWM_CDTY2 = 200000;                              // Channel 2: Set the PWM duty cycle to x%= (CDTY/ CPRD)  * 100 % , CDTY = 2 * 10 exp 5
20

21
 // Alternatively, you can use this format :  PWM->PWM_CH_NUM[2].PWM_CPRD = 1000000 ;                    
22
 // In this example, Frequency is 1 HZ with a DT of 20% so you can see it with an LED attached to pin 39 with a resistor  
23
 
24
}

Antwort schreiben

Bitte melde dich an, um einen Beitrag zu schreiben.

oder

Mit Google-Account einloggen

Die Registrierung ist kostenlos und dauert nur eine Minute.

Jetzt registrieren