Real time Hourly Device Control

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 8.

Moderator: Benj

Derrihj
Posts: 104
Joined: Mon Jul 09, 2018 12:43 pm
Has thanked: 21 times
Been thanked: 12 times
Contact:

Real time Hourly Device Control

Postby Derrihj » Sat Jan 18, 2020 1:54 am

Hi every one,is it advisable to use internal oscillator while designing a real time clock? my issue is,i wanted to control some device and turn it off when set hours have reached so what i did i got my PIC16f886, set the internal frequency to 8MHZ, enabled Timer2 int with Prescaler Rate= 1:16,
Postscaler Rate=1:10, Rollover= 250 and got a clean 50.000Hz interrupt Frequency.The ka project tested fine both software and hardware the only thing i realised was when i compared my seconds movement with a real clock set up to run at the same time my seconds where some how slower than all the real clocks i tested with so my question is, can't we use internal oscillators when designing real time projects or controls? why the slow movement yet i had no delays used in the timing loop. Here is my flow-chat.
Attachments
Device Time Cutoff.fcfx
(22.34 KiB) Downloaded 12 times

User avatar
medelec35
Valued Contributor
Valued Contributor
Posts: 8533
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2456 times
Been thanked: 3522 times
Contact:

Re: Real time Hourly Device Control

Postby medelec35 » Sat Jan 18, 2020 1:46 pm

Hi Derrih,
Derrihj wrote:is it advisable to use internal oscillator while designing a real time clock?

No, internal oscillator is not suitable.
Lets do some calculations to prove this.
Suppose internal osc has a tolerance of 1%.
Since there are 86400 seconds in a day.
The maximum error is 86400*1/100 = 864 secs = 14.4 minutes!
As your project is running at 8MHz, The alternative could be to use a 8MHz crystal which could have a tolerance of range of about 25 to 100 ppm (parts per million) depending on choice.
Suppose you choose a tol of 25ppm then the maximum error is 86400*25/1000000 = 2.16 secs per day.
The disadvantage is crystals accuracy depends on both temperature and associated load capacitors.
For the best accuracy, there are RTC (Real Time clock) components that are not affected by temperature changes.
E.g DS3231/DS3232 by Maxim. They have a tolerance of 2PPM.
The maximum error is 86400*2/1000000 = 0.17 secs per day = 63 seconds per year!
Some people use a 32.768KHz watch crystal connected to timer1 external pins.
If that was the case the error calculations are the same as parts per million (depending on crystal choice), but you then can use internal oscillator.

So you have some choices there.
These users thanked the author medelec35 for the post (total 4):
kersing (Sat Jan 18, 2020 2:02 pm) • jgu1 (Sat Jan 18, 2020 2:57 pm) • Derrihj (Sat Jan 18, 2020 3:35 pm) • AbhijitR (Mon Jan 20, 2020 2:45 am)
Rating: 21.05%
 
Martin

If you read a post that is useful, please show appreciation by clicking on thumbs up Icon.

Derrihj
Posts: 104
Joined: Mon Jul 09, 2018 12:43 pm
Has thanked: 21 times
Been thanked: 12 times
Contact:

Re: Real time Hourly Device Control

Postby Derrihj » Sat Jan 18, 2020 3:43 pm

Thanks allot medelec35 its educative to always have you around and that is why its always good to ask the professionals before u act now i have to remake the PCB with an external oscillator this one with internal oscillator was one second behind when i was testing it this went on increasing to 2 seconds and more as time went on.harass am beginning to hate internal oscillators.

User avatar
medelec35
Valued Contributor
Valued Contributor
Posts: 8533
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2456 times
Been thanked: 3522 times
Contact:

Re: Real time Hourly Device Control

Postby medelec35 » Sat Jan 18, 2020 4:29 pm

Hi Derrihj,
Thanks you & Your'e welcome.
Internal oscillators help to keep component count down, and accuracy is OK for lower baud communication purposes and other non very precision timing and e.g UART, SPI, I2C and even servos etc.
When is come to very precision timing like TIME, UART with higher baud rates and very short duration pulses etc then internal oscillator is not the way to go.
Martin

If you read a post that is useful, please show appreciation by clicking on thumbs up Icon.

