ISR

Newcomers to Astrobe and Oberon are welcome to ask any beginner-level questions here
Post Reply
anitasure123
Posts: 22
Joined: Tue Jul 21, 2015 6:49 am

ISR

Post by anitasure123 » Thu Aug 13, 2015 7:28 am

Hello There,

How to define ISR in oberon. I want to define ISR for external interrupt. as i am using starter edition, I can not check the definition of MCU and LPC import is not available.
Please reply.

Thanks
Anita

cfbsoftware
Site Admin
Posts: 423
Joined: Fri Dec 31, 2010 12:30 pm
Contact:

Re: ISR

Post by cfbsoftware » Thu Aug 13, 2015 10:31 pm

There aren't any pre-defined GPIO interrupt-related definitions in the Astrobe library modules. All the information you need is in the NXP LPC176x-5x UserManual (UM10360) e.g. Section 9.5.6 GPIO interrupt registers. You can download a copy of this from the NXP User Manual links on the Astrobe Development Boards page:

http://www.astrobe.com/boards.htm

You can give the relevant register addresses meaningful names by defining them as hexadecimal constants in CONST sections when you develop your own Oberon modules e.g.

Code: Select all

CONST
  NVICBase* = 0E000E000H;
  NVICISER0* = NVICBase + 0100H;
  NVICISER1* = NVICBase + 0104H;
  NVICICER0* = NVICBase + 0180H;
  NVICICER1* = NVICBase + 0184H;
  VTOR*      = NVICBase + 0D08H;
Examples of how to define, install and use Oberon interrupt handlers are included with the Astrobe Starter Edition e.g. IRQTimer.mod and IRQBlinker.mod.

anitasure123
Posts: 22
Joined: Tue Jul 21, 2015 6:49 am

Getting Hard fault Error

Post by anitasure123 » Thu Oct 08, 2015 7:08 am

Hello,

Whenever my application detects a external interrupt3 which i configured for pin P2.6, getting hard fault. I am unable to recognise the bug in this code. and code is below:

1)PWMSys.mod:

MODULE PWMSys;
IMPORT MCU, SYSTEM,Out,In,Timer,Traps,Main,Timer0;

CONST
IOIntStatus = 40028080H;
IO2IntEnR = 400280B0H;
IO2IntStatR = 400280A4H;
IO2IntClr = 0400280ACH;

EINT3ExceptionVector = 010000094H; (*VIC for external interrupt3*)
Timer0ExceptionVector = 010000044H;
NVICBase = 0E000E000H;
NVICISER0 = 0E000E100H;
NVICISER1 = 0E000E104H;
NVICICER0 = 0E000E180H;
NVICICER1 = 0E000E184H;
NVICICPR0 = 0E000E280H;
VTOR = NVICBase + 0D08H;
VAR timerFreq,timerTick,pwm_on_us,zero_cross_us,pwm_on,zero_cross,main_state,pwm_off_period:INTEGER;

PROCEDURE setup_pin_interrupt;
VAR
s:SET;
BEGIN
SYSTEM.GET(IO2IntEnR,s);
SYSTEM.PUT(IO2IntEnR,s+{6});
(*SYSTEM.PUT(IO2IntClr,+{6});*)
END setup_pin_interrupt;

PROCEDURE setup_pin_direction;
VAR
s:SET;
BEGIN
SYSTEM.GET(MCU.FIO2DIR,s);
SYSTEM.PUT(MCU.FIO2DIR,s-{6}+{0});(*P2.6 as input*)
(*P2.0 as output*)
END setup_pin_direction;

PROCEDURE pwm_sys_init;
VAR TICKRATE_HZ1:INTEGER;
BEGIN
TICKRATE_HZ1 := 4000;
timerFreq := MCU.CCLK;
timerTick := (timerFreq DIV TICKRATE_HZ1) DIV 1000;
setup_pin_direction;
setup_pin_interrupt;
END pwm_sys_init;

