Page 1 of 1

problems with PWM

Posted: Fri Dec 27, 2013 3:47 pm
by abaumann
Hi,

I hope evrybody had a Merry Christmas and I wish evrybody a new Happy New Year !

In the last weeks I wrote some small test programs (extending the ADC for multible channels, implement a interrupt generating GPIO for input detection ..).

I use mbed LPC1768.

After that I'm trying to implement programm using PWM to control a motor.
After some days I can not find the error.
To make error detection easier I remove most of the program to only include the first lines which create Hardware Faults.
The following program generate:
Hard Fault @00001E90H in TestSinglePWM
The program code:

Code: Select all

MODULE TestSinglePWM;
IMPORT Out,SYSTEM,MCU,Main;
  

PROCEDURE PowerUp();
CONST
  PCPWM1 = {6};  (* PWM1 power/clock control bit  
                    On reset, the PWM is enabled (PCPWM1 = 1)
                  *)      
VAR
  s: SET;  
BEGIN 
  SYSTEM.GET(MCU.PCONP, s);
   IF ~(6 IN s) THEN
    SYSTEM.PUT(MCU.PCONP, s + PCPWM1)
   END
END PowerUp;


(* Only for  channel 1 *)
PROCEDURE Init*();
VAR
  s: SET; 
BEGIN
  PowerUp();
  
  (* set clock to CCLK/4  *)
  SYSTEM.GET(MCU.PCLKSEL0, s);
  SYSTEM.PUT(MCU.PCLKSEL0, s - {12,13});
  
(*  Out.String("set clock to CCLK/4  "); Out.Ln();  *)
  
  SYSTEM.GET(MCU.PINSEL4, s);
  SYSTEM.PUT(MCU.PINSEL4, s + {0} - {1});
    
 (* Neither pull-up nor pull-down *) 
  SYSTEM.GET(MCU.PINMODE4, s);
  SYSTEM.PUT(MCU.PINMODE4, s + {1} - {0});
     
  SYSTEM.GET(MCU.PWM1TCR,s);
  
  (*
  (* no prescale  *)
  SYSTEM.PUT(MCU.PWM1PR,0);
 *)
 (* Out.String("no prescale  "); Out.Ln(); *)
   
  (* SET single PWM mode  *)
  (*
  SYSTEM.GET(MCU.PWM1MCR, s);

  SYSTEM.PUT(MCU.PWM1MCR,s+{1});  (*  or 0 ?  *)
 *)   
END Init;

BEGIN

 Out.String("PWM Test !!!");Out.Ln; 
 Init();
 Out.String("Init passed !!!");Out.Ln; 
 

END TestSinglePWM.
For me it looks like that evry access to a PWM1 related control register raises a hardware fault.
In this version
SYSTEM.GET(MCU.PWM1TCR,s);
generate the hardware fault.

The first lines of code (all lines before SYSTEM.GET(MCU.PWM1TCR,s); ) are working !

The same problem occurs if I use the line :

SYSTEM.PUT(MCU.PWM1PR,0);
or
SYSTEM.GET(MCU.PWM1MCR, s);

...

I think it act in a way as if the PowerUp() would not work ???

Is there anything to do additionally to Powerup to access PWM1 controll registers ?

Is something in the standard libs which influence the way to use PWM ?

I don't know what I can do next.

I have also analysed the PWM example for LPC2378, the C++ implementation on the mbed - site and the documentation of LPC1768.

It would be nice to get a hint.


Best regards


Andreas

Re: problems with PWM

Posted: Fri Dec 27, 2013 10:12 pm
by cfbsoftware
Thank you for reporting the problem. It seems that there is an error in the LPC1769 MCU.mod library file. Try replacing the line:

Code: Select all

PWMBase* = 04001800H
with

Code: Select all

PWMBase* = 040018000H
(i.e. there is an extra trailing 0)

Re: problems with PWM

Posted: Mon Dec 30, 2013 4:40 pm
by abaumann
Hi,

Thank you for your quick response !
Before your response I was also looking to the PWMBase address in MCU.mod but could not detect the difference. It seems that sometimes I need glasses :))

Now my PWM test program works.


Best regards

Andreas