PDA

View Full Version : Need some advice.



cphillips82
- 27th April 2008, 10:27
Hi everyone, I'm building a device which controls temperature. Currently I'm using an 18b20 to pick up the temperature and I also have to detect zero crossing on a 50hz ac waveform on portb.0 so I can fire a triac on cirtain 0-10ms periods. I'm using a 16f628 at 4meg. it is critical that the phase controling is not interupted while gathering the temp from the 18b20 however I'm having trouble due to the time being needed to access the temperature. Does anybody know if it is at all possible to do this using the interupt on portb.0 or am I just barking up the wrong tree using this 18b20 or should I use something like a 16f88 and an lm35 with some kind of voltage ref? thanks in advanced

Acetronics2
- 27th April 2008, 13:23
Hi,

No problem ... just poll the DS data line to see if conversion has ended.




'************************************************* ****************************
' Start temperature conversion
'************************************************* ****************************

mainloop: OWOut DQ, 1, [$CC, $44 ]

'************************************************* ****************************
' Check for still busy converting ( ~ 4500 fois ... )
'************************************************* ****************************

waitloop:

INPUT DQ
If NOT DQ Then waitloop

'************************************************* ****************************
' Read the temperature
'************************************************* ****************************

OWOut DQ, 1, [$CC, $BE ]

OWIn DQ, 0, [temperature.LOWBYTE, temperature.HIGHBYTE, Skip 4, count_remain, count_per_c]



Here, you won't have a Waitloop, but, say, goto your regulating loop ...

AND remember heating has "a little" ( LOL !!! ) inertia, and some AC periods more or less won't disturb the system ...
the temp data will be updated each ~ .75 s ... that's all !!!

using a MOC 3041 to drive your SCR could miraculously simplify your program ...
just an idea ...

Alain

sayzer
- 27th April 2008, 17:34
From my side, I can say couple of things.

1. If the temp resolution (and consistency) IS NOT very critical, then you can use LM35 with 12F675, and if only turn ON/OFF is on the subject (no voltage control) then you can directly fire the triac from PIC pin using zero-crossing.

2. If temp resolution (and consistency) is critical then you can use DS18B20 with 12F675 and fire the triac from PIC pin using zero-crossing. You can check the "busy" feature so that you do not wait for temp conversation.

In both cases, sensitive gate triacs will be more suitable for PIC's current sink (25mA max).
If you use regular triacs, then gate will draw about 35mA, thus a MOC type will be appropriate as Alain mentioned.

cphillips82
- 28th April 2008, 02:26
thanks for your reply s. here is a piece of software I'm using just to see if I can get it working without the flicker of when temp hits 5000 and 10000, so far failed, I'm using a moc 3021 and a bt137 and bridge with a 1k feeding porta.0 and a 10k holding it low. I have been able to make a simple dimming program so I know this hardware works, I also have an lcd so I need a few more io that a 12f675
Define LCD_DREG PORTB
'Set starting data bit
Define LCD_DBIT 4 'rb4,rb5,rb6,rb7
'Set LCD RS Port
DEFINE LCD_RSREG portb
'Set LCD RS Bit
define LCD_RSBIT 3
'Set LCD Enable Port
Define LCD_EREG portb
'Set LCD Enable Bit
Define LCD_EBIT 2
'Set number of LCD Lines
Define LCD_LINES 2
'Set Command Delay time in uS
define LCD_COMMANUS 2000
'Set Data delay time in uS
define LCD_DATAUS 50

temp var word
temp = 0
temp2 var word
target var word
target = 3000
symbol fire = portb.1
symbol ac = portb.0

maxdelay var word
maxdelay = 8000

delay var word
delay = 4000

trisa = %00000011
trisb = %00000001

DQ VAR PORTa.0 ' One-wire data pin
temperature VAR WORD ' Temperature storage
count_remain VAR BYTE ' Count remaining
count_per_c VAR BYTE

