Timer- peripheral

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

Timer- peripheral

Post by anitasure123 » Thu Aug 06, 2015 8:35 am

Hello There,
This is simple code to print the "Hello" on astrobe terminal after delay of 2 seconds. Here to create a delay i am using Timer0 peripheral. But not generating the delay, following is the code:
////////////////////////////////////////////////////////////////////////////////
MODULE Timer_demo;
IMPORT Main,Out,In,MCU,SYSTEM,Timer,LinkOptions;

PROCEDURE Power_up();
VAR
s:SET;
s1,i:INTEGER;
BEGIN
SYSTEM.GET(MCU.PCONP,s);
SYSTEM.PUT(MCU.PCONP,s + {1}); (*enable power for Timer0*)
END Power_up;

PROCEDURE Timer_init(val:INTEGER);
VAR
s:SET;
s1,i,clk:INTEGER;
BEGIN
clk:=LinkOptions.Fosc DIV (4*1000000)-1;

Power_up();

SYSTEM.GET(MCU.T0TCR,s);
SYSTEM.PUT(MCU.T0TCR,s+{1});(*reset timer*)

SYSTEM.PUT(MCU.T0PR,0);
SYSTEM.PUT(MCU.T0MR0,val*clk);

SYSTEM.GET(MCU.T0MCR,s); (*stop on match0*)
SYSTEM.PUT(MCU.T0MCR,s+{2});

SYSTEM.GET(MCU.T0TCR,s);(*enable timer*)
SYSTEM.PUT(MCU.T0TCR,s+{0});

(*wait until time has elapsed
REPEAT UNTIL SYSTEM.BIT(MCU.T0TCR,1); *)
END Timer_init;

PROCEDURE delay_milli(sec:INTEGER);
BEGIN
Timer_init(sec);
END delay_milli;

PROCEDURE Hello;
BEGIN

Out.String("Hello"); Out.Ln;
delay_milli(2000000);

Out.String("Hello"); Out.Ln;
delay_milli(2000000);


END Hello;
BEGIN
Hello;
END Timer_demo.
//////////////////////////////////////////////////////////////////////////////////////////
What is mistake in this.

Please reply.

Thanks
Anita

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

Re: Timer- peripheral

Post by cfbsoftware » Thu Aug 06, 2015 12:34 pm

Hi Anita,

You shouldn't have to worry about the low-level details when you are performing general tasks like timer delays in Astrobe because we provide library modules to do that. What you are trying to do can be done much more simply like this:
Timer_demo.JPG
However, if you want to see how to write this sort of low-level code in Oberon you should refer to the source code of the library modules which is included with the Personal and Professional Editions of Astrobe.

Regards,
Chris
You do not have the required permissions to view the files attached to this post.

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

Re: Timer- peripheral

Post by anitasure123 » Thu Aug 20, 2015 6:47 am

Thank You for reply.

Can you please give me Timer module definition. as I am using Starter edition i cant see its definition. I can use predefined Timer function, but after match i want to generate interrupt where my code has to perform some job.

In C language this statement is used - while(LPC_TIMER0->TCR & 0x01); ----> which is used to wait until time has elapsed. How can i do the same in oberon language?

Please reply,
Thanks
Anita

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

Re: Timer- peripheral

Post by cfbsoftware » Thu Aug 20, 2015 12:21 pm

The Timer library module definitions and descriptions are in the Astrobe documentation which is included in the Starter Edition or can be downloaded from our website.

The C statement:

Code: Select all

while(LPC_TIMER0->TCR & 0x01); 
means:
continue looping while bit 0 of LPC_TIMER0->TCR is set (i.e. bit 0 = 1)
In Oberon this is:

Code: Select all

WHILE SYSTEM.BIT(MCU.T0TCR, 0) DO END;
or, if you prefer:

Code: Select all

REPEAT UNTIL ~SYSTEM.BIT(MCU.T0TCR, 0);

Locked