DS1307 and DS3231 RTC’s Running Fast

Ok,

So I made a clock. A Big Clock.

(The Veroboard Construction was Version 1, that used an Atmega328 uC. What a pain! If you do not have the supporting Circuitry (i.e. the USB Interface Chip to program), it is very difficult to update the program.)

Version 2 uses a Wemos D1 Mini Module, which gives me the easy programming interface, and the ability to do NTP Time Syncs, and I can also just do program updates through the Network.

    

Basically the uC uses a RTC Module to keep track of the time, and then pushes the outputs through Shift Register LED Drivers (Max6971), which then runs Segments made out of LED Strips.

The RTC Module keeps the realtime clock running, even when power is removed to the clock itself. So that whenever the clock is turned on, it has the right time (or that is what it was supposed to be doing).

On site, the clock was only powered for about 10 – 12 hours a week, and the rest of that time it was powered off, with the RTC just keeping track of time.

The problem I was having with the clock is that it was running fast, by that I mean a minute or so fast per week!. Trying additional decoupling caps on the RTC module did not help.

I originally was using a DS1307 RTC Module,

Which is not a Temperature Compensated device, so I expected it not to be completely accurate, but not to such an extent. So I tried another one of the same modules, same result.

Ok, some more research lead me to the DS3231 RTC Module,

Temperature Compensated, Internal Crystal Oscillator, with a rated accuracy of +- 2ppm (0 to 40deg). So that should be accurate to within 1 minute a year.

Tried it, and same result. 6 Weeks, and the clock was running 6 minutes fast!

Eventually a lot of googling helped me find my problem. Here is my code :