DS18B20_9bit CON %00011111 ; 93.75ms, 0.5°C
DS18B20_10bit CON %00111111 ; 187.5ms, 0.25°C <-- My favorite
DS18B20_11bit CON %01011111 ; 375ms, 0.125°C
DS18B20_12bit CON %01111111 ; 750ms, 0.0625°C (default)

OWOUT DQ, 1, [$CC, $4E, 0, 0, DS18B20_11bit]



lcdout 254,1
pause 100

on interrupt goto firetriac
intcon = %10010000

mainloop:
for temp = 0 to 10000
if temp = 5000 then
gosub startcon
endif
if temp = 10000 then
gosub readtemp
endif
next temp
goto mainloop




disable
firetriac:
pauseus delay
fire = 1
pauseus 10
fire = 0
intcon.1 = 0
resume
enable

startcon:
OWOut DQ, 1, [$CC, $44] ' Start temperature conversion
return
readtemp:


waitloop: OWIn DQ, 4, [count_remain] ' Check for still busy converting
IF count_remain = 0 Then mainloop 'was this what you ment about no waiting in the 'loop

OWOut DQ, 1, [$CC, $BE] ' Read the temperature
OWIn DQ, 0, [temperature.LOWBYTE, temperature.HIGHBYTE, Skip 4, count_remain, count_per_c]

' Calculate temperature in degrees C to 2 decimal places (not valid for negative temperature)
temperature = (temperature >> 1)

lcdout 254,1, dec temperature / 10 ,".", dec1 temperature , " c"
lcdout 254,192, dec delay

return

cphillips82
- 28th April 2008, 02:30
what I want to do over all is to dim an incandescent light depending what temperature it is without an annoying flicker while fetching the temp.

mister_e
- 28th April 2008, 04:31
You may try to switch to asm interrupt or Darrel's instant interrupt to see if it works better.

A real schematic would help...

To generate 10uSec with PAUSEUS, you need at least a 10MHz crystal. If you're using a 4MHz, you'll need to use asm NOP or GOTO

A scope is handy for those things. 1 channel on the Main AC, the other on the PIC output... now you see if you're really in-synch. Be careful if you do that, unless we might see some smoke messages :D

cphillips82
- 28th April 2008, 06:20
my interup seems to work fine it just that the owin owout commands seem to really take alot of time and the interupts are missed in the process. i'll try to draw up a schematic.

cphillips82
- 28th April 2008, 06:39
here is a quick diagram, I know thats not a moc3021

cphillips82
- 28th April 2008, 06:42
here abit smaller

mister_e
- 28th April 2008, 17:32
my interup seems to work fine it just that the owin owout commands seem to really take alot of time and the interupts are missed in the process. i'll try to draw up a schematic.

This is why i've suggested to use Darrel's instant interrupts ;)

Acetronics2
- 28th April 2008, 19:07
Hi,

The MOC 3041 ( and not 3021 ...) permitted to avoid all the zero detection AND the interrupts ...

burst mode is really not a problem with heating systems ...

Alain

cphillips82
- 30th April 2008, 09:07
not too sure what you mean "burst mode" is that like on 1 sec off 4 secon = 20% heat?. I'll try instant interupt but I'm a little affraid of asm..... I hate it!

cphillips82
- 30th April 2008, 09:28
and let the fun begin! can somebody tell me what error: variable wsave3 request 416 beyond ram_end 79 means? I have 3 errors like this in my first attempt at compiling. I installed mpasm and the include files for instant interupt.

Acetronics2
- 30th April 2008, 09:31
not too sure what you mean "burst mode" is that like on 1 sec off 4 secon = 20% heat?. I'll try instant interupt but I'm a little affraid of asm..... I hate it!

Hi,

this is it ... in the end BUT, exactly ... the half waves are "full" , THANKS to the MOC 3041.

for your example you will have 100 half waves ON ( always an integer ! ) @ 50 Hz = 1s followed by 400 "half waves OFF" @ 50 Hz = 4 sec ...


