NerdKits - electronics education for a digital generation

You are not logged in. [log in]

NEW: Learning electronics? Ask your questions on the new Electronics Questions & Answers site hosted by CircuitLab.

Project Help and Ideas » Waste Oil Burner Controller

December 16, 2011
by rjardo
rjardo's Avatar

First off, sorry for the long post, hopefully it is interesting to some... I'm working on an automated controller for my waste oil burner/boiler. The mechanical part has been fun, but I'm now challenged with adding this control for automatic cycling.. Here's the general inputs/outputs I'm dealing with: Inputs: Call for heat (wall thermostat or 'on' switch) oil preheated sensor (need to electrically pre-heat waste oil so is flows/burns well) flame sensor (shuts things down if the oil nozzle clogs or air supply fails) water overtemp sensor (safety overtemp) water temp sensor (nice to have for some things but not necessary) flue overtemp (shuts things down if exit temps get too hot) Outputs: oil preheater element-110vac air solenoid-24vac (turns on air supply to atomize oil) draft motor- 110 or ?vdc (pulls combustion gases thru heat exchangers) water pump - (circulates heated water thru radiators) flasher/buzzer - signals error conditions so I can fix/clean/reset

Currently I'm using a dip switch bank to simulate inputs and an LED bank to simulate outputs. once I get the logic working, I'll worry about real world sensors and relays. I'm sure this is a pretty simple state machine and am looking at the stoplight activity now. I started with the led_blink code and added control to read input from a dip switch, but will need to learn more about interrupts so i can 'monitor' the dip switches rather than evaluate them once and they just stay set (i think this is my current problem) I am used to PLC and ladder logic for AND OR NOT NOR stuff.

Here's some of my logic that i'm having trouble coding (i'm an ansi c hack, so i have a very hard time writing code from scratch):

switch 1 turns on led 1 (i'm good with this and made it work) switch 1+2 turns on led 1+2 (both off if either input goes away) if switch 3 makes (some kind of overtemp) i want most everything to kick off but maybe leave one on (water circulator pump)and turn something else on (error buzzer/light)

Specific questions: Can i check for a low input, or a not high? I have pullups enabled, but all the sample code checks for a pin to go high. Can I check for one input AND another AND NOT another. I'm OK with bitwise operations, but can't get the logic behind why this"if(PINB & (1<<PB1))" evaluates true..

Here's some of my not-so-pretty code and what I THINK I'm doing with it. Obviously, I'm not successful..

 while(1) {
if(PINB & (1<<PB1)) {
   //call for heat from thermostat
   delay_ms(200);
 // turn on LED1 - (oil preheat element)
    PORTC |= (1<<PC0);
 }
 else if ((PINB & (1<<PB1))&&(PINB & (1<<PB2))){
// call for heat + oil is hot sensor
   delay_ms(200);
   // turn on LED1 and 2
    PORTC |= (1<<PC0);
        PORTC |= (1<<PC1);

}
else {
//delay 
   delay_ms(200);
    PORTC &= ~(1<<PC0);
    PORTC &= ~(1<<PC1);
    PORTC &= ~(1<<PC2);
    PORTC &= ~(1<<PC3);
    PORTC &= ~(1<<PC4);
    PORTC &= ~(1<<PC5);
    PORTC &= ~(1<<PC3);
}
}
   return 0;
}

the first IF works fine and turns led1 on and off, but when i trip the second dip switch nothing happens. i think it' evaluating the first if, finding it tru, and not going any further in the code. what i'm trying to get is my first If statement to read:

if (something AND NOT something else OR NOT something else)

but i'm not clear enough on several topics to make this actually happen :)

Done ranting...

December 16, 2011
by hevans
(NerdKits Staff)

hevans's Avatar

Hi rjardo,

The ! operator is the logical not operator. So you can use !(PINB & (1<<PBx)) to check if a pin is low.

I think you have the idea behind the AND and OR correct, but your if / else if structure is giving you problems. The else if clause will only ever execute if its preceding if statement did not.

So in your code if PB1 is high, the first if clause will execute and because the second clause is an else statement, it will not execute (the test doesn't even get evaluated). If PB1 is low, the first if clause evaluates to false, so the first else/if clause gets checked but we know for a fact that PB1 was low so that evaluates to false also. In your piece of code the second else/if clause has no way of ever executing (aside from the very very small probability of the pin changing state in the middle of the two checks).

I think if you just switch your first two clauses the code will behave more like what you want it to. First check for both PB1 and PB2 to be high to execute a certain block, and if that is not true then check for only PB1. Does that make sense?

Humberto

December 16, 2011
by rjardo
rjardo's Avatar

Humberto, Thanks for the rapid response support! I did get the logic working with your information. One thing I was missing inside the [else if] block of code was to force the unwanted outputs (leds) low. I'm sure I'll need more advanced help once I have the logic fully defined and start to hook to real world inputs and drive real outputs. Most of the inputs will be switches, but one is a flame sensor that outputs millivolts, so I'll need to use the ADC to determine if my flame goes out. I'll try using snips from the temperature sensor code before shamelessly begging for help :)

thanks again

Post a Reply

Please log in to post a reply.

Did you know that using an alternating excitation voltage can reduce the noise in many sensor measurements? Learn more...