Moin,
ich möchte 2 Motoren mit einem PWM Signal ansteuern welches von dem
kleinen Olimex HXXX Board mit dem At91-Sam7S 256 erzeugt wird.
Dazu braucht man bekanntlich 2 Signale pro Motor welche gegenläufig
sind. Bisher hab ich Probeweise ein Signal erzeugt, welches die Motoren
an - und wieder aus macht (Endlosschleife). Also es wird einfach
zwischen 2 festen Werten hin und her gewechselt im Sekundentakt.
Also: 1Sek an - 1 Sek aus -1Sek an usw.
Das funktioniert auch erst ganz gut, und dann wirds ziehmlich schnell
sonderbar. Die Motoren fangen an sich in die andere Richtung zu drehen,
stehen zu bleiben oder sich nur sehr langsam zu drehen.
Am Oszi kann ich sehen das das Signal sich ändert. Zum Beispiel den Duty
Cycle invertiert - also 2 geleiche Signale erzeugt usw.
Jemand sowas schonmal gemacht gemacht? Erlebt?
Hier ein wenig Code von mir:
1 | void InitPWM(void) {
|
2 | // Enable clock for interface
|
3 | AT91C_BASE_PMC->PMC_PCER = 1 << AT91C_ID_PWMC;
|
4 |
|
5 | // Set second functionality of pin
|
6 | AT91C_BASE_PIOA->PIO_PDR = AT91C_PA11_PWM0 |
|
7 | AT91C_PA12_PWM1 |
|
8 | AT91C_PA13_PWM2 |
|
9 | AT91C_PA14_PWM3 ;
|
10 |
|
11 |
|
12 |
|
13 | /*Select B Register */
|
14 | AT91C_BASE_PIOA->PIO_BSR = AT91C_PA11_PWM0 |
|
15 | AT91C_PA12_PWM1 |
|
16 | AT91C_PA13_PWM2 |
|
17 | AT91C_PA14_PWM3 ;
|
18 |
|
19 |
|
20 |
|
21 | // Enable clock for PWM
|
22 | AT91C_BASE_PWMC->PWMC_MR = 0x00010001;
|
23 |
|
24 | // Frequency for PWM
|
25 |
|
26 | // Period for PWM
|
27 | AT91C_BASE_PWMC_CH0->PWMC_CPRDR = 1023;
|
28 | AT91C_BASE_PWMC_CH1->PWMC_CPRDR = 1023;
|
29 | AT91C_BASE_PWMC_CH2->PWMC_CPRDR = 1023;
|
30 | AT91C_BASE_PWMC_CH3->PWMC_CPRDR = 1023;
|
31 | // Duty for PWM
|
32 | AT91C_BASE_PWMC_CH0->PWMC_CDTYR = 511;
|
33 | AT91C_BASE_PWMC_CH1->PWMC_CDTYR = 511;
|
34 | AT91C_BASE_PWMC_CH2->PWMC_CDTYR = 511;
|
35 | AT91C_BASE_PWMC_CH3->PWMC_CDTYR = 511;
|
36 |
|
37 | // Modify the period at the next period start event.
|
38 | AT91C_BASE_PWMC_CH0->PWMC_CMR = 0x0000;
|
39 | AT91C_BASE_PWMC_CH1->PWMC_CMR = 0x0200;
|
40 | AT91C_BASE_PWMC_CH2->PWMC_CMR = 0x0000;
|
41 | AT91C_BASE_PWMC_CH3->PWMC_CMR = 0x0200;
|
42 |
|
43 |
|
44 | // Enable PWM chanel
|
45 | AT91C_BASE_PWMC->PWMC_ENA = 0xF;
|
46 | }
|
Damit initialisiere ich das PWM Signal. In einer while setze ich dann
fortwährend:
1 | void setEngineOne(int val) {
|
2 | // set new value
|
3 | unsigned int pwm_val=(unsigned int)(511 + val);
|
4 | AT91C_BASE_PWMC_CH0->PWMC_CDTYR = pwm_val;
|
5 | AT91C_BASE_PWMC_CH1->PWMC_CDTYR = pwm_val;
|
6 |
|
7 | }
|
Bin ein wenig ratlos. Wäre subba wenn jemand ne Idee hat.
MFG
Kalle