I am having difficulty connecting a servo to my SAM7-P256 from Olimex.
Here is my code:
pPWMC->PWMC_DIS = AT91C_PWMC_CHID0 | AT91C_PWMC_CHID1 | AT91C_PWMC_CHID2 | AT91C_PWMC_CHID3;
pPWMC->PWMC_MR = ((10 << 8 ) | 0x01 ); // MCK selection or'ed with Divider
pwm->PWMC_CMR=
// AT91C_PWMC_CPRE_MCK | // Divider Clock ?
AT91C_PWMC_CPRE_MCKA | // Divider Clock A
// AT91C_PWMC_CPRE_MCKB | // Divider Clock B
AT91C_PWMC_CPD | // Channel Update Period
// AT91C_PWMC_CPOL | // Channel Polarity Invert
// AT91C_PWMC_CALG | // Channel Alignment Center
0x0;
// Set the Period register (sample size bit fied )
pwm->PWMC_CPRDR=938;
// Set the duty cycle register (output value)
pwm->PWMC_CDTYR=70;
// Initialise the Update register write only
pwm->PWMC_CUPDR=0;
AT91C_BASE_PWMC->PWMC_ENA=1;
...pause for a while...
AT91C_BASE_PWMC->PWMC_CH[0].PWMC_CUPDR=100;
...pause for a while...
AT91C_BASE_PWMC->PWMC_CH[0].PWMC_CUPDR=70;
I cant seem to figure out the calculation for period (I want 20ms) and duty cycle (I want 1.5ms). The board is running at ~48MHz from what all the examples I have looked at seem to say. Does anyone have an easy way to figure out what dividers/prescalers I need and then what period and duty cycle to set?
The servo reacts differently when I try different values (although it always ends up pegging to the right) so I think I have everything initialized correctly.
This is my first foray into embedded/microcontroller programming, but I do have plenty of experience in C elsewhere.
Thanks,
Joe