EmbeddedRelated.com
Forums
The 2024 Embedded Online Conference

Please Help...Programming Assitance Needed with Dragon12

Started by b_scheibe April 14, 2007
I am very new to programming/HC12 so please bare with me. The code i
am currently dealing with is something my professor made available so
that i can modify it. I am trying to run a heater using the Dragon 12
with a relay hooked up between the two. I already have a thermistor
set up on the board with temperature being displayed to the LCD. I am
wanting the heater to turn on when the temp is below 270 and turn off
when the temp is above 280. I currently have the relay hooked up to
PB2 and ground. This is where my programming knowledge ends. I am
assuming it is just a matter of turning the relay either high or low
according to my previously mentioned criteria. What i am wanting to
know is what i need to add to my Freescale CodeWarrior C code to cause
these things to happen. If there is any other information you need,
let me know. Thanks for your help.

-Bryan
--- In 6..., "b_scheibe" wrote:

> What i am wanting to know is what i need to add to my Freescale
> CodeWarrior C code to cause these things to happen.

It's a good idea to pay attention in class. Surely you attended
lectures on this subject? And what about sample code or exercises?

Eric
I agree with you, it is a good idea to pay attention in class. That
is why in my college career i've yet to miss a class for any reason
besides a job interview. In this case that has nothing to do with
what i am working on. I'm going beyond the scope of my Mechatronics
class to add my own little 'thing' for a project req. in another
class. Since i've had practically no success in meeting up with my
professor i thought someone might be of assistance on here.
--- In 6..., "Eric Engler" wrote:
>
> --- In 6..., "b_scheibe" wrote:
>
> > What i am wanting to know is what i need to add to my Freescale
> > CodeWarrior C code to cause these things to happen.
>
> It's a good idea to pay attention in class. Surely you attended
> lectures on this subject? And what about sample code or exercises?
>
> Eric
>
--- In 6..., "b_scheibe" wrote:
> I am very new to programming/HC12 so please bare with me. The code i
> am currently dealing with is something my professor made available
> so that i can modify it. I am trying to run a heater using the
> Dragon 12 with a relay hooked up between the two. I already have a
> thermistor set up on the board with temperature being displayed to
> the LCD. I am wanting the heater to turn on when the temp is below
> 270 and turn off when the temp is above 280. I currently have the
> relay hooked up to PB2 and ground. This is where my programming
> knowledge ends. I am assuming it is just a matter of turning the
> relay either high or low according to my previously mentioned
> criteria. What i am wanting to know is what i need to add to my
> Freescale CodeWarrior C code to cause these things to happen. If
> there is any other information you need, let me know. Thanks for
> your help.
>
> -Bryan

Well, Dragon12 is so far the best setup for my projects (and just
keeps getting better), but I see that you need more info about the
hardware you are interfacing with, and how it looks inside the MCU.
Actually from what you've said so far, you did not even indicate that
you know what "if/else" means in C. There's no way we could tell you
*everything* you need to know, so let us know in more detail, what you
have. If your professor just gave you source code to get you started,
I suppose a sort of framework, have you even figured out what *that*
does? We certainly cannot guess what the code does so far.

Do you have the relay coil directly connected to the MCU pin? will
that cause a problem? How much current can the pin drive? Will counter
EMF burn out the MCU? Has all this been already tested by someone with
the same hardware? All this research will help you, but has nothing
really to do with this 68HC12 group unless you have specific questions
about what it says in spec sheets for the MC9S12DP256 or DP512.

Also, you would need to know how to read in a variable that represents
a temperature from your sensor. Maybe you know that number is not
necessarily '270' when the actual temperature is 270 degrees (F? C?
K?). Well I suppose you already can get the actual temperature value
because you say it is displayed on the LCD, but sure will hepl if you
can read the code and know how it does it.
I use a ULN2803A darlington array to drive relays. The chip has surpressor diodes to absorb the energy in the relay magnetic field when it is shut off and will sink 500ma per darlington. The processor should not be used to drive relays directly as the current requirement is likely to exceed the output rating of the chip and the "spike" when the relay is shut off may damage the processor output or cause a "noise crash" - and require a reset.

Data sheet:

http://www.tranzistoare.ro/datasheets/105/366825_DS.pdf

The common (surpressor diode) is connected to the +5 rail. The relay coil is connected between the +5 rail and the chip "out" terminal. A one (+5) at the input will then energise the relay. The relay is selected to have a contact rating suitable to the heater load and for high power applications the relay might pick up a power contactor. A solid state relay can also be driven by the darlington and this method will provide optical isolation of the heater power circuit. Jameco part 481001is a triac output solid state relay rated 240V at 10 amps and it provides 4000V isolation between the AC power and your delicate 5V electronics.

----- Original Message -----
From: Jefferson Smith
To: 6...
Sent: Tuesday, April 17, 2007 9:07 AM
Subject: [68HC12] Re: Please Help...Programming Assitance Needed with Dragon12
--- In 6..., "b_scheibe" wrote:
> I am very new to programming/HC12 so please bare with me. The code i
> am currently dealing with is something my professor made available
> so that i can modify it. I am trying to run a heater using the
> Dragon 12 with a relay hooked up between the two. I already have a
> thermistor set up on the board with temperature being displayed to
> the LCD. I am wanting the heater to turn on when the temp is below
> 270 and turn off when the temp is above 280. I currently have the
> relay hooked up to PB2 and ground. This is where my programming
> knowledge ends. I am assuming it is just a matter of turning the
> relay either high or low according to my previously mentioned
> criteria. What i am wanting to know is what i need to add to my
> Freescale CodeWarrior C code to cause these things to happen. If
> there is any other information you need, let me know. Thanks for
> your help.
>
> -Bryan

