Real time Hourly Device Control

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

Moderator: Benj

Post Reply
Derrihj
Posts: 348
Joined: Mon Jul 09, 2018 12:43 pm
Has thanked: 67 times
Been thanked: 33 times
Contact:

Real time Hourly Device Control

Post by Derrihj »

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 199 times

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: Real time Hourly Device Control

Post by medelec35 »

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.
Martin

Derrihj
Posts: 348
Joined: Mon Jul 09, 2018 12:43 pm
Has thanked: 67 times
Been thanked: 33 times
Contact:

Re: Real time Hourly Device Control

Post by Derrihj »

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.

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: Real time Hourly Device Control

Post by medelec35 »

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

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: Real time Hourly Device Control

Post by medelec35 »

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
(37.36 KiB) Downloaded 1085 times
Martin

Derrihj
Posts: 348
Joined: Mon Jul 09, 2018 12:43 pm
Has thanked: 67 times
Been thanked: 33 times
Contact:

Re: Real time Hourly Device Control

Post by Derrihj »

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?

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: Real time Hourly Device Control

Post by medelec35 »

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%.
Martin

Derrihj
Posts: 348
Joined: Mon Jul 09, 2018 12:43 pm
Has thanked: 67 times
Been thanked: 33 times
Contact:

Re: Real time Hourly Device Control

Post by Derrihj »

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: 348
Joined: Mon Jul 09, 2018 12:43 pm
Has thanked: 67 times
Been thanked: 33 times
Contact:

Re: Real time Hourly Device Control

Post by Derrihj »

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 204 times

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

Re: Real time Hourly Device Control

Post by Benj »

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.

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

Re: Real time Hourly Device Control

Post by Benj »

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 206 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.

Derrihj
Posts: 348
Joined: Mon Jul 09, 2018 12:43 pm
Has thanked: 67 times
Been thanked: 33 times
Contact:

Re: Real time Hourly Device Control

Post by Derrihj »

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: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: Real time Hourly Device Control

Post by Benj »

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.

Derrihj
Posts: 348
Joined: Mon Jul 09, 2018 12:43 pm
Has thanked: 67 times
Been thanked: 33 times
Contact:

Re: Real time Hourly Device Control

Post by Derrihj »

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 5953 times
20200125_202838.jpg
20200125_202838.jpg (142.61 KiB) Viewed 5953 times
20200125_202759.jpg
20200125_202759.jpg (136.57 KiB) Viewed 5953 times
Last edited by Derrihj on Sat Jan 25, 2020 8:13 pm, edited 1 time in total.

Derrihj
Posts: 348
Joined: Mon Jul 09, 2018 12:43 pm
Has thanked: 67 times
Been thanked: 33 times
Contact:

Re: Real time Hourly Device Control

Post by Derrihj »

One more
Attachments
20200125_203006.jpg
20200125_203006.jpg (141.7 KiB) Viewed 5952 times

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: Real time Hourly Device Control

Post by medelec35 »

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?
Martin

Derrihj
Posts: 348
Joined: Mon Jul 09, 2018 12:43 pm
Has thanked: 67 times
Been thanked: 33 times
Contact:

Re: Real time Hourly Device Control

Post by Derrihj »

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: 348
Joined: Mon Jul 09, 2018 12:43 pm
Has thanked: 67 times
Been thanked: 33 times
Contact:

Re: Real time Hourly Device Control

Post by Derrihj »

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.

Derrihj
Posts: 348
Joined: Mon Jul 09, 2018 12:43 pm
Has thanked: 67 times
Been thanked: 33 times
Contact:

Re: Real time Hourly Device Control

Post by Derrihj »

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

Derrihj
Posts: 348
Joined: Mon Jul 09, 2018 12:43 pm
Has thanked: 67 times
Been thanked: 33 times
Contact:

Re: Real time Hourly Device Control

Post by Derrihj »

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.

Post Reply