PROCEDURE pwm_set_parameters(p,z:INTEGER);
BEGIN
pwm_on :=timerTick * p;
zero_cross :=timerTick * z;
pwm_off_period:=timerTick * 100;
Out.String("In pwm_set_parameters pwm_on= zero_cross= ");Out.Int(pwm_on,0);Out.Int(zero_cross,0); Out.Ln;
END pwm_set_parameters;

PROCEDURE Getdata;
BEGIN
In.Int(pwm_on_us);
In.Int(zero_cross_us);
Out.String("pwm on in us=");Out.String("zero cross in us =");Out.Int(pwm_on_us,0);Out.String(" ");Out.Int(zero_cross_us,0);Out.Ln;

END Getdata;

PROCEDURE stop_pwm;
VAR
s:SET;
BEGIN;
SYSTEM.GET(MCU.FIO2CLR0,s);
SYSTEM.PUT(MCU.FIO2CLR0,s+{0});
(*SYSTEM.GET(MCU.PWM1PCR,s);*)

END stop_pwm;

PROCEDURE pwm_init;
VAR
s:SET;
s1,s2,freq:INTEGER;
BEGIN
SYSTEM.GET(MCU.PCONP,s);
SYSTEM.PUT(MCU.PCONP,s + {6});
SYSTEM.GET(MCU.PINSEL4,s);
SYSTEM.PUT(MCU.PINSEL4,s + {0}+{2}+{4}+{6}+{8}+{10});
freq:=MCU.CCLK DIV (4*1000000)-1;
SYSTEM.PUT(MCU.PWM1PR,freq);
SYSTEM.GET(MCU.PWM1LER,s);
SYSTEM.PUT(MCU.PWM1LER,s-{0..6}+{7});
SYSTEM.PUT(MCU.PWM1MR0,10000);
SYSTEM.GET(MCU.PWM1MCR,s);
SYSTEM.PUT(MCU.PWM1MCR,s +{1});
SYSTEM.PUT(MCU.PWM1MR1,pwm_on_us);
SYSTEM.GET(MCU.PWM1LER,s);
SYSTEM.PUT(MCU.PWM1LER,s+{0..6}-{7});
SYSTEM.GET(MCU.PWM1PCR,s);
SYSTEM.PUT(MCU.PWM1PCR,s+{9..14});
SYSTEM.GET(MCU.PWM1TCR,s);
SYSTEM.PUT(MCU.PWM1TCR,s +{0,3});
END pwm_init;

PROCEDURE fire_pwm;
VAR
s:SET;
BEGIN
SYSTEM.GET(MCU.FIO2SET,s);
SYSTEM.PUT(MCU.FIO2SET,s+{0});

END fire_pwm;


PROCEDURE Timer0_IRQHandler*[0];
BEGIN

CASE main_state OF
(*pwm_off*) 0 : stop_pwm;
Timer0.Stop_timer0;
main_state := 2;|

(*pwm_on*) 1 :stop_pwm;
Timer0.Start_Timer0(pwm_off_period * 1000);(*pwm off period*)
main_state := 0;|

(*state_wait_for_
pwm_on*) 2 :
fire_pwm;
Timer0.Start_Timer0(pwm_on *1000);(*pwm on period*)
pwm_init;
main_state := 1;


END;

END Timer0_IRQHandler;

PROCEDURE EINT3_IRQHandler[3];
VAR
i:INTEGER;
BEGIN
IF SYSTEM.BIT(MCU.FIO2PIN0,6) THEN SYSTEM.PUT(IO2IntClr,6);
SYSTEM.GET(IO2IntStatR,i);
(*Out.String("value of i=");Out.Int(i,0);Out.Ln;*)
SYSTEM.PUT(IO2IntEnR,i);
Timer0.Start_Timer0(zero_cross);
END;

END EINT3_IRQHandler;

PROCEDURE pwm_start;
BEGIN
(*Out.String("in pwm_start"); Out.Ln;*)
SYSTEM.PUT(NVICICPR0,+{21});
SYSTEM.PUT(NVICISER0,+{21});

