Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Alarm clock with the PIC12?

Status
Not open for further replies.

ragnar21

Newbie
Joined
Aug 3, 2022
Messages
1
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
11
I want to make an alarm like system with the PIC12F509. Obviously it will require a realtime clock or a time counter thingy. The issue is, I can't seem to find if the PIC has an inbuilt module for these or not. Else, I will have to get an external clock and make it output time to the PIC I suppose?

I tried searching for this question online but whenever the word "clock" or "time" was mentioned, it was a reference to the clock speed or response time. Thanks a lot for your responses in advance!
 

Hi,

search the datasheet for "timer".

If you want some accurate alarm system, then you ned an accurate clock source. Usually XTAL. External XTAL or external external oscillator. This reduces the available pin count.

Klaus
 

Using an external crystal across OSC1 and OSC2 will provide an accurate timing reference, good to within a second a day or so. Your biggest problem is only having 4 other pins for signals but you might be able to expand with i2c or SPI if you are careful.

Brian.
 

That is a very old device but the suggested replacement (PIC16F15313) has much better timers (16-bit for a start!).
There are a couple of issues you will need to overcome to make a usable alarm (other than the need for an external crystal mentioned above).
As your device only has a single 8-bit timer, with a 4MHz clock (the minimum for an HS crystal - you can go to DC with an external clock!), the input to the timer is (Fosc/4) 1MHz and with the maximum pre-scalar value (1:256) oyu still have a 3,906.25Hz 'tick'. Given it is an 8-bit timer, that means the ISR will be called at 15.26Hz (or once every 65.54mS). Therefore, the ISR will need to have an internal counter variable to count down the ~15 calls just to measure 1 second. You will need further variables to make it measure minutes and hours etc..
Then you need to remember that your MCU only has 41 bytes of RAM (and 1024 words of FLASH for the program).
Next comes the issue of the fact that the timer only counts seconds. It has no idea of 'time of day' or 'day of week' values (depending on how you want your alarm to work). Therefore it can be useful as it is as a 'ring on x seconds/minutes/hours' alarm, but not as 'ring at 8:00AM'. Of course you can add that but it will take additional RAM and FLASH.
Of course you also need some way to interact with the alarm to set the alarm time (whoever you define that). Your MCU does NOT have a hardware UART module so you are left with the GPIO pins (all 4 of them!) for switches and LEDs or (as @betwixt suggests) an external SPI, I2C or UART device - but that means you need to bit-bang the functionality which brings us back to the 1024 words of FLASH memory making that extremely tight.
Even the PIC16F15313 only has 4 GPIO pins but at least it has a EUSART module.
If you must use the PIC12F509 then you might be on a 'hiding to nowhere'. If you really want to make an alarm clock, then I suggest that you look for a more suitable MCU, one that has a built-in 'real-time clock' for a start and more IO pins for a display etc..
Susan
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top