AnsweredAssumed Answered

ADuC7126 PWM Demo code doesn't work correctly

Question asked by Guanhan on Nov 29, 2017

Hi everyone
I assign the single channel PWM.

But I found the PWM didn't work  when I try to config the PWM to use the P2.1.

Here are the code that I assign:


  

int main(void)
{

#define GPIO_PIN1_PINFNUC_SELECT01  (0x00000010)

#define GPIO_Pin1_IOState       0x020000

#define GPIO_Pin1_Outputmode    (0x02000000)

#define PWM_PWMEN                               (0x0001)

#define PWM_CLOCK_PRESCALER_UCLKDIV256          (0x01C0)

#define PWM_TRIP_Interrupt_EN                   (0x0400)

 

 

GP2CON =    (  GPIO_PIN1_PINFNUC_SELECT01 );
GP2DAT =     (  GPIO_Pin1_IOState | GPIO_Pin1_Outputmode );

PWMCON0 = ( PWM_PWMEN | PWM_CLOCK_PRESCALER_UCLKDIV256 | PWM_TRIP_Interrupt_EN);

 while (1)
  {   

       if(PWM_Interrupt_State)
       {
           PWM0COM0 = 0x08;          //high
           PWM0COM1 = 0x64;          //low
           PWM0COM2 = 0x01;          //high
           PWM0LEN  = 0x64;          //low
           PWM_Interrupt_State = false;
       }

   }

}

 

void IRQ_Handler(void) __irq
{

#define Interrupt_PWM_Trip                   (0x2000000)
 unsigned long IRQSTATUS = 0; 

   IRQSTATUS = IRQSTA;

   if((IRQSTATUS & Interrupt_PWM_Trip) !=0)
    {
        PWMCLRI = 0xFF;     // Clear the PWM trip interrupt source
        PWM_Interrupt_State = true;
    }

}

//End

 


BTW, I had used Demo code of the  ADuC7xxxV0.2 folders.
 I tried the PWMTest.c ,PWMSignalTest.c and PWM Signal Generator.c File for test .

After that I found the code had the error in the config description

here are the error sentence that I found :

 

PWMCON    = BIT0 + BIT10;     // PWM Standard mode, UCLK/2, PWM Trip interrupt enabled

//End

 

And I tried to change the Config register description to PWMCON0

But It didn't make PWM work ,either


 I will Add the Demo code  files in the end

If anyone tell me  where is mistake in the code, also inside ADuc 7xxxV0.2 demo code.

I will very appreciate if anyone  help.

Written by Guanhan_Chen
2017/11/29.

Outcomes