CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

Temperature controller with PIC18F452
Goto page 1, 2  Next
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
artohautala



Joined: 17 Nov 2011
Posts: 187

View user's profile Send private message Send e-mail

Temperature controller with PIC18F452
PostPosted: Wed Nov 08, 2017 8:42 am     Reply with quote

Hi guys,

I'm trying to make very stabilized temperature oven for crystal oscillator.

Motivation:
[...for my very accurate (big maybe huge!) clock without DCF77 (Germany Mainfingen https://www.ptb.de/cms/en/ptb/fachabteilungen/abt4/fb-44/ag-442/dissemination-of-legal-time/dcf77.html ) because I'm living in periphery
in Finland it's not working very well here ... sometimes work sometimes not ...)
]

So I'll be happy if I get some advice to make rather accurate temperature controller with PIC18F452. I'm planning to use KTY-121 for
temperature sensing and PWM controlled 10 ohms/5 W resistor for heating that oven... ( PWM (is switched with 2SK2231 fet).

So I'll be very pleased if someone will advise me how to set those mathematical (I'm very poor in maths!) P, I and D parameters
to get things work !

All the best for you all Smile

-arto -
newguy



Joined: 24 Jun 2004
Posts: 1899

View user's profile Send private message

PostPosted: Wed Nov 08, 2017 9:34 am     Reply with quote

Read this first: http://www.wescottdesign.com/articles/pid/pidWithoutAPhd.pdf

That will give you a good grasp of a PID control loop and how to properly tune it.

Regarding a high precision oscillator - never done that before. I have done simple RTC layouts that have had okay accuracy (~30 seconds drift in a month), but nothing that was highly accurate.
Ttelmah



Joined: 11 Mar 2010
Posts: 19195

View user's profile Send private message

PostPosted: Wed Nov 08, 2017 9:45 am     Reply with quote

Buy an OXCO.

You can't just add temperature regulation to a standard crystal for really good stability. Problem is the ageing effects will be larger than the temperature effects. Proper OXCO's use SC cut crystals, which have _worse_ temperature behaviour than standard crystals, but give better ageing behaviour. Off the shelf modules have nice little insulated and shielded cases, and can typically give 10PPB quite easily, and even 1PPB in some cases. 10PPB modules are under $50.
artohautala



Joined: 17 Nov 2011
Posts: 187

View user's profile Send private message Send e-mail

PostPosted: Wed Nov 08, 2017 10:11 am     Reply with quote

Ttelmah wrote:
Buy an OXCO.

You can't just add temperature regulation to a standard crystal for really good stability. Problem is the ageing effects will be larger than the temperature effects. Proper OXCO's use SC cut crystals, which have _worse_ temperature behaviour than standard crystals, but give better ageing behaviour. Off the shelf modules have nice little insulated and shielded cases, and can typically give 10PPB quite easily, and even 1PPB in some cases. 10PPB modules are under $50.


Hi Ttelmah,

Thank for your answer !

Yes you are right when you told me to purchase OXCO ...
but I'm old pensioner and I like to test all kinds of interesting electronics ... for hobby purposes ...
So I like to study mathematics of temperature controllers ... I know it's not very "sexy" but very interesting.

and how to use those PID controller algorithms to program PIC18F452 (or other similar PIC's)
data from PIC A/D (0...1023) and use that data to PWM to control heater resistor ... to get stable temperature ...

all the best
-arto-
Ttelmah



Joined: 11 Mar 2010
Posts: 19195

View user's profile Send private message

PostPosted: Wed Nov 08, 2017 1:52 pm     Reply with quote

Fair enough. You'd need to get technical specs of the ageing characteristics of the crystal you intend to use, and build in compensation for this.

You do realise it is actually much cheaper and simpler to use a TXCO?. These are easily 10* better than ordinary crystals and now don't cost much more.

On the regulation, you'd almost certainly find you can get +/- 0.1 degree without using PID at all. Just a dynamic P term. Just measure the temperature, and if it is below the required level turn on a heater with the PWM changing using a factor based on how far the temperature is away from the required level. Slowly integrate the PWM level that is giving the required output, and use this as the baseline, and turn down the P factor as you do this. Effectively a long term 'I' base level, and a very small 'P' term once the level is close to stable.
temtronic



Joined: 01 Jul 2010
Posts: 9081
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Thu Nov 09, 2017 6:14 am     Reply with quote

Sounds like you want the PIC project to warm to be happy.
Can I assume this is powered from the 'mains' and not batteries ? In either case consider...
Putting the PIC into a small insulated box. 1" of Styrofoam is nice, 2" is better! If you take the time, you can carve interlocking joints so virtually no heat escapes. This keeps heat local to the PIC
use an on-board series regulator like the 7805. Heat from the PSU will warm the PIC. Effectively, you've got a 'free' source of heat.

You may find that this is enough to keep the PIC happy.

For my remote energy control systems, I used a small 'beverage' sized cooler for the test chamber. About the 1/2 the size of a PC tower, only needed to drill 1/4" hole for the RJ45 cable to get in. The PIC was mounted on the lid and since hot air rises, it was always in the 'hot' zone. LM34 temp sensors (3) detected local PCB temp, 'floor' temp and 7805 heatsink temp.

You can spend months seeing how this works... mine spent a week in the freezer collecting data. THAT is when I learned to save data in CSV format so that Excel could import and display data INSTANTLY.

You may find as I did that you won't need the heater, maybe not the txco if the enclosure is built right.

Also... temperature control is a slow process. You don't need 1000's of readings per second ! Once per minute is probably fine. It really depends on the heat loss. The higher the loss, the quicker the controller needs to be to resupply the heat.

Just food for thought.

Jay

Jay
artohautala



Joined: 17 Nov 2011
Posts: 187

View user's profile Send private message Send e-mail

PostPosted: Thu Nov 09, 2017 9:22 am     Reply with quote

temtronic wrote:

Sounds like you want the PIC project to warm to be happy.
Can I assume this is powered from the 'mains' and not batteries ? In either case consider...
Putting the PIC into a small insulated box. 1" of Styrofoam is nice, 2" is better! If you take the time, you can carve interlocking joints so virtually no heat escapes. This keeps heat local to the PIC
use an on-board series regulator like the 7805. Heat from the PSU will warm the PIC. Effectively, you've got a 'free' source of heat.

You may find that this is enough to keep the PIC happy.

For my remote energy control systems, I used a small 'beverage' sized cooler for the test chamber. About the 1/2 the size of a PC tower, only needed to drill 1/4" hole for the RJ45 cable to get in. The PIC was mounted on the lid and since hot air rises, it was always in the 'hot' zone. LM34 temp sensors (3) detected local PCB temp, 'floor' temp and 7805 heatsink temp.

You can spend months seeing how this works... mine spent a week in the freezer collecting data. THAT is when I learned to save data in CSV format so that Excel could import and display data INSTANTLY.

You may find as I did that you won't need the heater, maybe not the txco if the enclosure is built right.

Also... temperature control is a slow process. You don't need 1000's of readings per second ! Once per minute is probably fine. It really depends on the heat loss. The higher the loss, the quicker the controller needs to be to resupply the heat.

Just food for thought.

Jay


Hi Jay,

and thank you for your good ideas !

I know thermal control is very very slow process !

OK

so I thought to make thermal insulated oven ... in oven there is components:

- crystal 16 Mhz
- 74HCT14 ic to make crystal oscillate
- 2x BB139 capacitance diodes in parallel to fine control crystal frequence
- 1.8...22pF adjustable trimmer capacitor to adjust raw control
- 5 k 10 turns trimmer to trim those BB139's
- KTY1-121 thermal sensor
- ADC 12 or 16 bits to get thermal data from sensor thermal insulated oven to PIC processor.

So I think there's no need to put the PIC processor into oven because I don't use the A/D converter of PIC because it's resolution is
not enough accurate.
So I'm gonna fine tune with capacitance diodes and trimmer 5k those long term variations.

I know cheap quarts wrist clock is about 2...4 seconds/month accurate ... I hope that
I can make clock to be about 2...4 / year
but I don't know if it's realistic... on the other hand clock will be at rather stable room temperature all the time.

All the best for you and all the people !

Smile

-arto-
Ttelmah



Joined: 11 Mar 2010
Posts: 19195

View user's profile Send private message

PostPosted: Thu Nov 09, 2017 11:15 am     Reply with quote

Seriously the PIC ADC is plenty accurate enough for any temperature control you will want. You won't achieve anything better.....

First problem is that high bit ADC's (16bit for example), are generally _audio_ ADC's. They give this as resolution not accuracy (very important difference). Then the actual accuracy of the ADC is dependant on it's reference. Even a 0.1% accuracy reference is an expensive and rare part. Then you have the accuracy of your sensor itself.

If you look at something like the Honeywell LM73, you see it being advertised as a 11 to 14bit temperature sensor, but though it's resolution is 0.03125C, it's accuracy is only +/-1.45C.

To get better than 10bit accuracy, you need the total errors from everything in the whole system to be <0.1%. Genuinely achieving beyond 12bit (many PIC's offer an ADC with this resolution), involves really careful analog design....
temtronic



Joined: 01 Jul 2010
Posts: 9081
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Sat Nov 11, 2017 6:17 am     Reply with quote

You may find it's easier to put the PIC and parts into the 'oven'. Splitting it into two sections means wires, at least 4 between them so you risk getting EMI of some sort getting in and changing the ADC input. Also ANY analog lines need special attention when reading over 8-10 bits even IN a nickle plated steel box made of 1/8" plate. BTDT !!
To expand your project you could have one PIC in the oven, send time data to the 'display' PIC via serial. This could even be wireless using say HC-12 modules. So ONE PIC does the time keeping and several remotes would show you the time.

I have an 18F46K22 driving a 'big' LED display. The digit is 8.5x11 (size of paper), each segment is a strip of 4 LEDs. I use an uln2003 to interface the PIC to the 12V LED segments. This project is an updated version of the 'monodigichron' clock from 70's Popular Electronics.

More 'food for thought', you can get I2C RTC using DS1307 for about $3, complete with battery AND some EEPROM. It's an 'off the shelf' module I use since it's cheaper than buying the individual parts ! And NO wiring errors !!

PICs are addictive....

Jay
Ttelmah



Joined: 11 Mar 2010
Posts: 19195

View user's profile Send private message

PostPosted: Sat Nov 11, 2017 6:51 am     Reply with quote

It's worth also thinking about the temperature to use.
The norm is to decide on a temperature just a little above the highest ambient, and regulate at this. So if the highest temperature at your site is (say) 32C, then allow a couple of degrees for heating effects in the electronics, and then a small margin, and aim to regulate at perhaps just under 40C.
Now the commonest AT cut 'watch' crystals have a cubic temperature co-efficient. The ones normally used for watch crystals are cut at phi/theta of 35/18 degrees, which gives a relatively flat 'plateau' between about 0C and 40C, making them pretty unaffected by temperature in this region. So if you regulate near the top of this you are regulating inside a region where the behaviour is already little affected by temperature.
On ageing, lower frequency crystals exhibit much less ageing than higher frequency types, and a crystal will exhibit 90% of it's ageing over the first four weeks of use. so also worth perhaps doing an initial soak for a few weeks before final adjustment. Glass encapsulated crystals typically exhibit perhaps 1/10th the ageing effects of metal encapsulated types. Provided mechanical forces are not a problem, therefore well worth choosing glass types if possible.
temtronic



Joined: 01 Jul 2010
Posts: 9081
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Sat Nov 11, 2017 8:58 pm     Reply with quote

DS3231 is an accurate RTC chip, +-2 minutes per year from Dallas Semi of a very wide range of temps (way too cold to way too hot...).

Might be an option for you. off the shelf, easy to use, battery backup of course.

Jay
Ttelmah



Joined: 11 Mar 2010
Posts: 19195

View user's profile Send private message

PostPosted: Sun Nov 12, 2017 1:54 am     Reply with quote

As another comment, if he wants 'near atomic' accuracy, and the MSF/DCF transmissions are unreliable, how well is GPS received?.
GPS can give you really accurate clock information, the downside compared to MSF/DCF, is the higher power requirements of the receiver.
A standard GPS module, linked to his PIC, with it running a standard RTC with a watch crystal, and he can every hour read the time from the GPS, and adjust the RTC. Include an offset for the time needed to trigger/read the serial and decode it, and he can have time accurate to a few mSec at any time of the year. Short term loss of GPS won't matter since the RTC will merrily keep going, and when it comes back time will then re-synchronise.
temtronic



Joined: 01 Jul 2010
Posts: 9081
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Sun Nov 12, 2017 6:22 am     Reply with quote

Mr. T got me thinking ( dang, no wonder I can't finish projects....lol). I see 'entry level' GPS modules for under $15 CDN.
Have to admit GPS would be a nice,accurate solution, No need for battery backup to keep RTC going, no 'oven' box required, no fancy temp-adc-pwm control software.
Eliminating the ADC stuff is nice as high bit ADC is a tricky design challenge.Not having the 'oven' simplifies the project and overall software is easier.

side note:
I have a few LaCrosse Technology clocks with weathermen on them. They all 'sync' to some RF signal from somewhere once per day so if you update every hour you'll always be on time.

just more 'food for thought'.

Jay
artohautala



Joined: 17 Nov 2011
Posts: 187

View user's profile Send private message Send e-mail

PostPosted: Sun Nov 12, 2017 7:26 am     Reply with quote

Ttelmah wrote:
As another comment, if he wants 'near atomic' accuracy, and the MSF/DCF transmissions are unreliable, how well is GPS received?.
GPS can give you really accurate clock information, the downside compared to MSF/DCF, is the higher power requirements of the receiver.
A standard GPS module, linked to his PIC, with it running a standard RTC with a watch crystal, and he can every hour read the time from the GPS, and adjust the RTC. Include an offset for the time needed to trigger/read the serial and decode it, and he can have time accurate to a few mSec at any time of the year. Short term loss of GPS won't matter since the RTC will merrily keep going, and when it comes back time will then re-synchronise.


Hi,
Ttelmah,

LOT OF thank you for GOOD IDEA to make use of GPS Smile

I just tested my (old) car navigator Garmin nuvi205W. It works well in my car and I found it works indoors too at my home
though it is just now very bad weather. So I think some GPS module works too as good as my Garmin car navigator do indoors at my home.
Please tell me how to link those parts together. So how I can get time information from GPS instead of place coordinates data and then set Real Time Clock module ?

What GPS module is good for my purpose ?

What RTC module do you recommend? (I have experience with DS1307Z I2C battery backup module from Microbot and I found it is rather inaccurate in practice but maybe it don't matter if I set it to right time every now and then).

So when I think different ways to make rather accurate digital wall clock I found there's many possibilities to make it.

I THINK THIS GPS IDEA IS VERY GOOD !

all the best
-arto-

... sorry this is bullshit:

< I just tested my (old) car navigator Garmin nuvi205W ... it works well in my car and I found it works indoors too at my home...>

My navigator can not find satellites indoors.

I do not know if there's better GPS modules as in my Garmin navigator.
temtronic



Joined: 01 Jul 2010
Posts: 9081
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Sun Nov 12, 2017 8:35 am     Reply with quote

Here's a link to what I've been using, connects to PIC via I2C:

https://www.banggood.com/DS3231-AT24C32-IIC-High-Precision-Real-Time-Clock-Module-For-Arduino-p-81066.html

Only $3 CDN and comes WITH battery ! One actually had a rechargeable battery in it !! I bought 5 pcs.

I haven't done any long term testing, though the 'specs' says it's a lot better than the DS1307

GPS NEEDS a clear 'line of sight', so a metal roof kills the signals. The only way around that is to put GPS + HC-12 outside and transmit to the PIC time project.

Jay
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group