Pages: [1]   Go Down
Author Topic: Due generating Synchronous PWM  (Read 1305 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi,

I am trying to generate two synchronous PWM (in channel 5, pin 8 and 44) by directly manipulating the registers, but there is no signal generated from pin 8 or 44. I think I strictly followed the instruction from the datasheet. Is there any mistake in my codes? Any help would be much appreciated.

Code:
void setup() {
  // put your setup code here, to run once:
  pinMode(8,OUTPUT);
  pinMode(44,OUTPUT);
  PWM->PWM_WPCR= 0x50574DFC;
  PWM->PWM_DIS=  0x000000FF;
  PWM->PWM_CLK=  0x00000001;
  PWM->PWM_CH_NUM[5].PWM_CMR= 0x00010000;  // period 84KHz
  PWM->PWM_CH_NUM[5].PWM_CPRD=0x00000C00;  // 1024 resolution
  PWM->PWM_CH_NUM[5].PWM_CDTY=0x00000600;  // start duty cycle is 0
  PWM->PWM_CH_NUM[5].PWM_DT  =0x00000000;  // dead time 5 (58ns)
  PWM->PWM_SCM  =0x00020020;  // synchronous mode 2 channel 5
  PWM->PWM_SCUP =0x00000000;  // minimum update period
  PWM->PWM_ENA  =0x00000020;

}

void loop() {
  // put your main code here, to run repeatedly:
 
}
Logged

Ottawa,Canada
Offline Offline
Jr. Member
**
Karma: 0
Posts: 82
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

it not really using syncronous channels as the data sheet states / you are just using both outputs of the same channel .. `
(i didnt need dead time .. but easy to add.. )

in anyevent  here is a chunk of code that sets up TWO seperate channels (two differnt duty cycles )
if you want to just use channel outputs 5H & 5L  rip out the "syncronous" stuff (channel 0 & channel 4)
(ALSO .. i didnt need dead time .. but easy to add.. )

Code:
void
PWM_setup ()
{
//PWM config
  pmc_enable_periph_clk (ID_PWM);

  PWMC_DisableChannel (PWM, PWM_CHANNEL_4);
  PWMC_DisableChannel (PWM, PWM_CHANNEL_5);
  PWMC_DisableChannel (PWM, PWM_CHANNEL_0);

  PWMC_ConfigureClocks (pwm_clk, 0, VARIANT_MCK);

  int ulPin = 8;
  // Setup PWM for this pin {theta1}
  PIO_Configure (g_APinDescription[ulPin].pPort,
g_APinDescription[ulPin].ulPinType,
g_APinDescription[ulPin].ulPin,
g_APinDescription[ulPin].ulPinConfiguration);
  ulPin = 9;
  // Setup PWM for this pin  {thetaRB}
  PIO_Configure (g_APinDescription[ulPin].pPort,
g_APinDescription[ulPin].ulPinType,
g_APinDescription[ulPin].ulPin,
g_APinDescription[ulPin].ulPinConfiguration);
  //**pin44        {theta2}
  PIO_Configure (g_APinC19RE_Description.pPort,
g_APinC19RE_Description.ulPinType,
g_APinC19RE_Description.ulPin,
g_APinC19RE_Description.ulPinConfiguration);

  PWMC_ConfigureSyncChannel (PWM,
     PWM_SCM_SYNC4 | PWM_SCM_SYNC5 | PWM_SCM_SYNC0
     , PWM_SCM_UPDM_MODE1, 0, 0);

  PWMC_SetPeriod (PWM, PWM_CHANNEL_4, pwm_period);
  PWMC_SetPeriod (PWM, PWM_CHANNEL_5, pwm_period);

  PWMC_ConfigureChannel (PWM, PWM_CHANNEL_4, PWM_CMR_CPRE_CLKA, 0,
PWM_CMR_CPOL);
  PWMC_SetDutyCycle (PWM, PWM_CHANNEL_4, pwm_dutyRS);
  PWMC_SetDutyCycle (PWM, PWM_CHANNEL_5, pwm_duty1);

  PWMC_SetPeriod (PWM, PWM_CHANNEL_0, pwm_period);
  PWMC_SetDutyCycle (PWM, PWM_CHANNEL_0, pwm_duty1);
  PWMC_ConfigureChannel (PWM, PWM_CHANNEL_0, PWM_CMR_CPRE_CLKA, 0, 0);

  PWM->PWM_OOV = PWM_OSSUPD_OSSUPH5;
  PWMC_SetSyncChannelUpdatePeriod (PWM, 1);


  PWMC_ConfigureComparisonUnit (PWM, PWM_CHANNEL_5, 1, 1);
  PWMC_ConfigureComparisonUnit (PWM, PWM_CHANNEL_4, 1, 1);
  PWMC_ConfigureEventLineMode (PWM, 0, PWM_ELMR_CSEL5 | PWM_ELMR_CSEL4);
  PWMC_SetSyncChannelUpdateUnlock (PWM);

  PWMC_EnableChannel (PWM, PWM_CHANNEL_0);
  PWMC_SetSyncChannelUpdateUnlock (PWM);
}
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thank you sooo much. It is working now! Very helpful!

Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 1
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Tom_Stark I think you just forget to activate the MCK in the PMC register. Anyone correct me if I'm wrong.

Thanks,

Daniel
Logged

Pages: [1]   Go Up
Jump to: