View previous topic :: View next topic |
Author |
Message |
manuelxastre
Joined: 09 Jul 2004 Posts: 1
|
incubadora de huevos controlada por pic |
Posted: Fri Jul 09, 2004 4:00 am |
|
|
ola estoi aciendo una incubadora que sera controlada por pic o sea
dentro de esta incubadora tendre que tener justo 25 grados mi idea es usar un pic que detecte si la temperatura es de 25 grados e entonces encenderia un led verde si la tenperatura baja menos de 25 grados el pic encenderia una bonbilha que calentaria la incubadora asta los 25 grados
pero si la tenperatura passa de los 25 grados el pic pondria en marcha un pequeno ventilador que bajaria la tenperatura asta los 25 grados
e echo este pequenho codigo pero esto no funciona
#include <16F877.h>
#device *=16
#device ICD=TRUE
#device adc=10
#use delay(clock=20000000)
#fuses NOWDT,HS, PUT, NOPROTECT, BROWNOUT, NOLVP
#define VENTILADOR PIN_B0
#define LUZ PIN_B1
#define TEMP_alta PIN_B2
#define NORMAL PIN_B3
#define TEMP_baixa PIN_B4
void main()
{
int choice=1; int flag=0;
int8 sense;
float voltage= 0;
setup_adc_ports(ALL_ANALOG);
setup_adc(ADC_CLOCK_DIV_32);
while (flag == 0)
{
set_adc_channel(0);
delay_us(10);
sense=read_adc();
if(sense >=110)//esto seria 25 grados el valor tendria que ser ajustado para conseguir los 25grados
{
output_high ( ventilador );
output_high ( temp_alta );
output_low ( luz );
output_low ( normal );
output_low ( temp_baixa );
delay_ms(20);
if(sense <=110)
{
output_high ( luz );
output_high ( temp_baixa );
output_low ( ventilador );
output_low ( normal );
output_low ( temp_alta );
delay_ms(20);
if(sense ==110)
{
output_low ( luz );
output_low ( temp_baixa );
output_low ( ventilador );
output_high ( normal );
output_low ( temp_alta );
delay_ms(20);
}
}
}
}
}
como sensor de temperatura usare un LM35 |
|
|
Guest
|
|
Posted: Fri Jul 09, 2004 4:09 am |
|
|
It would be better to use "<=" and ">=" instead of the "==" what is a hard (and probably never-true) condition for temperatures.
Try to use:
if(sense >= 110) ........
else if (sense >= 100) ........
else if (sense <= 90) ...........
//AND WHAT ELSE? |
|
|
future
Joined: 14 May 2004 Posts: 330
|
|
Posted: Fri Jul 09, 2004 7:36 am |
|
|
I would not use a pic to do something like this, a little analog comparator should do the job. |
|
|
Humberto
Joined: 08 Sep 2003 Posts: 1215 Location: Buenos Aires, La Reina del Plata
|
|
Posted: Fri Jul 09, 2004 10:46 am |
|
|
Hola manuelxastre,
1) Too much microcontroller for such task.
2) Why so fast ? at least you are going to control a device that has a
considerable high thermic inertia. Consider a slower xtal frequency
and some delays in the main loop.
3) You didnīt define whatīs your REF voltage.
4) Reduce your code to minimum and first solve the main task, wich is
read an analog value using the internal ADC.
5) You need to define if the convertion result (float) will be right or left
justified.
6) You will need to average multiple temperature aquisition to smooth the
output AD value.
7) After you get repeatedly the same AD value corresponding with an
voltage applied to the input ADC, you will start writing your control
algoritm.
Best wishes,
Humberto
. |
|
|
|