chipKIT® Development Platform

Inspired by Arduino™

Timer Alarm Interrupts?

Created Sat, 21 Apr 2012 02:55:30 +0000 by gregcotten


gregcotten

Sat, 21 Apr 2012 02:55:30 +0000

Hello,

As I patiently wait for my uno32 to arrive, I have a small question. Has anyone used the onboard timers to trigger alarm interrupts? I really like the user-contributed MsTimer2 AVR/Arduino library (http://arduino.cc/playground/Main/MsTimer2). Essentially I need a precise interrupt that triggers every 20 milliseconds.

Help?

Thanks, Greg


les1943

Sat, 21 Apr 2012 06:26:23 +0000

Greg, As my language skills are still amateur I used the RTCC on UNO with the alarm pin output and looped it back to a pin interrupt,( pins 2---7 ) continual alarms can be generated in units of 20 due to chipkit Rising or falling interrupts. 20 msec should be possible as RTC has HH:MM:SS:ss

This is my effort... Les.

void setrtc(unsigned long newtime){ // SET THE TIME DATE AND ALARM //Unlock RTCCON; SYSKEY = 0x0; SYSKEY = 0xAA996655; SYSKEY = 0x556699AA; RTCCONSET = 0X00000008; // WRITE ENABLE //RTCCONSET =0X04; // RTCC output enable // /assume the secondary oscillator is enabled and ready, i.e. OSCCON<1>=1, OSCCON<22>=1, and RTCC write is enabled i.e. RTCWREN (RTCCON<3>) =1;/ unsigned long date=0x06102705;// set date to Friday 27 Oct 2006 unsigned long atime = newtime; // + 0x00000200);// set alarm time to time -9 sec RTCCONCLR=0x8000; // turn off the RTCC while(RTCCON&0x40); // wait for clock to be turned off RTCTIME=newtime; // safe to update the time RTCDATE=date; // update the date RTCCONCLR=0x6080; // turn off BITS RTCCONSET=0X01; // RTCOE output enable // turn off the alarm, chime and alarm repeats; clear // the alarm mask while(RTCALRM&0x1000); // wait ALRMSYNC to be off RTCALRMCLR=0xCFFF; // clear ALRMEN, CHIME, AMASK, ARPT; ALRMTIME=atime; ALRMDATE=date; // update the alarm time and date RTCALRMSET=0xC100; /// alarm signal 0xC200 10 sec or 1 minute 0xC300 RTCCONSET=0x8000; // turn on the RTCC RTCCONCLR = 0X08; // WRITE disable while(!(RTCCON&0x40)); // wait for clock to be turned on SYSKEY = 0x0; }


gregcotten

Sat, 21 Apr 2012 06:46:09 +0000

Which pin is the alarm pin? I couldn't find it on the uno32 board reference document.

Do I need an external crystal to make this work or is there one already?

Also, in this code, what is newtime supposed to be? Where do I set the interval for the continuous alarm?

I'm a little new to this stuff if you can't already tell. Thanks for your help!

Greg


les1943

Sat, 21 Apr 2012 07:25:16 +0000

Greg.

Yes u need a crystal 32,768 hz soldered in X2 on uno

chipkit pin 2 is the alarm output , newtime is my data to start from a known time.

This line below sets the alarm i have an interrupt every 2 sec with 0xC100 0xC001 should be 20msec (need to check that) ( due to interrupt x 2 ) there is a RTCC page on the microchip data sheets for all the details.

RTCALRMSET=0xC100; /// alarm signal 0xC200 10 sec or 1 minute 0xC300


unsigned long time=0x12584000; // startup time

// in setup //

setrtc(time);


a tad crude++ but it works !!

Les

Edit... Sorry I Just checked the data sheet , the alarm each 20 msec not possible the mask only goes to .5 sec...

bit 11-8 AMASK<3:0>: Alarm Mask Configuration bits( 0000 = Every half-second 0001 = Every second 0010 = Every 10 seconds 0011 = Every minute 0100 = Every 10 minutes 0101 = Every hour 0110 = Once a day 0111 = Once a week 1000 = Once a month 1001 = Once a year (except when configured for February 29, once every four years) 1010 = Reserved; do not use 1011 = Reserved; do not use 11xx = Reserved; do not use


gregcotten

Sat, 21 Apr 2012 21:08:59 +0000

That is unfortunate. Does anyone else have any suggestions for generating an interrupt every 20 ms or so?

Thanks, Greg


les1943

Sun, 22 Apr 2012 11:01:37 +0000

Greg, I dont know if this post is relevant , or you already checked it out . ask the author ?.

http://www.chipkit.org/forum/viewtopic.php?f=6&t=1194&hilit=timer+interrupts


gregcotten

Mon, 23 Apr 2012 20:56:45 +0000

I figured it out I think - the solution can be found in my post here: http://www.chipkit.org/forum/viewtopic.php?f=6&t=1194&p=5273#p5273