as the DS1820 needs ~ 750 ms for conversion, just fix your regulator period to 1 sec ( in your example .2sec ON and .8 sec OFF ) and you'll have a .5% resolution in power ...

far more than you need ... but very easy for your regulating soft calculations.

Alain

sayzer
- 30th April 2008, 09:58
Why not just skip the busy state of the temp conversation??

If the temp conversation is in progress, do not wait, just pass it.

Acetronics2
- 30th April 2008, 10:14
Hi, Sayzer


WHILE temp conversion ...

REGULATOR loops ...

of course !

just have to verify that the Process time. constant is 10 times or more the sensor time constant ...

If you want it to look at, I committed sometimes ago a DS 1820 temp regulator : a R/C servo drives air flow section to cool some heating stuff ...

Let's say it is intended to control the air flaps of a model "Corsair F4U " engine cowling ...

Alain

cphillips82
- 30th April 2008, 11:49
thanks for you suggestion acetronics but burst will not work for me, I really need to regulate via dimming an incandescent bulb so it is not switching on and off all the time annoying eyes. I have checked only sending a
OWOut DQ, 1, [$CC, $44] ' Start temperature conversion
yet this still makes a flicker which tells me that my interupt is not being seen while sending this message. does anybody know or can work out how long this command takes so I may be able to time when to send it?

Acetronics2
- 30th April 2008, 15:05
when sending this line ... it just tell the DS to do it's measurement.

what takes time is wait for the DATA line to come back high ...

you can do other things just past this line ... PbP doesn't poll the line or insert a Pause "by itself " to let you do what you want during the conversion time.

some MPLAB "stopwatch" to justify it.

Owout $CC,$44 ... 473 µs @ 4 Mhz
$CC,$BE ... id !!!
Owin.. ... 1140 µs ( read result )


will be difficult not to see "something" happens when "talking" with the DS ...

I remember having soldered a an Incubator regulator with a single TDA 1023 ... which has a voltage setpoint input.
The pic could make the temp measurement, drive alarms (?), convert digital setpoint ( a simple R/2R ladder as a DAC will be enough ) to an analog setpoint , and drive a cute viewing LCD display panel ...

can of course being done with a Pic, but some trickery will be compulsory to place the different DS commands in the cycle time ...

Alain

cphillips82
- 1st May 2008, 08:07
I love IT! This chip rocks, so an input voltage = output duty cycle. Is that right in simple terms? I'm going to study this data sheet. thanks for the suggestion!
Clint

Acetronics2
- 1st May 2008, 08:59
Hi,

You also may download the TCA 785 or TDA 1185 Datasheets ... same kind of chips !

Alain

PS : Do not forget the Lilly -of-the-valley !!!

cphillips82
- 1st May 2008, 13:43
i'm going to take the approach of using an 16f88 with a tca785 using the onboard pwm so there are no timing issues while keeping the ds1820. what is the lilly of the vally?

cphillips82
- 2nd May 2008, 14:01
Befor I go on this venture.acetronic/thankyou!!!!!!1!!

Acetronics2
- 2nd May 2008, 14:16
Hi,

" The Lilly of the Valley" ... is a nice little flower you are supposed to offer people you like, on the 1st of May ... as a lucky charm !!!

I hope it's not only a French tradition ...

Women do like you offer such nice flowers ...

16F88 will be a bit overkill ( a 16F84 is enough ... LOL ! ) ... but you won't have "backfire" issues with this config. just don't forget an opto coupler for isolating the power section.

IDEA !!! use "PWM", HPWM, or "SoftPwm" to issue yor required voltage ( will be the best solution for opto-coupler insulation ...)

Alain

mister_e
- 2nd May 2008, 21:21
Maudit Francais! Yeah it seems to be an European tradition.

Here we usually throw flower pot on the right edge of the head of someone we don't like :D