Sign in

username:

password:



Not a member?

Search hc11



Search tips

Subscribe to hc11



Ads

Discussion Groups

Discussion Groups | M68HC11 | Simple program to make HC11 act as Or Gates

Technical discussions about Freescale Microcontrollers: M68HC11. (Freescale Semiconductor is a Subsidiary of Motorola).

Simple program to make HC11 act as Or Gates - w_gossage - Aug 1 15:16:47 2006

I am new to the programming world and the HC11, so forgive me if I am
asking a very basic question. I am looking for a simple program that
will take 3 digital (5V) inputs and if any one of them are true trigger
the internal timer. Once the internal timer expires, I would like for
the HC11 to give a 5V (or 12V) output that can activiate a relay. I
have the Axiom Manufacturing CME-11E9-EVBU board.

Can anyone help point me in the right direction?

Thanks,
Wayne



(You need to be a member of hc11 -- send a blank email to hc11-subscribe@yahoogroups.com )


Re: Simple program to make HC11 act as Or Gates - David Kelly - Aug 1 17:17:33 2006

On Tue, Aug 01, 2006 at 07:13:28PM -0000, w_gossage wrote:
> I am new to the programming world and the HC11, so forgive me if I am
> asking a very basic question. I am looking for a simple program that
> will take 3 digital (5V) inputs and if any one of them are true trigger
> the internal timer. Once the internal timer expires, I would like for
> the HC11 to give a 5V (or 12V) output that can activiate a relay. I
> have the Axiom Manufacturing CME-11E9-EVBU board.
>
> Can anyone help point me in the right direction?

Its hard to help without actually writing the code for you. This is a
very trivial task. Once you have activated the relay, what condition
clears the situation and return to the initial state?

What if one of your inputs changes its mind before the timer expires?

What if the first input is asserted, timer starts, then a 2nd is
asserted, and the first changes its mind before the timer expires? Do
you need to retime from leading edge of the 2nd input?

How long is the timer? Microseconds? Milliseconds? Minutes?

Too many questions. Poorly stated requirements document.

--
David Kelly N4HHE, d...@HiWAAY.net
========================================================================
Whom computers would destroy, they must first drive mad.



(You need to be a member of hc11 -- send a blank email to hc11-subscribe@yahoogroups.com )

Re: Simple program to make HC11 act as Or Gates - w_gossage - Aug 1 20:52:17 2006

--- In m...@yahoogroups.com, David Kelly wrote:
>
> On Tue, Aug 01, 2006 at 07:13:28PM -0000, w_gossage wrote:
> > I am new to the programming world and the HC11, so forgive me if
I am
> > asking a very basic question. I am looking for a simple program
that
> > will take 3 digital (5V) inputs and if any one of them are true
trigger
> > the internal timer. Once the internal timer expires, I would
like for
> > the HC11 to give a 5V (or 12V) output that can activiate a
relay. I
> > have the Axiom Manufacturing CME-11E9-EVBU board.
> >
> > Can anyone help point me in the right direction?
>
> Its hard to help without actually writing the code for you. This is
a
> very trivial task. Once you have activated the relay, what condition
> clears the situation and return to the initial state?
>
> What if one of your inputs changes its mind before the timer
expires?
>
> What if the first input is asserted, timer starts, then a 2nd is
> asserted, and the first changes its mind before the timer expires?
Do
> you need to retime from leading edge of the 2nd input?
>
> How long is the timer? Microseconds? Milliseconds? Minutes?
>
> Too many questions. Poorly stated requirements document.
>
> --
> David Kelly N4HHE, dkelly@...
>
======================================================================
==
> Whom computers would destroy, they must first drive mad.
>
Okay, here is the additional information...

Once the relay is activated, I do not want it to change state, until
the power is shut off to the entire circuit. If one of the inputs
changes its mind before the timer expires, I would like the timer to
stop. If a second input is asserted, and the first changes its mind,
I would like the timer to keep counting (due to what my inputs are,
it is doubtful that this will actually occur). I would like to be
able to set the timer from about 30seconds, to 5 minutes or so.

