Jump to content
Sign in to follow this  
TFcroft4

Interrupt Driven Clock

Recommended Posts

My first PIC project is a Real Time Clock used for start and finish for running events especially orienteering.

 

The system is run from a PIC 16F877 Monotronix board with a RTC, I2C serial LCD Display and key pad , and 2 multi 7 segment LED displays linked by a RS232 link. ( Velleman modules). The LED displays can have different but synchronised times. ( In orienteering runners are called up 3 minutes before their individual start times.)

 

The current system works by polling the RTC and updating the LEDs via RS232 and handles the keycode received and LCD display using a FSM system.

 

See www.finchhouse.org Clock Project

 

I plan to upgrade to an interrupt driven system using a Pulse per Second from the DS1307 RTC and or a GPS module or failing these the internal time base.

 

Looking at the NOVO RTS system I have the following outline plan

 

Events: Each second interrupt from GPS/RTC send PPS Semaphore and send PPS message via RS232 to LEDs

Each TS time interval trigger NOVO Timer event

 

Tasks: Calculate and send new time data messages via RS232 to each LED module on PPS Semaphore ( must complete within each second before next PPS pulse)

Poll keypad ( I2C) , get character on Timer Event - Create Key received Semaphore (poll every 1/10th second ? how quickly can a key be pressed?)

(Could be interrupt event but don't have I2C Interrupt to main board at the moment.)

Finite State Machine on Key Semaphore or Time out (If there is a key received or update screen every 1/10th second)

Depending on Key

Change State i.e Which Screen is displayed on LCD

Change Settings e.g. Time or date settings, Time Zone, Sound on or off

Update Screen as screens also show current time to echo LED display

 

Regardless of internal accuracy (ideally 1/100th sec in a time structure ) the displays are only required to show HH:MM:SS

 

I would welcome any thoughts and observations - will this work with standard NOVO libraries or will I need a special build?

 

Thanks

 

Ted

 

PS In NOVO is there a way for a semaphore to carry a message such as which key was pressed?

Share this post


Link to post
Share on other sites
I would welcome any thoughts and observations - will this work with standard NOVO libraries or will I need a special build?
Free supplied Novo RTOS builds only support up to 3 tasks, so you may have to squeeze so tasks together.

 

PS In NOVO is there a way for a semaphore to carry a message such as which key was pressed?
No, the semaphores are simple counting semaphores. Declare a variable or data struct to carry extra information.

 

Attached is my alarm clock code I did in a couple of hours a while back as a demonstration of some Matrixmultimedia EBlocks. It displays the time on an LCD display, allows the time and alarm time to be set.

 

Take a look, I hope it helps.

 

Regards

Dave

Clock.zip

Share this post


Link to post
Share on other sites
I would welcome any thoughts and observations - will this work with standard NOVO libraries or will I need a special build?
Free supplied Novo RTOS builds only support up to 3 tasks, so you may have to squeeze so tasks together.

 

PS In NOVO is there a way for a semaphore to carry a message such as which key was pressed?
No, the semaphores are simple counting semaphores. Declare a variable or data struct to carry extra information.

 

Attached is my alarm clock code I did in a couple of hours a while back as a demonstration of some Matrixmultimedia EBlocks. It displays the time on an LCD display, allows the time and alarm time to be set.

 

Take a look, I hope it helps.

 

Regards

Dave

 

Thanks for the code - i will take a look.

 

I Think I can work with three tasks i.e.

 

1 Calculate and send new time data messages via RS232

2 Poll keypad ( I2C) , get character

3 Finite State Machine on Key Semaphore or Time out

 

I'll let you know how I get on

 

Thanks again

 

TF

Share this post


Link to post
Share on other sites

A little time down the line - here is an update.

 

The clocks ( 5 units ) run using NOVO RTOS with three tasks:

 

 

Task1 - Called every second roll over - semaphore is set by an interrupt on Port B when GPS unit sends the PPS pulse, this resets a millisecond count and calculates the new values for the various time displays and also updates the LED displays.

 

(If for any reason the GPS interrupt does not work then the TMR interrupt is used to set the semaphore when milliseconds reach 1000.)

 

Task 2 - Called every 15 ms - Key board and LCD screen handler - polls the keypad every time the task runs and updates the LCD Screen on the Modtronix LCD2S . The screen handler is a finite state machine based on demo code that came with the Modtronix board - the only cost is that it uses a lot of code space to handle the multiple screen displays which are used to set various clock options e.g Daylight Saving Time.

 

Task 3 - GPS synchronisation task - called once after all initialisations are complete but can also be called on demand by one of the menu options in Task 2. This task waits for standard NMEA messages either $GPZDA or $GPRMC, these give the current (UTC) time ( and date). These messages are parsed to extract the current time. The system clock and DS1307 RTC are updated with the current UTC time.

 

One major headache was the GPS synchronisation hanging on some occasions when part of the initialisation routines. This seemed to be random but I now think was possibly caused by the serial output from the GPS, which starts immediately, not being serviced.

 

The GPS unit used was EasyGPS board from http://www.mikroe.com/en/tools/gps/easygps/ - this is a complete board at a reasonable price rather than a module so saved having to build hardware except for interconnections. The GPS module is quite sensitive and picks up a reasonable number of satellites even indoors but near a window. By using the GPS pulse per second interrupt the 5 clocks are all synchronised to the GPS system.

 

Thanks.

Share this post


Link to post
Share on other sites

Join the conversation

You are posting as a guest. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...