Dew Heater Controller

Status
Not open for further replies.

icarii

New Member
For starters, I am new to PIC's (sorry).
I have attached the circuit i have designed. I am by no means an expert and I hoping someone with more experience and knowledge will take a look and see if I made a mistake, should have down something different, or have suggestion on how to make it better. I am hoping to order the parts in the next couple of days.

This project is a Dew Heater Controller for a telescope.
I choose the PIC18F27J53 because it has 7 PWM pins.

Goals/Requirements:
1. 4 15w (or less) heater outputs, each heater will have its own temp sensor
2. temperature controlled, one temp sensor on the main box for the outside temp
3. humidity sensor, the humidity sensor will be a break out circuit that is not on the circuit i posted (may not impliment)
4. LCD screen for Info
5. Push buttons for settings and scrolling through info
6. Log data and/or get data from/to USB port

Question/confusion i have:
1. USB connection: the datasheet states i can use a 5v tolerant pin for detecting a USB connection (i am using self power for usb, not usb power). But i am out of those pins as i needed them for the PWM connections. Can I simple add a resistor to drop the voltage to 3.3v and connect to a standard input pin?
2. The heaters will be controlled by a Mosfet SPA07N60CFDXK Q1-Q4. Do I need and protection diods with those? I have used NPN transistors before, but never Mosfets.
3. The temp sensors are DS18S20's. My plan is to use the 1-wire bus. And when one of the heaters are plugged into the controller it detects the SN and asked for what port it is attached to, then stores that in firmware so it does not ask again. Is that possible or am I dreaming on the capablities of this PIC?

I am sure i have missed something as I have read alot of datasheets on all of the products I choose. But some of it gets a bit confusing, which is why i am posting this. If anyone can give me a bit of help, that would be great. Please let me know if none of this makes since. Thanks
 

Attachments

  • DewHeater-R1.0.jpg
    574 KB · Views: 513
You may be making this too complicated. An old tape VCR contains a DEW sensor. AFAIK it doesn't sense RH linearly, just on/off for condensation. But that's much simpler.

Even if you DID use an RH, you might not need a temp sensor. When RH reaches 100%, dew forms. Of course that requires that the RH sensor be the same temp as the optical surface needing protection, but that's the same problem with a temp sensor too.
 
The plan is to take a reading from the outside temp sensor then a reading from the optic temp sensor and then turn the heater on so the optics stay 2-3 degrees above the outside temp or once everything is working use the dew point but that will be after everything else is working.
 
1. I think so. Just use a voltage divider so that it is at zero volts when disconnected.
2. If the heaters are inductive you will need diodes. However, I don't think 3.3V will turn on the mosfets.
3. No problem doing that.

Mike.
 
Thanks for the reply. The datasheet for the mosfets says the gate voltage is 3volts. Just to clarify, that does mean it will turn it on right? Mosfets are new to me and i just want to make sure i am understanding it right. Also, what diode would you recommend. The heater are nichrome wire, so they don't have inductance but i will be using PWM and i am not sure if i still need the diodes. Thanks again for the help.
 
The threshold is where the mosfet will BARELY turn on. A mosfet has a current drive- when Ids exceeds the drive set by the gate voltage, it will drop voltage (and heat) across drain-source to limit the current. That's bad. We want it to act as a low-resistance switch.

What's more, Vth is often specified to vary widely, like +/-1v. Well if it was 2v, then that'd be swell, but it might be 4v.

Look up "logic level MOSFETs". You won't find them at Radio Shack but they're common now. There are low thresholds, under 2v. You still need to look up the IV curve and ensure 3.3v will drive a significantly higher current than you will use.

Protection diodes are not all that necessary if you don't have inductance, but diodes are cheap. Sure, why not use them?

Why 3.3v at all? USB is 5v.
 
I chose 3.3v because i was looking for an 18f that had enough CCP/ECCP/PWM pin to handle the heaters and humidity sensor. Now i am learning that may not be necassary.

I would like to use the PIC18F4550. As it is 5v and has plenty of pins. The datasheet says it has 1CCP/ECCP/10 bit PWM. But that is has 4 channells of PWM. Does that mean i could control the heater indeividually with this chip? Also, aren't the specs for hardware PWM? Can software PWM be used on any output pin?

The more datasheets and web sites i read the more confussed i get. The project may melt my brain in the end. LOL

Thanks for any help or tips you can give.
 
Due to the thermal mass of the heaters, slow software PWM should work fine. Setup a 1mS interrupt and have a PWM period of 0-99 so it is switching at 10Hz. There will be an issue reading the One Wire devices but that can be overcome by starting read/writes after an interrupt has occurred.

Edit, the 18F4550 will be fine for this.

Mike.
 
Last edited:
By all means, use 5V parts then!

Your plans for PWM may be problematic.
Say you've got the 12v battery. What resistance is your wire? If it's low, then PWM will in theory regulate the current, but the ON-state current is so high it can cause excessive switching losses and the battery may not perform well if excessive amperage is asked for in pulses. Causes excessive drop in the batt voltage- also, electrical noise, if you have something sensitive to that. It's usually better to have a wire resistance close to the maximum power needed at the coldest temps, and switched on/off with a higher duty cycle. And slowly might be better.

