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:
The program code:Hard Fault @00001E90H in TestSinglePWM
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.
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