User avatar
medelec35
Valued Contributor
Valued Contributor
Posts: 8533
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2456 times
Been thanked: 3522 times
Contact:

Re: Real time Hourly Device Control

Postby medelec35 » Sat Jan 18, 2020 4:38 pm

One other thing to mention.
I believe 8 MHz is a good choice in frequency as you can enable PLL (if your microcontroller supports it) to multiply actual clock frequency to 4 X 8 = 32MHz.
The higher frequency will have much less of an impact and will allow higher comms rate to be used.

Looking at your flowchart, I would suggest the following within interrupt:
2020_01_18_15_54_37_Window.png
2020_01_18_15_54_37_Window.png (37.36 KiB) Viewed 500 times
Martin

If you read a post that is useful, please show appreciation by clicking on thumbs up Icon.

Derrihj
Posts: 104
Joined: Mon Jul 09, 2018 12:43 pm
Has thanked: 21 times
Been thanked: 12 times
Contact:

Re: Real time Hourly Device Control

Postby Derrihj » Sat Jan 18, 2020 10:27 pm

Thanks medelec35 yes i had copied that into interrupt when i was trying out any way of making my counting work better and yes it improved somehow
as seconds were easily added up within the int not to be interrupted by the next beat of int count while in the loop outside INT.Dont know if ive sad it right but anyway another thing PIC16f886 has no PLL but what u are trying to say that PLL would solve the problem sothat i dont have to switch to external oscillator?

User avatar
medelec35
Valued Contributor
Valued Contributor
Posts: 8533
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2456 times
Been thanked: 3522 times
Contact:

Re: Real time Hourly Device Control

Postby medelec35 » Sun Jan 19, 2020 12:07 am

Derrihj wrote: another thing PIC16f886 has no PLL but what u are trying to say that PLL would solve the problem sothat i dont have to switch to external oscillator?

No not at all the PLL is only as accurate as the clock.
So if chip did have PLL and using 8MHz internal clock at 1% tolerance, then if use PLL the clock will be 8 * 4 = 32MHz, also with a tolerance of 1%.
These users thanked the author medelec35 for the post:
Derrihj (Sun Jan 19, 2020 8:34 am)
Rating: 5.26%
 
Martin

If you read a post that is useful, please show appreciation by clicking on thumbs up Icon.

Derrihj
Posts: 104
Joined: Mon Jul 09, 2018 12:43 pm
Has thanked: 21 times
Been thanked: 12 times
Contact:

Re: Real time Hourly Device Control

Postby Derrihj » Sun Jan 19, 2020 8:42 am

I see some circuits with an external crystal oscillator with its body grounded whats the point in that does it do any good in stability? Whats so important in doing that?

Derrihj
Posts: 104
Joined: Mon Jul 09, 2018 12:43 pm
Has thanked: 21 times
Been thanked: 12 times
Contact:

Re: Real time Hourly Device Control

Postby Derrihj » Mon Jan 20, 2020 9:57 am

Can i use the RTC component (DS3231 ic) to extract out only the seconds and use them in my project for accuracy only seconds from DS3231 ic then i use them to give me minutes and hours then i use the hours to control a relay? Check out the flowchat below and guide me on this.
Attachments
RTC test.fcfx
(11.42 KiB) Downloaded 8 times

User avatar
Benj
Matrix Staff
Posts: 14559
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4591 times
Been thanked: 4237 times
Contact:

Re: Real time Hourly Device Control

Postby Benj » Mon Jan 20, 2020 11:00 am

Hello,

I see some circuits with an external crystal oscillator with its body grounded whats the point in that does it do any good in stability? Whats so important in doing that?


Maybe only partially to do with electrical shielding and probably more to stop the high frequency from being radiated out rather then improving internal stability though it likely will help a little. Likely mainly used for mechanical stability to avoid stress to the connection pins.

Can i use the RTC component (DS3231 ic) to extract out only the seconds and use them in my project for accuracy only seconds from DS3231 ic then i use them to give me minutes and hours then i use the hours to control a relay?


Sounds like it should be possible. I'll have a look at your code.
These users thanked the author Benj for the post:
Derrihj (Mon Jan 20, 2020 11:44 am)
Rating: 5.26%
 