One note there is that, on the PICs I know with multiple PWM modules, they must ALL be in sync. That is, say you've got two 5A loads that need to run at 50% duty. The modules all have to turn to the ON-state when TMR2 resets, drawing 10A total. Whereas, by using slower on/off in code, you could have it run one heater at 5 amps for 30 sec, turn it off, then switch to another heater at 5 amps. Which means the battery load is smooth.

You don't want to slow it down so much that it's within the thermal time constant of the telescope hardware. Unlikely, but a long on/off cycle of say minutes could cause the lens to move back and forth with thermal expansion.

Even if I've got 4x 15W heaters and each has a 30% duty cycle, sequencing them so that at least one, sometimes two, but never 3 are always on at the same time is better than all 4 turning on at the same time then all-off. A small batt would prefer to deliver ~18W constantly than 60W pulsed at 30%.

Make your circuit detect battery voltage, if it's below 10.5v then turn off. Taking a lead-acid batt below 10.5v will greatly shorten its lifespan. There's very little charge left, anyways.
 
Last edited:
this can be caused by several thing the doors that switch from def to heat are contoled by vacume on this car so it could be a hose of or a broken vacume pot to a spring is broke take it to dealer to be fixed or reputable mech with this car i would because it is exapensive car and you want it fixed right not rigged also could be control it self hope this helps thanks john
 
New Circuit

Oznog and Mike, thank you for all your help.

I got side tracked from this project, life.

Attached is the circuit i have went with. I have all the parts. I am using C18 in MLAB. But I have a problem. I have not been able to figure out how to assign the pins correctly in C18. I have Googled until complete frustration and confusion. I have read the datasheet on the LCD but the example code has me just as confused. So my biggest question for starting out is how do I assign the pins in C18 based on my schematic? I am using a New Haven NHD-0216K1Z-FS RGB 16x2 LCD. And i have not found any examples for a PIC 18f with this LCD using C18.

Here is the example code from the datasheet:
I think the D_I is the same as the RS pin but this is one of the things that has me confused.

Hopefully someone can point me in the right direction.
 

Attachments

  • DewHeater-R2.1.jpg
    338.9 KB · Views: 205
This is what I have so far, but it does not work. Any pointers???

 
I change my code to this:


And now I get gibberish. Which is better than nothing. What am I missing? Anyone have any idea?
 
OK, I think I have figured out the problem but I am not sure how to fix it.

This how my circuit is connected:
LCD -- PIC
DB4 -- RA0
DB5 -- RA1
DB6 -- RA2
DB7 -- RA3

When I tell it to send a command to PORTA using 4 bit, the PIC is sending the binary code across the entire PORTA which would be RA0-RA7. But the LCD is looking for the high side of the byte to set the 4 bit mode. (Does that make since? Am i even close to right?) If I am right, how to I fix it? If not, what is wrong and how do I fix it?

Please somebody point me in the right direction.
 
You need to change your code to,
Code:
void command(char i){
    LCD_Data = i[COLOR="red"]>>4[/COLOR];
    LCD_RS = 0; //3_0
    LCD_RW = 0; //3_7
    Nybble();
    [COLOR="red"]LCD_Data = i[/COLOR];
    Nybble();
}

void write(char i){
    LCD_Data = i[COLOR="red"]>>4[/COLOR];
    LCD_RS =1;
    LCD_RW =0;
    Nybble();
    [COLOR="red"]LCD_Data = i[/COLOR];
    Nybble();
}

and, set the port to digital,
Code:
void main(void) {
    ADCON1 = [COLOR="red"]0x0f[/COLOR];
    TRISA = 0b00000000;
    TRISB = 0b00000000;
    //P1=0;
    //P3=0;
    Delay10KTCYx(200);
    while(1){
        init();
        disp_pic();
        Delayms(1000);
    }
}


Is there any reason why you are repeatedly initialising the display?

Edit, BTW, to keep the formating use code tags instead of quote tags.

Mike.
 
Last edited:
Fix My LCD Problem

That Mike for the help.

I found the shift bits command last night and the all digital command but i did not have that one correct. But i got the same results. After a lot of head scratching I figured it out. The first problem: I am using PORTA, which on a PIC18f4550 PORTA only has 6 pins so the PIC was dumping the last 2 bits. I solved it with this code:

Code:
void command(char i){
	char j;
	j = i;
	i = i >> 4;
	LCD_Data = i;
	LCD_RS = 0;
	LCD_RW = 0; 
	Nybble();
	LCD_Data = j;
	Nybble();
}

void write(char i){
	char j;
	j = i;
	i = i >> 4;
	LCD_Data = i;
	LCD_RS = 1;
	LCD_RW = 0;
	Nybble();
	LCD_Data = j;
	Nybble();
	LCD_RS = 0;
}

