1sec puls!

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 5.
To post in this forum you must have a registered copy of Flowcode 5 or higher.

Moderator: Benj

Post Reply
jgu1
Posts: 1333
Joined: Tue Oct 06, 2009 9:39 am
Has thanked: 1135 times
Been thanked: 299 times

1sec puls!

Post by jgu1 »

Hi All!
I have tried to make 1 sec pulse with a pic. It is also no problem. But I would like to use a watchcrystal 32.768 kHz crystal. When I use a watchcrystal 32.768 kHz crystal,
the oscillator will not run. No matter how I configure crystal settings in the config it does not work. Is it not possible to use such a "slow" crystal directly on Pic. or should we use C code with options for OSCON. Perhaps it can not be done with all types Pic :?: .
If it can be done with watchcryslat 32.768 kHz is there anyone who will be helpful to change the attached example. It could even be a 12f pic or similar
I have tried searching on the subject, but without success.

Thank´s in advance.

Jorgen

kersing
Valued Contributor
Valued Contributor
Posts: 2045
Joined: Wed Aug 27, 2008 10:31 pm
Location: Netherlands
Has thanked: 553 times
Been thanked: 1081 times

Re: 1sec puls!

Post by kersing »

Which PIC are you trying to use?
“Integrity is doing the right thing, even when no one is watching.”

― C.S. Lewis

jgu1
Posts: 1333
Joined: Tue Oct 06, 2009 9:39 am
Has thanked: 1135 times
Been thanked: 299 times

Re: 1sec puls!

Post by jgu1 »

Hi Kersing!

Sorry I forgot to attach my FC. Hereby.

Jorgen
Attachments
1sec.fcf
(9.5 KiB) Downloaded 276 times

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

Re: 1sec puls!

Post by medelec35 »

Hi Jorgen,
I have an idea for a very accurate 1 second pulse indeed (Should be as accurate as a RTC).
Connect a 65.536KHz crystal (Available from Mouser Electronics for example) to Timer 1 osc (not main osctillator leave that at 4,8 19.66MHz, 32MHz etc).
leave timer 1 prescaller at 1:1 the timer 1 will interrupt at exactly one second.
If you connect a 32.768KHz crystal to timer1 just like this:
Timer1 osc running at 32.768KHz.png
(43.75 KiB) Downloaded 4013 times
Then timer1 will interupt every 1/32768*65536 = 2 seconds
This is because Timer 1 being a 16bit timer then with prescaller on 1:1 acts as a divide by 65536 counter.
To get 1 second with 32.768KHz you need a divide by 32768 counter as what is probably in watches.

With 65.536KHz crystal Then timer1 will interupt every 1/65536*65536 = 1 second
Since using Transition on T1CKI external pin then interrupt frequency shown will not be correct as this is assuming your using main osc to control timer 1

So conclusion, I don't believe it can be done using a 32.768KHz crystal.
Sorry

Hope this makes sense.

Martin
Martin

kersing
Valued Contributor
Valued Contributor
Posts: 2045
Joined: Wed Aug 27, 2008 10:31 pm
Location: Netherlands
Has thanked: 553 times
Been thanked: 1081 times

Re: 1sec puls!

Post by kersing »

Hi Martin,

How about preloading timer1 so it interrupts once every 32768 pulses?

Jac
“Integrity is doing the right thing, even when no one is watching.”

― C.S. Lewis

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

Re: 1sec puls!

Post by medelec35 »

Hi Jac,
Trouble with preloading, will waste a few cycles, so time will no longer be as accurate.
I remember reading this in the past that's why I ruled it out before posting:

It maybe accurate enough so worth a shot?

If I can find the information regarding preloading timer 1 I will post it.
Martin

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

Re: 1sec puls!

Post by medelec35 »

medelec35 wrote:Trouble with preloading, will waste a few cycles, so time will no longer be as accurate.
I remember reading this in the past that's why I ruled it out before posting:
Not sure where original information on this is, but I have found:
Reloading the TIMER adds a few instruction cycles to the total time lapse between interrupts.
The simplest way it to let TIMER1 run free, but that will give you an overflow interrupt each 2 seconds, if your project can live with that good (most alarm clocks do).
Otherwise you will have to take into acount the extra instruction cycles when calculating the reload value for the timer.
If you can't get an integer value to reload the TIMER, than you will need to reload it with a correction value every 'n' cycles.
http://www.microchip.com/forums/m672828.aspx
(Post 10).
It may or may not be true, but reading this in more than one location gives me doubts if using 32.768KHz with preloding of timer 1 is going to be accurate.


Martin
Martin

jgu1
Posts: 1333
Joined: Tue Oct 06, 2009 9:39 am
Has thanked: 1135 times
Been thanked: 299 times

Re: 1sec puls!

Post by jgu1 »

Hello Both!

Thank you for your trouble and help. Martin then I learned something new again :D .I did not know it was possible in this way. I would order a crystal asap and test your example. Very interesting. Hope I can go again if I get the problem with the program. :D

Best regard

Jorgen

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

Re: 1sec puls!

Post by medelec35 »

Hi Jorgen,
jgu1 wrote:Hope I can go again if I get the problem with the program.
Sure that's what these forums are about, Helping people when they get stuck.
I have not used this method myself, its only theory and calculations which lead me to believe about 65.536KHz crystal .
So I hope in right. :)
Martin

jgu1
Posts: 1333
Joined: Tue Oct 06, 2009 9:39 am
Has thanked: 1135 times
Been thanked: 299 times

Re: 1sec puls!

Post by jgu1 »

Hi Again!

I will try if it can be managed for me to make a program with your example.

But I thought that it was possible to use a 32.768khz crystal as a master oscillator.

Thank you Martin

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

Re: 1sec puls!

Post by medelec35 »

a 32.768khz crystal as a master oscillator will be of no use just as it is, especially with 16F88.
First of all oscillator is divided by 4 before going to timer interrupts if using main osc as a source.
As explained before with 32.768khz connected to Timer 1 and using 1:1 prescaller then the interrupt will trigger every 2 seconds.

With 32.768khz crystal as a master oscillator, Divide by 4 then 1 to 1 prescaller, then interrupt will be triggered every 8 seconds.
Also LCDs and other peripherals may fail to work correctly?

So only option is to use 32.768khz crystal as a master oscillator on a device which has PLL which will allow the osc frequency to be multiplied to a more reasonable level.
It should be then a matter of choosing correct PPL frequency and divider to allow timer interrupt to interrupt every second or 1/2 second etc.
The 18F4455 springs to mind as that has CPU Sys Clock select of divide by none, 2,3, or 4 and Oscillator which has divide by non,2,3,4,5,6,10 & 12.
You maybe able to find a target divide which does the same with less pins?

I'm no expert on this but I say its possible a 32.768khz crystal as a master oscillator.
Martin

jgu1
Posts: 1333
Joined: Tue Oct 06, 2009 9:39 am
Has thanked: 1135 times
Been thanked: 299 times

Re: 1sec puls!

Post by jgu1 »

Hi again Martin!

Thanks again for your explanation. :D I will order a new crystal and try your idea.

Jorgen.

Post Reply