User avatar
Benj
Matrix Staff
Posts: 14559
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4591 times
Been thanked: 4237 times
Contact:

Re: Real time Hourly Device Control

Postby Benj » Mon Jan 20, 2020 11:04 am

Looking at your program seconds will never be equal to 60 as the RTC will wrap the value from 59 to 0.

I've made a small change for you to instead check for seconds being less then the previous value.
RTC test.fcfx
(11.55 KiB) Downloaded 13 times


This way the program should work even if you don't read the RTC every second, an absolute minimum of 2 times a minute should be enough for reliable operation.
These users thanked the author Benj for the post:
AbhijitR (Mon Jan 20, 2020 1:48 pm)
Rating: 5.26%
 

Derrihj
Posts: 104
Joined: Mon Jul 09, 2018 12:43 pm
Has thanked: 21 times
Been thanked: 12 times
Contact:

Re: Real time Hourly Device Control

Postby Derrihj » Mon Jan 20, 2020 12:16 pm

Thanks Benj will have to build a hardware with LCD, test and see how the seconds accurately move in line with a physical normal clock seconds.The baud rate for DS3231 here should be set to what 100KHz,400KHz or 1MHz for the Ds3231 to work perfectly?

User avatar
Benj
Matrix Staff
Posts: 14559
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4591 times
Been thanked: 4237 times
Contact:

Re: Real time Hourly Device Control

Postby Benj » Mon Jan 20, 2020 1:31 pm

Hello,

The baud rate for DS3231 here should be set to what 100KHz,400KHz or 1MHz for the Ds3231 to work perfectly?


If you're not bothered about throughput then the slower you clock the I2C the more reliable and immune to noise it should be so for your application I would go for 100KHz. However reading the datasheet it only mentions 400KHz so I would use that setting :D

Also for added stability make sure you have a ceramic decoupling cap as close as possible to the IC. 100nF is my goto value but anything from 1nf to 10uf should work pretty well. If you're using a module then it likely already has the cap in place.
These users thanked the author Benj for the post:
Derrihj (Mon Jan 20, 2020 2:06 pm)
Rating: 5.26%
 

Derrihj
Posts: 104
Joined: Mon Jul 09, 2018 12:43 pm
Has thanked: 21 times
Been thanked: 12 times
Contact:

Re: Real time Hourly Device Control

Postby Derrihj » Sat Jan 25, 2020 8:03 pm

Many thanks goes out to medelec35, i always say its Educative to have you around and Yes it is also thanks to Benj,my project was a success.After i remade the PCB this time with an external oscillator it turned out perfect, you can hardly see a difference if compared with a real physical clock in-fact you can not see any difference ive run it for hours and its wonderful.I gave this device a name as SSD (System Service Dailer) ok You enter the hours on a keypad that you want a system to run and after those hours the system will be cutoff from power and request for servicing.I used the MCU eeprom to store hours used to keep that record even if power to the system is swtched off.There is a password requested before you can enter new service run time, you can enter hours from 1 hour to 9000 hours there is an option of timing only Minutes from 1 minute to 60 minutes also entered using a keypad after you have provided a correct password,you can also change the password as needed.I did the password thing in this project so that only the operator or engineer can change the service run time of any system. Check out the Pictures of my finished project will upload a video of it in action soon if possible and show how it works, guys Flowcode is intresting.
Attachments
20200125_202848.jpg
20200125_202848.jpg (140.44 KiB) Viewed 298 times
20200125_202838.jpg
20200125_202838.jpg (142.61 KiB) Viewed 298 times
20200125_202759.jpg
20200125_202759.jpg (136.57 KiB) Viewed 298 times
Last edited by Derrihj on Sat Jan 25, 2020 8:13 pm, edited 1 time in total.
These users thanked the author Derrihj for the post (total 3):
medelec35 (Sat Jan 25, 2020 8:12 pm) • AbhijitR (Sun Jan 26, 2020 5:17 am) • Benj (Mon Jan 27, 2020 11:24 am)
Rating: 15.79%
 