That started showing characters on the LCD. But it would some times display gibberish after a program and would always display gibberish after a power reset. Which meant it wasn't initializing correctly. I was caused by the fact I am using Pins 0-3 on PORTA and the init command is ox30 and 0x20. I changed those to 0x03 and 0x03 in the init function:

Code:
void init(){
	LCD_Data = 0;
	LCD_RS = 0;
	Delayms(30);
	LCD_Data = 0x03;
	Delayms(10);
	Nybble();
	Delayms(10);
	Nybble();
	Delayms(10);	
	Nybble();
	Delayms(10);
	LCD_Data = 0x02;
	Nybble();
	command(0x28);
	command(0x10);
	command(0x0C);
	command(0x06);
	command(0x01);
	Delayms(100);
}

Here is the complete code in case someone else is having the same problem:
Code:
#include <p18f4550.h>
#include <delays.h>

#pragma config PLLDIV   = 5         // (20 MHz crystal on PICDEM FS USB board)
#pragma config CPUDIV   = OSC1_PLL2   
#pragma config USBDIV   = 2         // Clock source from 96MHz PLL/2
#pragma config FOSC     = HSPLL_HS
#pragma config FCMEN    = OFF
#pragma config IESO     = OFF
#pragma config PWRT     = OFF
#pragma config BOR      = ON
#pragma config BORV     = 3
#pragma config VREGEN   = ON      //USB Voltage Regulator
#pragma config WDT      = OFF
#pragma config WDTPS    = 32768
#pragma config MCLRE    = ON
#pragma config LPT1OSC  = OFF
#pragma config PBADEN   = OFF
//      #pragma config CCP2MX   = ON
#pragma config STVREN   = ON
#pragma config LVP      = OFF
//      #pragma config ICPRT    = OFF       // Dedicated In-Circuit Debug/Programming
#pragma config XINST    = OFF       // Extended Instruction Set
#pragma config CP0      = OFF
#pragma config CP1      = OFF
//      #pragma config CP2      = OFF
//      #pragma config CP3      = OFF
#pragma config CPB      = OFF
//      #pragma config CPD      = OFF
#pragma config WRT0     = OFF
#pragma config WRT1     = OFF
//      #pragma config WRT2     = OFF
//      #pragma config WRT3     = OFF
#pragma config WRTB     = OFF       // Boot Block Write Protection
#pragma config WRTC     = OFF
//      #pragma config WRTD     = OFF
#pragma config EBTR0    = OFF
#pragma config EBTR1    = OFF
//      #pragma config EBTR2    = OFF
//      #pragma config EBTR3    = OFF
#pragma config EBTRB    = OFF

#define CLOCK_FREQ 48000000
#define LCD_E	 LATBbits.LATB2
#define LCD_RS   LATBbits.LATB0
#define LCD_RW	 LATBbits.LATB1
#define LCD_Data PORTA

char const text1[] = {"New Haven       "};
char const text2[] = {"Character LCD   "};
//

/** D E C L A R A T I O N S *******************************************/
#pragma code    // declare executable instructions

void Delayms(int n);
void command(char i);
void write(char i);
void init(void);
void home(void);
void nextline(void);
void disp_pic(void);
void Nybble(void);

void main(void) {
	ADCON1 = 0x0f;
	TRISA = 0b00000000;
	TRISB = 0b00000000;
	LCD_Data = 0;
	LCD_RS = 0;
    Delay10KTCYx(1500);
	init();
	while(1){
		home();
		disp_pic();
		Delayms(2000);
	}
}

void Delayms(int n){
//	int i;
	int j;
	j = n * 12;
	Delay10KTCYx(j);
}

void command(char i){
	char j;
	j = i;
	i = i >> 4;
	LCD_Data = i;
	LCD_RS = 0;
	LCD_RW = 0; 
	Nybble();
	LCD_Data = j;
	Nybble();
}

void write(char i){
	char j;
	j = i;
	i = i >> 4;
	LCD_Data = i;
	LCD_RS = 1;
	LCD_RW = 0;
	Nybble();
	LCD_Data = j;
	Nybble();
	LCD_RS = 0;
}

void Nybble(){
	LCD_E = 1;
	Delayms(1);
	LCD_E = 0;
}

void init(){
	LCD_Data = 0;
	LCD_RS = 0;
	Delayms(30);
	LCD_Data = 0x03;
	Delayms(10);
	Nybble();
	Delayms(10);
	Nybble();
	Delayms(10);	
	Nybble();
	Delayms(10);
	LCD_Data = 0x02;
	Nybble();
	command(0x28);
	command(0x10);
	command(0x0C);
	command(0x06);
	command(0x01);
	Delayms(100);
}

void home(){
	command(0x02);
	Delayms(5);
}

void nextline(){
	command(0xc0);
}

void disp_pic(){
	int i;
	home();
	for (i=0;i<16;i++){
		write(text1[i]);
	}
	 nextline();
	 for (i=0;i<16;i++){
		write(text2[i]);
	}
}

Again Mike, thanks for the help.
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…