Traps.Assign(EINT3ExceptionVector,EINT3_IRQHandler);
(*Out.String("in pwm_start"); Out.Ln;*)
END pwm_start;



PROCEDURE Stop_timer0;
BEGIN
SYSTEM.PUT(MCU.T0TCR,-{0});
END Stop_timer0;


BEGIN
pwm_sys_init;
Out.String("enter pwm on period,zero cross peak detect time");Out.Ln;
Getdata;
pwm_set_parameters(pwm_on_us,zero_cross_us);
WHILE TRUE DO
main_state :=2;
pwm_start;
END;
END PWMSys.
//////////////////////////////////////////////////////////////////////////////////////////////
2)Timer0.mod:

MODULE Timer0;
IMPORT Main,Out,In,MCU,SYSTEM,Timer,LinkOptions,Traps,PWMSys;

PROCEDURE Timer0_IRQHandler[0];
CONST
ledBit={22};
VAR
direction:SET;
BEGIN


END Timer0_IRQHandler;


PROCEDURE Timer_init(sec:INTEGER);

VAR
s:SET;
k:BOOLEAN;
s1,i,clk,j:INTEGER;
BEGIN
clk := (MCU.PCLK DIV (1000000))-1;
(*Out.Int(LinkOptions.Fosc,2); Out.Ln;
Out.Int(clk,2);Out.Ln;*)

SYSTEM.GET(MCU.PCONP,s);
SYSTEM.PUT(MCU.PCONP,s+ {1});
(*SYSTEM.PUT(MCU.T0PR,clk);
SYSTEM.GET(MCU.PCLKSEL0,s);
SYSTEM.PUT(MCU.PCLKSEL0,s-{2,3});*)
SYSTEM.PUT(MCU.T0TC,0);
SYSTEM.GET(MCU.T0TCR,s);
SYSTEM.PUT(MCU.T0TCR,s+{1});(*reset timer*)
SYSTEM.PUT(MCU.T0PR,clk);
SYSTEM.PUT(MCU.T0MR0,sec);
SYSTEM.PUT(MCU.T0IR,0FFFFH);
SYSTEM.GET(MCU.T0MCR,s); (*interrupt and stop on match0*)
SYSTEM.PUT(MCU.T0MCR,s+{0,2});

SYSTEM.PUT(MCU.T0TCR,s+{0}); (*start timer*)
(*wait until time has elapsed*)
WHILE SYSTEM.BIT(MCU.T0TCR,0) DO END;
(*PWM_8_20.SetPWM(1,2000);*)
END Timer_init;


PROCEDURE Start_Timer0*(M_sec:INTEGER);
CONST
Timer0ExceptionVector = 010000044H;
NVICBase = 0E000E000H;
NVICISER0 = NVICBase + 0100H;
NVICISER1 = NVICBase + 0104H;
NVICICER0 = NVICBase + 0180H;
NVICICER1 = NVICBase + 0184H;
NVICICPR0 = NVICBase + 0E200H;
VTOR = NVICBase + 0D08H;
ledBit = {22};
VAR
s,direction:SET;
k:BOOLEAN;
s1,i,clk,j:INTEGER;


BEGIN

SYSTEM.PUT(NVICICPR0,+{1});
SYSTEM.PUT(NVICISER0,+{1});
Timer_init(M_sec);
Traps.Assign(Timer0ExceptionVector,PWMSys.Timer0_IRQHandler);
END Start_Timer0;

PROCEDURE Stop_timer0*;
BEGIN
SYSTEM.PUT(MCU.T0TCR,-{0});
END Stop_timer0;
END Timer0.
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Please reply

Thanks
Anita

cfbsoftware
Site Admin
Posts: 423
Joined: Fri Dec 31, 2010 12:30 pm
Contact:

Re: ISR

Post by cfbsoftware » Sat Oct 10, 2015 1:31 am

Your question is beyond the scope of this free support forum. If you need professional assistance to help debug and troubleshoot programs that you are developing contact support@cfbsoftware.com. We may be able to offer you a quotation for the work and / or suggest a contract Oberon developer who may be able to help you.

Post Reply