Derrihj
Posts: 104
Joined: Mon Jul 09, 2018 12:43 pm
Has thanked: 21 times
Been thanked: 12 times
Contact:

Re: Real time Hourly Device Control

Postby Derrihj » Sat Jan 25, 2020 8:10 pm

One more
Attachments
20200125_203006.jpg
20200125_203006.jpg (141.7 KiB) Viewed 297 times
These users thanked the author Derrihj for the post:
Benj (Mon Jan 27, 2020 11:24 am)
Rating: 5.26%
 

User avatar
medelec35
Valued Contributor
Valued Contributor
Posts: 8533
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2456 times
Been thanked: 3522 times
Contact:

Re: Real time Hourly Device Control

Postby medelec35 » Sat Jan 25, 2020 8:25 pm

Hi Derrihj,
Derrihj wrote:Many thanks goes out to medelec35, i always say its Educative to have you around

It's a pleasure & glad I have helped.
Your project sounds interesting and would love to see a video if it working and perhaps compared to a clock.
What tolerance crystal did you opt for?
These users thanked the author medelec35 for the post:
Benj (Mon Jan 27, 2020 11:26 am)
Rating: 5.26%
 
Martin

If you read a post that is useful, please show appreciation by clicking on thumbs up Icon.

Derrihj
Posts: 104
Joined: Mon Jul 09, 2018 12:43 pm
Has thanked: 21 times
Been thanked: 12 times
Contact:

Re: Real time Hourly Device Control

Postby Derrihj » Sat Jan 25, 2020 8:33 pm

Its a 8MHz crystal, i got these from china but i even dont know its tolorence coz ive learned this tolorence thing about crystal oscillators from you so when i was buying them i had no idea about tolorence but when i measured it with a crystal tester it was showing 7.997MHz
Last edited by Derrihj on Mon Jan 27, 2020 10:58 pm, edited 1 time in total.

Derrihj
Posts: 104
Joined: Mon Jul 09, 2018 12:43 pm
Has thanked: 21 times
Been thanked: 12 times
Contact:

Re: Real time Hourly Device Control

Postby Derrihj » Sat Jan 25, 2020 10:22 pm

There is something i want to add in this project and that is a GSM modem,when you look at my project there are 4 pins next to the LCD connector two are for 5v out and the other two are TX and RX pins but at the moment are grounded thru two pull down resistors.When the GSM is connected i would like it to work in this way: Take for example there is a system installed somewhere may be some organisation's AC generator with my device in place,so when i make a phone call to the GSm connected to my device the GSM cancels the call and in the next 2 seconds or so the GSM sends a message to my phone asking to type password then i send the numbers in the exact order of the saved password in my device and the GSM recieves them,sends it to the MCU to compare it with the correct password then if the two are a perfect match, the GSM sends the system info to my phone like;
SHr = 250 (Set Hours)
SRHr = 10 (System Run Hours)
SRM = 2 (System Run Minutes)
SRS = 15 (System Run Seconds)

Just like that which shows that the system has so far run for 10 hours,2 minutes and 15 seconds out of the set "250" hours for example. Then i can be able to change the run time,stop the operation of the system or run the system with just a simple message from my phone to the Device installed miles away.
Last edited by Derrihj on Mon Jan 27, 2020 11:14 pm, edited 1 time in total.
These users thanked the author Derrihj for the post:
Benj (Mon Jan 27, 2020 11:25 am)
Rating: 5.26%
 

Derrihj
Posts: 104
Joined: Mon Jul 09, 2018 12:43 pm
Has thanked: 21 times
Been thanked: 12 times
Contact:

Re: Real time Hourly Device Control

Postby Derrihj » Mon Jan 27, 2020 3:45 pm

Thanks guys
Last edited by Derrihj on Mon Jan 27, 2020 3:47 pm, edited 1 time in total.

Derrihj
Posts: 104
Joined: Mon Jul 09, 2018 12:43 pm
Has thanked: 21 times
Been thanked: 12 times
Contact:

Re: Real time Hourly Device Control

Postby Derrihj » Mon Jan 27, 2020 3:46 pm

Thanks guys for your response, again guys i will need your help with the GSM part as ive explained above any kind of help it can be a flow chat any, i can start and build on that.