Basically, I have the circuit working the way that I want it to
utilizing logic gates, but the task at hand is to switch it over to a
microcontroller.

Like I said, I am new to this stuff, so I'm basically clueless.

Thanks,
Wayne



(You need to be a member of hc11 -- send a blank email to hc11-subscribe@yahoogroups.com )

Re: Re: Simple program to make HC11 act as Or Gates - David Kelly - Aug 1 21:41:27 2006


On Aug 1, 2006, at 7:48 PM, w_gossage wrote:

> Okay, here is the additional information...
>
> Once the relay is activated, I do not want it to change state, until
> the power is shut off to the entire circuit. If one of the inputs
> changes its mind before the timer expires, I would like the timer to
> stop. If a second input is asserted, and the first changes its mind,
> I would like the timer to keep counting (due to what my inputs are,
> it is doubtful that this will actually occur). I would like to be
> able to set the timer from about 30seconds, to 5 minutes or so.
>
> Basically, I have the circuit working the way that I want it to
> utilizing logic gates, but the task at hand is to switch it over to a
> microcontroller.
>
> Like I said, I am new to this stuff, so I'm basically clueless.

My preference is to find a C compiler as the code will look something
like this:

#include

#define BIT_A (1<<0)
#define BIT_B (1<<1)
#define BIT_C (1<<2)

#define INPUT_A (HC11_PORTA & BIT_A) // bit 0 of port A
#define INPUT_B (HC11_PORTA & BIT_B) // bit 1 of port A
#define INPUT_B (HC11_PORTA & BIT_C) // bit 2 of port A
#define INPUT_DDR HC11_DDRA

#define OUTPUT_P HC11_PORTB
#define OUTPUT_DDR HC11_DDRB
#define OUTPUT_B (1<<0) // bit 0 of port B

// TIMEOUT is how many times the selected TIMERx
// overflows in the desired period of time. Set to 60 if
// overflow once per second and desired time is 60 seconds.
#define TIMEOUT 99999

void
initialize(void)
{
// configure port bits for input. This writes '1' to each
// bit. Read manual, might need '0' for input. Default is
// usually input but good practice to always initialize.

INPUT_DDR |= BIT_A & BIT_B & BIT_C; // sets the bits
OUTPUT_DDR &= ~(OUTPUT_B); // clears the bit(s)

// I forget how the HC11 timers are configured. It depends
// on your particular HC11 and crystal frequency. I suggest
// you set the timer divisor so that it overflows about once
// per second or 18 times per second or some period you know.
// Use that period in calculating TIMEOUT.
HC11_TIMER0_CONFIG = some value;
HC11_TIMER0 = some value;
}

void
main(void)
{
unsigned counter;

initialize();
counter = TIMEOUT;

for(;;) {

if( INPUT_A | INPUT_B | INPUT_C ) {
if( counter == 0 ) {
OUTPUT_P |= OUTPUT_B;
for(;;)
; // do nothing forever
}
} else {
counter = TIMEOUT; // start over if all false
}

if( HC11_TIMER0_status & overflow_bit) {
clear the overflow bit;
if( counter != 0 ) // this should be redundant
counter--;
}
}
}

You should get the idea above. Could connect the timer to an
interrupt but there isn't much point in this simple application.

Would be of more use if you had a means of setting the time to be
measured without reloading new code. Left as an exercise for the reader.

The following test should be redundant but it doesn't hurt much to
add and adds a measure of safety net to your code.

if( counter != 0 )
counter--;

--
David Kelly N4HHE, d...@HiWAAY.net
========================================================================
Whom computers would destroy, they must first drive mad.



(You need to be a member of hc11 -- send a blank email to hc11-subscribe@yahoogroups.com )