Well, Dragon12 is so far the best setup for my projects (and just
keeps getting better), but I see that you need more info about the
hardware you are interfacing with, and how it looks inside the MCU.
Actually from what you've said so far, you did not even indicate that
you know what "if/else" means in C. There's no way we could tell you
*everything* you need to know, so let us know in more detail, what you
have. If your professor just gave you source code to get you started,
I suppose a sort of framework, have you even figured out what *that*
does? We certainly cannot guess what the code does so far.

Do you have the relay coil directly connected to the MCU pin? will
that cause a problem? How much current can the pin drive? Will counter
EMF burn out the MCU? Has all this been already tested by someone with
the same hardware? All this research will help you, but has nothing
really to do with this 68HC12 group unless you have specific questions
about what it says in spec sheets for the MC9S12DP256 or DP512.

Also, you would need to know how to read in a variable that represents
a temperature from your sensor. Maybe you know that number is not
necessarily '270' when the actual temperature is 270 degrees (F? C?
K?). Well I suppose you already can get the actual temperature value
because you say it is displayed on the LCD, but sure will hepl if you
can read the code and know how it does it.

------
No virus found in this incoming message.
Checked by AVG Free Edition.
Version: 7.5.446 / Virus Database: 269.5.1/764 - Release Date: 4/17/2007 4:43 AM
--- In 6..., "Vernon Lermond" wrote:
> I use a ULN2803A darlington array to drive relays. The chip has
> surpressor diodes to absorb the energy in the relay magnetic field
> when it is shut off and will sink 500ma per darlington. The
> processor should not be used to drive relays directly as the current
> requirement is likely to exceed the output rating of the chip and
> the "spike" when the relay is shut off may damage the processor
> output or cause a "noise crash" - and require a reset.

In fact the Dragon12 has an "application corner" where there is a
circuit (without the parts stuffed) for a relay driven by NPN
transistor (i.e. 2N2222). It accomodates a 1K on the gate and 1N4004
to protect the silicon, but who knows whether b_scheibe is using this
circuit? It would not likely be that same relay because... how much
power might one supply to power a "heater"?
I'm gonna have to agree with some of the previous comments...

You need to provide us with more information about what you need. Based on the things you've said, I would assume the following:

1) You know how to probe temps from the thermistor (If you can display temps on an LCD at will, you can probe the temperature at will...)
2) You have a relay hooked up correctly to the system (You said you had it hooked to a PB2).
3) The relay can be used to turn the heating system on or off. (You didn't really say this, but what else would I assume based on what you said?)

If these 3 things are true, then the only advice I could give you is this...

1) Don't forget to set DDRB = 0xFF (or 0x04) to ensure that PB2 is defined as an output.
2) Review IF statements in C and learn to put design conditional statements in C.
3) You will need to utilize code that will be nearly identical to..

if(temp<270){
PORTB = PORTB|0x04; //Sets PB2 high (flips the relay)
} else if(temp>280){
PORTB = PORTB&0xFB; //Sets PB2 low (flips the relay)
}

Now, if those last three things helped you, great! But, if those last three things helped you...then one of the following is true...

1) You didn't attend class often enough (digital output and if statements are trivial and fundamental parts of programming micro controllers)
2) You attended but did not pay attention in class. (for the same reasons as above).
3) Your university offers the worst mechatronics course I've ever heard of (basically for the same reasons as above)

Giving you the benefit of the doubt, hopefully none of those are true. Please define your problem a little more thoroughly for us...we really do want to help you.

In addition to this, the relay should not directly be driven from the MCU I/O
pin. You need to drive it with a transistor. The easiest way to do that is to
have an NPN transistor supply the ground to the relay. You may also need a
flyback diode across the relay coil in order to prevent nasty spikes over the
transistor when the relay is de-energized (switched off).

/Ruben

> I'm gonna have to agree with some of the previous comments...
>
> You need to provide us with more information about what you need. Based on the
> things you've said, I would assume the following:
>
> 1) You know how to probe temps from the thermistor (If you can display temps on
> an LCD at will, you can probe the temperature at will...) 2) You have a relay
> hooked up correctly to the system (You said you had it hooked to a PB2). 3) The
> relay can be used to turn the heating system on or off. (You didn't really say
> this, but what else would I assume based on what you said?)
>
> If these 3 things are true, then the only advice I could give you is this...
>
> 1) Don't forget to set DDRB = 0xFF (or 0x04) to ensure that PB2 is defined as
> an output. 2) Review IF statements in C and learn to put design conditional
> statements in C. 3) You will need to utilize code that will be nearly identical
> to..
>
> if(temp<270){
> PORTB = PORTB|0x04; //Sets PB2 high (flips the relay)
> } else if(temp>280){
> PORTB = PORTB&0xFB; //Sets PB2 low (flips the relay)
> }
>
> Now, if those last three things helped you, great! But, if those last three
> things helped you...then one of the following is true...
>
> 1) You didn't attend class often enough (digital output and if statements are
> trivial and fundamental parts of programming micro controllers) 2) You attended
> but did not pay attention in class. (for the same reasons as above). 3) Your
> university offers the worst mechatronics course I've ever heard of (basically
> for the same reasons as above)
>
> Giving you the benefit of the doubt, hopefully none of those are true. Please
> define your problem a little more thoroughly for us...we really do want to help
> you.
>
>

The 2024 Embedded Online Conference