void loop () {
 while (CurrentS==PrevS) { //HOLD UNTIL SECOND TICKS OVER
 DateTime now = rtc.now();
 CurrentS = now.second();
 ...
 } //loop

Which means that the uC continually polls the RTC, and then only once the second bit changes, does the rest of the code run. This means that it is hammering the RTC module thousands of times a second. Which the RTC module does not like, and it causes the internal registers to glitch.

All I had to do was change the way my code worked, I enabled the square wave output on the RTC, and connected that to my uC. Which now meant the uC only queried the RTC when the seconds had changed

void loop () {
 sqwstate = digitalRead(RTCsqwpin);
 // compare the buttonState to its previous state
 if (sqwstate != lastsqwstate) {
  if (sqwstate == HIGH) { // We have had a Seconds Tick
   DateTime now = rtc.now();
   Serial.print(now.hour(), DEC);
   Serial.print(':');
   Serial.print(now.minute(), DEC);
   Serial.print(':');
   Serial.print(now.second(), DEC);
   Serial.println();

DoTime();
...
}

 

And Bingo, that fixed the problem. I last set that clock on the 29 January 2017. It is now 4 April 2017, and the clock is still accurate to within 1 second. so that is a Success.

Hope this little tip can help somebody else out.

P

Superhouse.tv Clickbait Post, or End of the World

So, the other day I am going through my normal work day, when my phone makes the beeping message tone thing, to tell me that there is something important that I must look at.

It is a Tweet or Post by Jon Oxer from Superhouse.tv (an awesome Home Automation and Electronics Youtube Channel based in Australia). And the Title of the Post is “SuperHouse Vlog #50: The future of SuperHouse“.

Now, that channel had been quiet for a week or two (probably due to the holiday season), so as soon as I saw the title, my heart sank. To me that title meant the End of the World, or at least of that channel, and also the end of the inspiring content it provides.

I could barely concentrate through out the rest of the work day (and I can’t just stop and watch a 10 Minute video whenever I feel like it, ‘Ain’t nobody got time for that….’. All I could think of is how that resource is going the way of the Dodo.

Well, Eventually I got home, put my feet up, and could watch the Video…

It was not the End of the World as we know it. but instead it was………………… Well, watch the video below to see what it was.

 

Jaycar Ripping off Freetronics Products

Just came across this video from Freetronics (http://www.freetronics.com.au/)

Freetronics is a small Australian Company (Basically a one man show), that spent many days designing an Arduino Kit, complete with the Arduino, Components, Manual, Custom box and Foam.

One of their retailers, Jaycar, was selling this kit of theirs. Then all of a sudden Jon Oxer from Freetronics finds out that they (Jaycar) have now made their own branded copy of the kit, and are selling that instead. And worst of all, everything is copied almost exactly, even down to the Box, Foam, and almost Word-for-Word in the manual.

So Jaycar obviously decided that they can make more profit by cutting out the small company that did all the development. Very nice Jaycar!

So, if you can, rather buy from Freetronics.com.au instead of Jaycar. That way you can be sure that you are supporting a small business that is trying to make an income, instead of a Large Company just interested in Profits….

 

New Stuff Arriving Soon

Just a heads up, I have several videos planned, and will start shooting in the next day or 2.

I also have some things on their way from Aliexpress, that we will be looking at, taking apart, upgrading, and putting to good use.

So please remember to come back to this page now and then, or subscribe to the youtube channel ShoutingElectronics , That way you will get notified of when I stick more content up (and will also get me a few steps closer to having a shorter URL for my Youtube Channel…….

You can also hit us up on Twitter (@ShoutingElect) or Facebook (https://www.facebook.com/ShoutingElectronics/)

And Remember to check out the other Electronics Blogs I have listed, they are good, and have provided me with lots of inspiration already.

 

P

Check out my previous Youtube Vids

Yep, This is from my own personal Youtube Channel, before I decided to launch ShoutingElectronics, but still, give them a watch…..

Other Blogs

Hey, While you are here, I thought I should give you some more Blogs / Sites to try out (just click on the Logo)

EEVblog                      eevblogshortlogowithhand-75h-pantone

Superhouse.tv            superhouse

Mikes Electric Stuff    mes

Julian Ilett                    julian

Big Clive                       bigclive

Microchip Curiosity Board

The Other day I received a RoadTest Microchip Curiosity Board from Element14/Microchip.

The Board is quite a nice one :

board_large

Here is my first Impressions, review, and a Quickstart guide on using this nicely thought out board :

What it is : A development/demo board with built in Pickit Programmer.
This board is compatible with the Mplab Code Configurator by Microchip.

For a long time many hobbyists/professionals have struggled with the configuration of the
built-in peripherals in Microchip PIC Products (Jumping Between Datasheets, Appnotes,
Forums, Google Searches, etc, just to figure out that you forgot to set 1 little register for the
peripheral).
The Code Configurator is an easy click and fill in system that allows you to configure the PIC
and the peripherrals quickly and easily.

By using the Code Configurator, most of the peripheral setup is done by the software, so
you can concentrate on the Non-Boring parts of your coding.

The Curiosity system comes in a smart looking Red, Black and White Cardboard box.
In the box you have the Curiosity Board itself (in a Static Dissipative Grey Packet),
you also get some polystyrene packing peanuts (that have the same texture as cheese-puffs,
but no flavour).
Also included is a Warranty Registration Card, Important Information Sheet, and Curiosity
Information Sheet.

A quick glance at the board shows that it is a decent build, with decent white silkscreen, on
a red soldermask.
The PIC Microcontroller is a 20 Pin Dip (PIC16F1619) in a socket, which makes it easy to
swap out with another type, or to replace if you manage to destroy it somehow.
There are Female Headers that allow you access to each pin of the Microcontroller.
There is a Micro Bus Section of the board, a section for an optional bluetooth module, as
well as lots of other places for Input, Output, Etc.
You will also find a capacitive mTouch button, Potentiometer for the ADC, 7 LED’s or
status/debugging/whatever you want.
You also have a MCLR/Reset Pushbutton, and general purpose Pushbutton.

This board has a builtin 5v/3.3v supply (selectable using a jumper) that gets its power via a
USB port on the underside of the board.
The USB port also works to program and communicate with the board.

Also under the board is another PIC Microcontroller to handle the USB interface and
programming. It is basically a PICKIT on board!!! That already saves a lot of space and mess
on the desk. Normally you have your computer, USB Cable to Pickit Programmer, Cables and
Converters for the Programmer, which then connects to your Dev Board/Breadboard. Now
you just have the 1 Cable. How Neat.

The baord also comes 4 standoffs (1 at each corner), and also 3 rubber feet. Dont know
why they have had this double system, because sometimes the feet are standing on the
desk, other times the standoffs…

Anyway, lets plug this thing in, and see if it works.
The PIC comes preprogrammed with a demo program, so that you can see it working
straight away.
So Plug in a Powerbank/Cellphone Charger or USB connection into the USB socket on the
board, and it comes to life.
Straight away you get a Power LED, as well as the 3v3 LED coming to life. The 16F1619 can
run from 1.8v up to 5.5v, so you do not have to worry if you have set the jumper to the
wrong place.
Pressing S1 Lights D4.
Pressing the mTouch section of the board causes D6 to light
Twiddle the Pot, and D7 changes brightness (using the ADC and PWM Peripherals)
I let my 4 year old son test that part, he loved it (after I promised him that it will not shock
him)

Now that it is working, you will probably want to play a bit with it (which is easy with the
Code Configurator)
So far there are lots of Videos on Youtube on how to use the Code Configurator, but the
steps to get started are simple:
You need to have Mplab installed on your computer (with the Code Configurator Installed),
as well as a C Compiler, so this is how you do it:

Step 1:
Go to www.microchip.com (The files you need to download are approx 700MB, so do not
download them on a Metered Connection)
If you are downloading in South Africa, then with a standard 2Mbps ADSL Line, you are
looking at over an hour to download these 2 files.
Then under ‘Design Support’ you can download the Mplab X IDE
Then under ‘Design Support’ you download the ‘C Compiler’ eg XC8

Once the files are downloaded, Install MPLAB X IDE using the default settings.
Once the MPLAB X IDE install has finished, Untick the 3 Check Boxes, and click Finish
Then Run the XC8 Installer, again using the Default settings.

Then open up the MPLAB X IDE Icon on your desktop (The Big Red X).

Click ‘File’ ‘New Project’
Then click ‘Next’

From the Device List, Select (or type in) PIC16f1619, and click Next.
We are not using a Debug Header, so just click Next.

You will now be at the Tools Selection. Make sure your Curiosity Board is plugged in!
From the Microchip Starter Kits Section, select Curiosity, and Click Next
You will then select the XC8 Compiler, and Click Next.
Give your project a name, and Click Finish

Now click ‘Tools’ and ‘Plugins’ at the top.
Select the ‘Available Plugins’ Tab, and then tick the Checkbox next to MPLAB Code
Configurator, and click INSTALL.
Click Next, Accept the Terms (you are actually supposed to read them), and Click Install

After Installing, you will need to close off and reopen MPLAB X IDE.

Now there is something Important you need to do for the Curiosity Boards built in
Programmer, you must set LVP mode.

To Open the Code Configurator, click ‘Tools’ ‘Embedded’.
Click ‘MPLAB Code Configurator’, and you are good to go.

First get rid of the Overlay that says what is where.
Click ‘System’ on the top left.
Then in the window on the right, Expand the ‘CONFIG2’ section, and check the LVP Enable section.

Then lets do something with the LED’s,
so double click on GPIO on the left. It will then load the module to the top, under system.
Double click on it
Then on the right, click the padlocks in each column, This assigns the Pins to that Module
Then in the center, tick all the pins to make them outputs, Then mark every one as ‘Start High’
Click the Program button at the top (Paper, then Arrow, Pointing to the Chip.), It will ask you if it must make a main.c file, let it do that, and once it has done a firmware upgrade to the programmer on the curiosity board, it will upload your program, and all 4 RED led’s on your board should be on.

That shows that the PIC, Onboard Programmer, and Computer are all talking fine…

So time to search some of the Youtube Vids for the Curiosity Board by Microchip, and follow along, it is really that easy…