Sign in

username:

password:



Not a member?

Search m68hc11



Search tips

Subscribe to m68hc11



m68hc11 by Keywords

27c256 | 4K81H | 68HC11A1 | 68HC11P1 | 68hc24 | 68HC711E9 | 68HC811 | 8255 | A2D | ADC | ADC12138 | Am85C30 | BRCLR | Buffalo | CMOS | EEPROM | EPROM | Ethernet | EVB | EVBU | HC11E1 | HC11E9 | HC711E9 | Horray | ImageCraft | IRQ | Keypad | LCD | MC68HC11D0FN | MC68HC11E1CFU3 | MC68HC11F1 | MC68HC711E9 | MC68HC711E9CFN2 | Microcore11 | Microstamp11 | Minikit | NVRAM | PSD | PSD8xx | PSD9xx | PT1000 | RS232 | RTS | RXD | SPI | SRAM | TXD | Watchdogs | XIRQ


Ads

Discussion Groups

See Also

DSPFPGAElectronics

Discussion Groups | | A2D binary to Ascii conversion to terminal

A2D binary to Ascii conversion to terminal - Liew Ban Wui - Dec 25 8:36:00 2002

Hi there,

Isn't anybody can provide me the method to convert the a2d output
(from floating point binary data) to Ascii , so i can sent the ascii
code output to SCI/terminal . Thank you





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


Re: A2D binary to Ascii conversion to terminal - Author Unknown - Dec 25 8:43:00 2002

In a message dated 12/25/02 8:36:09 AM Eastern Standard Time,
writes:

> Isn't anybody can provide me the method to convert the a2d output
> (from floating point binary data) to Ascii , so i can sent the ascii
> code output to SCI/terminal . Thank you unsigned char addat;
float volts;

addat=readadchan(); //read a/d
volts=addat*5.0/255.0; //convert to floating point
printf("%7.3f\n"); //print out sci terminal
[Non-text portions of this message have been removed]





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

Re: A2D binary to Ascii conversion to terminal - Liew Ban Wui - Dec 25 12:30:00 2002

--- In , BobGardner@a... wrote:
> In a message dated 12/25/02 8:36:09 AM Eastern Standard Time,
> liewbw@m... writes:
>
> > Isn't anybody can provide me the method to convert the a2d
output
> > (from floating point binary data) to Ascii , so i can sent the
ascii
> > code output to SCI/terminal . Thank you
> >
>
> unsigned char addat;
> float volts;
>
> addat=readadchan(); //read a/d
> volts=addat*5.0/255.0; //convert to floating point
> printf("%7.3f\n"); //print out sci terminal > May i have the example code in asembly format ? thank you
> [Non-text portions of this message have been removed]




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

Re: Re: A2D binary to Ascii conversion to terminal - Author Unknown - Dec 25 12:35:00 2002

In a message dated 12/25/02 12:31:21 PM Eastern Standard Time,
writes:

> >unsigned char addat;
> >float volts;
> >
> >addat=readadchan(); //read a/d
> >volts=addat*5.0/255.0; //convert to floating point
> >printf("%7.3f\n"); //print out sci terminal Life's too short to remember which variable is in which register. If you
really have to see what the assembly looks like, dl the imagecraft compiler,
compile it, then look at the compiler generated assembly language..... I
can't imagine anything needing assembler anymore... that's right you guys...
a challenge... bring it on... send the spec and your tightest assembly
code... [Non-text portions of this message have been removed]





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

Re: A2D binary to Ascii conversion to terminal - Liew Ban Wui - Dec 25 12:55:00 2002

--- In , BobGardner@a... wrote:
> In a message dated 12/25/02 12:31:21 PM Eastern Standard Time,
> liewbw@m... writes:
>
> > >unsigned char addat;
> > >float volts;
> > >
> > >addat=readadchan(); //read a/d
> > >volts=addat*5.0/255.0; //convert to floating point
> > >printf("%7.3f\n"); //print out sci terminal
> >
>
> Life's too short to remember which variable is in which register.
If you
> really have to see what the assembly looks like, dl the imagecraft
compiler,
> compile it, then look at the compiler generated assembly
language..... I
> can't imagine anything needing assembler anymore... that's right
you guys...
> a challenge... bring it on... send the spec and your tightest
assembly
> code... > [Non-text portions of this message have been removed]

Herer is my project run

Sensor --> MC68HC11 (A2D) ---> RS232 ---> Computer
Below is the part of the asembly code for link the measured out to
port E :

*=====================================================================
* Init A2D: Initialize the Analog to Digital convertor
*=====================================================================
INIT_A2D:
LDX #$1000 ; needed for the BRCLR command
LDAA #%10010000 ; Power up A/D with clock delay
STAA $39,x
RTS *=====================================================================
* Read A2D values:
*=====================================================================
Read_A2D:
LDAA #%00000000 ; single scan, multi-mode, pins e0-3
STAA $30,x ; WRITE staRTS conversion
CONVERSION_NOT_DONE
BRCLR $30,x $80 CONVERSION_NOT_DONE
LDAA $31,x ; GET VALUE FORM PIN PE0
PULX
RTS *=====================================================================
* WRITE A2D: WRITE the 8 A2D values in Ram to the TERMinal.
*=====================================================================
WRITE_A2D:
LDAA A2D0
LDAB #'0
BSR WRITE_A2D_BYTE
LDAA A2D1
INCB
BSR WRITE_A2D_BYTE
LDAA A2D2
INCB
BSR WRITE_A2D_BYTE
LDAA A2D3
INCB
BSR WRITE_A2D_BYTE
LDAA A2D4
INCB
BSR WRITE_A2D_BYTE
LDAA A2D5
INCB
BSR WRITE_A2D_BYTE
LDAA A2D6
INCB
BSR WRITE_A2D_BYTE
LDAA A2D7
INCB
BSR WRITE_A2D_BYTE
RTS

WRITE_A2D_BYTE:
psha
pshb
BSR WRITE_TERM
LDAB #':
BSR WRITE_TERM
TAB
lsrb
lsrb
lsrb
lsrb
LDY #WA2D_TABle ; 4-bits to HEX
aby
LDAB $00,y
BSR WRITE_TERM
TAB
andb #$0F
LDY #WA2D_TABle
aby
LDAB $00,y
JSR WRITE_TERM
LDAB #$20 ; Space
JSR WRITE_TERM
pulb
pula
RTS
WA2D_TABle:
fcc "0123456789ABCDEF"
*=====================================================================
* WRITE 2 TERMinal:
* Input: ASCII data in the B register.
* Action: Wait until transmit buffer is empty, then
* transmit the data in the B register.
*=====================================================================
WRITE_TERM:
BRCLR $2e,x %10000000 WRITE_TERM ; check Transmit-empty
STAB $2f,x
RTS

==============================================
What i have done is convert the analog measurement data and sent to
Port PE0 for conversion. The Voltage reference is 5 V for high and 0
v for low.So, how to take the converted data from A2D result and
shift into a 8 bit binary data and then convert to ascii code . The
ascii code will transmit to SCI port.Thank you





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

Re: Re: A2D binary to Ascii conversion to terminal - Gordon Couger - Dec 26 2:09:00 2002

Why convert it to flotating point in the first place. Read the A/D register
as a short, int or long as approiate and and send it as is. If you are
going to use it on an Intel or other machine you will have to reverse the
byte in the case of an int and I don't rember how to handle a long.

If you don't need floating point don't link it in. It is SLOOOOOOW. I woked
whith a 68HC11 for 7 years professionaly and never had to use floating
point. I had to use some awkward fractions and such but I never could afford
the speed loss that F.P. cost.

I printed them out in hex on a termial because they were 8 bit A/C converers
and hex kept them in orderly rows. I used somting like witten from memory
the sentax may not be correct but you should get the idea..

char *hexstr ="0123456789ABCDEF"
void print-hex(char a)
{
char [3] s;
s[2] =0;
s[0]=hex-str[ a%16]; /* mod 16 I may have the operater wrong and the order
reversed */
s[1]=hex-str[a/16];
puts(s);
}

It's crude but small and fast and the string s was often a pointer to a
global string that I have for an output line insted of a local variable.
Again not clean but fast and small.

Gordon

Gordon Couger
Stillwater, OK
www.couger.com/gcouger
----- Original Message -----
From: <>
To: <>
Sent: Wednesday, December 25, 2002 9:55 AM
Subject: [m68HC11] Re: A2D binary to Ascii conversion to terminal > --- In , BobGardner@a... wrote:
> > In a message dated 12/25/02 12:31:21 PM Eastern Standard Time,
> > liewbw@m... writes:
> >
> > > >unsigned char addat;
> > > >float volts;
> > > >
> > > >addat=readadchan(); //read a/d
> > > >volts=addat*5.0/255.0; //convert to floating point
> > > >printf("%7.3f\n"); //print out sci terminal
> > >
> >
> > Life's too short to remember which variable is in which register.
> If you
> > really have to see what the assembly looks like, dl the imagecraft
> compiler,
> > compile it, then look at the compiler generated assembly
> language..... I
> > can't imagine anything needing assembler anymore... that's right
> you guys...
> > a challenge... bring it on... send the spec and your tightest
> assembly
> > code...
> >
> >
> > [Non-text portions of this message have been removed] >
>
> Herer is my project run
>
> Sensor --> MC68HC11 (A2D) ---> RS232 ---> Computer
> Below is the part of the asembly code for link the measured out to
> port E :
>
> *=====================================================================
> * Init A2D: Initialize the Analog to Digital convertor
> *=====================================================================
> INIT_A2D:
> LDX #$1000 ; needed for the BRCLR command
> LDAA #%10010000 ; Power up A/D with clock delay
> STAA $39,x
> RTS > *=====================================================================
> * Read A2D values:
> *=====================================================================
> Read_A2D:
> LDAA #%00000000 ; single scan, multi-mode, pins e0-3
> STAA $30,x ; WRITE staRTS conversion >
> CONVERSION_NOT_DONE
> BRCLR $30,x $80 CONVERSION_NOT_DONE
> LDAA $31,x ; GET VALUE FORM PIN PE0
> PULX
> RTS > *=====================================================================
> * WRITE A2D: WRITE the 8 A2D values in Ram to the TERMinal.
> *=====================================================================
> WRITE_A2D:
> LDAA A2D0
> LDAB #'0
> BSR WRITE_A2D_BYTE
> LDAA A2D1
> INCB
> BSR WRITE_A2D_BYTE
> LDAA A2D2
> INCB
> BSR WRITE_A2D_BYTE
> LDAA A2D3
> INCB
> BSR WRITE_A2D_BYTE
> LDAA A2D4
> INCB
> BSR WRITE_A2D_BYTE
> LDAA A2D5
> INCB
> BSR WRITE_A2D_BYTE
> LDAA A2D6
> INCB
> BSR WRITE_A2D_BYTE
> LDAA A2D7
> INCB
> BSR WRITE_A2D_BYTE
> RTS
>
> WRITE_A2D_BYTE:
> psha
> pshb
> BSR WRITE_TERM
> LDAB #':
> BSR WRITE_TERM
> TAB
> lsrb
> lsrb
> lsrb
> lsrb
> LDY #WA2D_TABle ; 4-bits to HEX
> aby
> LDAB $00,y
> BSR WRITE_TERM
> TAB
> andb #$0F
> LDY #WA2D_TABle
> aby
> LDAB $00,y
> JSR WRITE_TERM
> LDAB #$20 ; Space
> JSR WRITE_TERM
> pulb
> pula
> RTS
> WA2D_TABle:
> fcc "0123456789ABCDEF" >
> *=====================================================================
> * WRITE 2 TERMinal:
> * Input: ASCII data in the B register.
> * Action: Wait until transmit buffer is empty, then
> * transmit the data in the B register.
> *=====================================================================
> WRITE_TERM:
> BRCLR $2e,x %10000000 WRITE_TERM ; check Transmit-empty
> STAB $2f,x
> RTS >
>
> ==============================================
> What i have done is convert the analog measurement data and sent to
> Port PE0 for conversion. The Voltage reference is 5 V for high and 0
> v for low.So, how to take the converted data from A2D result and
> shift into a 8 bit binary data and then convert to ascii code . The
> ascii code will transmit to SCI port.Thank you > To unsubscribe from this group, send an email to:




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

Re: Re: A2D binary to Ascii conversion to terminal - Liew Ban Wui - Dec 26 5:29:00 2002

Hi ,
Thanks for giving me the advice. Since i am still a beginner for MC68HC11,i hope sir can give me some advice for this problem.I am using MC68HC11A0P F92J for the project in expanded mode .As i know , the A2D results will store into ADR1-ADR4 register ($1031 to $1034).Isnt each register just hold 2 bit data ? Does i need to combine each register (ADR1 + ADR2+ ADR3 +ADR4 = 8 bit binary data) and keep as 8 bit binary data . May i know that what is the meaning of " MC68HC11 Floating Point Package" ? software code or hardware? If the measured analog data is 3.58 V(V max = 5V) , isnt the 6811 A2D will automaticlly convert it as a floating point binary output or just a decimal output only ?Since the RS232 just accept Ascii code, so how can i convert the A2D result to ASCII code ( let said 3.58 in ascii code format),I hope sir can show me the example in asembly code for me .Thank you
----- Original Message -----
From: Gordon Couger
To:
Sent: Thursday, December 26, 2002 3:09 PM
Subject: Re: [m68HC11] Re: A2D binary to Ascii conversion to terminal Why convert it to flotating point in the first place. Read the A/D register
as a short, int or long as approiate and and send it as is. If you are
going to use it on an Intel or other machine you will have to reverse the
byte in the case of an int and I don't rember how to handle a long.

If you don't need floating point don't link it in. It is SLOOOOOOW. I woked
whith a 68HC11 for 7 years professionaly and never had to use floating
point. I had to use some awkward fractions and such but I never could afford
the speed loss that F.P. cost.

I printed them out in hex on a termial because they were 8 bit A/C converers
and hex kept them in orderly rows. I used somting like witten from memory
the sentax may not be correct but you should get the idea..

char *hexstr ="0123456789ABCDEF"
void print-hex(char a)
{
char [3] s;
s[2] =0;
s[0]=hex-str[ a%16]; /* mod 16 I may have the operater wrong and the order
reversed */
s[1]=hex-str[a/16];
puts(s);
}

It's crude but small and fast and the string s was often a pointer to a
global string that I have for an output line insted of a local variable.
Again not clean but fast and small.

Gordon

Gordon Couger
Stillwater, OK
www.couger.com/gcouger
----- Original Message -----
From: <>
To: <>
Sent: Wednesday, December 25, 2002 9:55 AM
Subject: [m68HC11] Re: A2D binary to Ascii conversion to terminal > --- In , BobGardner@a... wrote:
> > In a message dated 12/25/02 12:31:21 PM Eastern Standard Time,
> > liewbw@m... writes:
> >
> > > >unsigned char addat;
> > > >float volts;
> > > >
> > > >addat=readadchan(); //read a/d
> > > >volts=addat*5.0/255.0; //convert to floating point
> > > >printf("%7.3f\n"); //print out sci terminal
> > >
> >
> > Life's too short to remember which variable is in which register.
> If you
> > really have to see what the assembly looks like, dl the imagecraft
> compiler,
> > compile it, then look at the compiler generated assembly
> language..... I
> > can't imagine anything needing assembler anymore... that's right
> you guys...
> > a challenge... bring it on... send the spec and your tightest
> assembly
> > code...
> >
> >
> > [Non-text portions of this message have been removed] >
>
> Herer is my project run
>
> Sensor --> MC68HC11 (A2D) ---> RS232 ---> Computer
> Below is the part of the asembly code for link the measured out to
> port E :
>
> *=====================================================================
> * Init A2D: Initialize the Analog to Digital convertor
> *=====================================================================
> INIT_A2D:
> LDX #$1000 ; needed for the BRCLR command
> LDAA #%10010000 ; Power up A/D with clock delay
> STAA $39,x
> RTS > *=====================================================================
> * Read A2D values:
> *=====================================================================
> Read_A2D:
> LDAA #%00000000 ; single scan, multi-mode, pins e0-3
> STAA $30,x ; WRITE staRTS conversion >
> CONVERSION_NOT_DONE
> BRCLR $30,x $80 CONVERSION_NOT_DONE
> LDAA $31,x ; GET VALUE FORM PIN PE0
> PULX
> RTS > *=====================================================================
> * WRITE A2D: WRITE the 8 A2D values in Ram to the TERMinal.
> *=====================================================================
> WRITE_A2D:
> LDAA A2D0
> LDAB #'0
> BSR WRITE_A2D_BYTE
> LDAA A2D1
> INCB
> BSR WRITE_A2D_BYTE
> LDAA A2D2
> INCB
> BSR WRITE_A2D_BYTE
> LDAA A2D3
> INCB
> BSR WRITE_A2D_BYTE
> LDAA A2D4
> INCB
> BSR WRITE_A2D_BYTE
> LDAA A2D5
> INCB
> BSR WRITE_A2D_BYTE
> LDAA A2D6
> INCB
> BSR WRITE_A2D_BYTE
> LDAA A2D7
> INCB
> BSR WRITE_A2D_BYTE
> RTS
>
> WRITE_A2D_BYTE:
> psha
> pshb
> BSR WRITE_TERM
> LDAB #':
> BSR WRITE_TERM
> TAB
> lsrb
> lsrb
> lsrb
> lsrb
> LDY #WA2D_TABle ; 4-bits to HEX
> aby
> LDAB $00,y
> BSR WRITE_TERM
> TAB
> andb #$0F
> LDY #WA2D_TABle
> aby
> LDAB $00,y
> JSR WRITE_TERM
> LDAB #$20 ; Space
> JSR WRITE_TERM
> pulb
> pula
> RTS
> WA2D_TABle:
> fcc "0123456789ABCDEF" >
> *=====================================================================
> * WRITE 2 TERMinal:
> * Input: ASCII data in the B register.
> * Action: Wait until transmit buffer is empty, then
> * transmit the data in the B register.
> *=====================================================================
> WRITE_TERM:
> BRCLR $2e,x %10000000 WRITE_TERM ; check Transmit-empty
> STAB $2f,x
> RTS >
>
> ==============================================
> What i have done is convert the analog measurement data and sent to
> Port PE0 for conversion. The Voltage reference is 5 V for high and 0
> v for low.So, how to take the converted data from A2D result and
> shift into a 8 bit binary data and then convert to ascii code . The
> ascii code will transmit to SCI port.Thank you > To unsubscribe from this group, send an email to: To unsubscribe from this group, send an email to:

Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service.
[Non-text portions of this message have been removed]


______________________________
Stellaris® MCU Family: New Parts, New Package, New Price.


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

Re: Re: A2D binary to Ascii conversion to terminal - Author Unknown - Dec 26 7:56:00 2002

In a message dated 12/26/02 5:36:31 AM Eastern Standard Time,
writes:

> .As i know , the A2D results will store into ADR1-ADR4 register ($1031 to
> $1034).Isnt each register just hold 2 bit data ? Does i need to combine
> each register (ADR1 + ADR2+ ADR3 +ADR4 = 8 bit binary data) and keep as 8
> bit binary data . May i know that what is the meaning of " MC68HC11
> Floating Point Package" ? software code or hardware? If the measured analog
> data is 3.58 V(V max = 5V) , isnt the 6811 A2D will automaticlly convert it
> as a floating point binary output or just a decimal output only ?Since the
> RS232 just accept Ascii code, so how can i convert the A2D result to ASCII
> code ( let said 3.58 in ascii code format),I hope sir can show me the
> example in asembly code for me .Thank you Each register holds an 8 bit byte...one a/d conversion result. There are 8
channels on the multiplexer.... you can read 8 different analog voltages. The
Floating Point Package is a subroutine library to do single precision
floating point in software...Many would say this is unnecessary... the same
computations can be done using integer arithmetic... the a/d converter just
gives an 8 bit result 0 to 255... if you need this in volts, you must call
the floating point routines to convert the integer to ploating point, call
the floating point multiply/add/divide routines as needed.... all this detail
is tedious in assembler... rather than spend days learning all this low level
stuff, spend a couple days learning to compile and burn some one page c
programs... you'll be more productive in the long run.... [Non-text portions of this message have been removed]




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

Re: Re: A2D binary to Ascii conversion to terminal - Liew Ban Wui - Dec 26 8:00:00 2002

So it mean if I just use 1 channel (PE0) for analog input only, so i just need to take the ADR1 register output only ,then convert it to ascii code.below is the floating point conversion code example. After i take the output from register ADR1, i move the data to the fp routine, it will display output as ASCii, right ? ******************************************************************************

* FLOATING POINT TO ASCII CONVERSION SUBROUTINE *

* This subroutine performs floating point to ASCII conversion of *

* the number in FPACC1. The ascii string is placed in a buffer *

* pointed to by the X index register. The buffer must be at least *

* 14 bytes long to contain the ASCII conversion. The resulting *

* ASCII string is terminated by a zero (0) byte. Upon exit the *

* X Index register will be pointing to the first character of the *

* string. FPACC1 and FPACC2 will remain unchanged. *

******************************************************************************

FLTASC EQU *

PSHX SAVE THE POINTER TO THE STRING BUFFER.

LDX #FPACC1EX POINT TO FPACC1.

JSR CHCK0 IS FPACC1 0?

BNE FLTASC1 NO. GO CONVERT THE NUMBER.

PULX RESTORE POINTER.

LDD #$3000 GET ASCII CHARACTER + TERMINATING BYTE.

STD 0,X PUT IT IN THE BUFFER.

RTS RETURN.

FLTASC1 LDX FPACC1EX SAVE FPACC1.

PSHX

LDX FPACC1MN+1

PSHX

LDAA MANTSGN1

PSHA

JSR PSHFPAC2 SAVE FPACC2.

LDX #0

PSHX ALLOCATE LOCALS.

PSHX

PSHX SAVE SPACE FOR STRING BUFFER POINTER.

TSY POINT TO LOCALS.

LDX 15,Y GET POINTER FROM STACK.

LDAA #$20 PUT A SPACE IN THE BUFFER IF NUMBER NOT NEGATIVE.

TST MANTSGN1 IS IT NEGATIVE?

BEQ FLTASC2 NO. GO PUT SPACE.

CLR MANTSGN1 MAKE NUMBER POSITIVE FOR REST OF CONVERSION.

LDAA #'- YES. PUT MINUS SIGN IN BUFFER.

FLTASC2 STAA 0,X

INX POINT TO NEXT LOCATION.

STX 0,Y SAVE POINTER.

FLTASC5 LDX #N9999999 POINT TO CONSTANT 9999999.

JSR GETFPAC2 GET INTO FPACC2.

JSR FLTCMP COMPARE THE NUMBERS. IS FPACC1 > 9999999?

BHI FLTASC3 YES. GO DIVIDE FPACC1 BY 10.

LDX #P9999999 POINT TO CONSTANT 999999.9

JSR GETFPAC2 MOVE IT INTO FPACC2.

JSR FLTCMP COMPARE NUMBERS. IS FPACC1 > 999999.9?

BHI FLTASC4 YES. GO CONTINUE THE CONVERSION.

DEC 2,Y DECREMENT THE MULT./DIV. COUNT.

LDX #CONST10 NO. MULTIPLY BY 10. POINT TO CONSTANT.

FLTASC6 JSR GETFPAC2 MOVE IT INTO FPACC2.

JSR FLTMUL

BRA FLTASC5 GO DO COMPARE AGAIN.

FLTASC3 INC 2,Y INCREMENT THE MULT./DIV. COUNT.

LDX #CONSTP1 POINT TO CONSTANT ".1".

BRA FLTASC6 GO DIVIDE FPACC1 BY 10.

FLTASC4 LDX #CONSTP5 POINT TO CONSTANT OF ".5".

JSR GETFPAC2 MOVE IT INTO FPACC2.

JSR FLTADD ADD .5 TO NUMBER IN FPACC1 TO ROUND IT.

LDAB FPACC1EX GET FPACC1 EXPONENT.

SUBB #$81 TAKE OUT BIAS +1.

NEGB MAKE IT NEGATIVE.

ADDB #23 ADD IN THE NUMBER OF MANTISSA BITS -1.

BRA FLTASC17 GO CHECK TO SEE IF WE NEED TO SHIFT AT ALL.

FLTASC7 LSR FPACC1MN SHIFT MANTISSA TO THE RIGHT BY THE RESULT (MAKE

ROR FPACC1MN+1 THE NUMBER AN INTEGER).

ROR FPACC1MN+2

DECB DONE SHIFTING?

FLTASC17 BNE FLTASC7 NO. KEEP GOING.

LDAA #1 GET INITIAL VALUE OF "DIGITS AFTER D.P." COUNT.

STAA 3,Y INITIALIZE IT.

LDAA 2,Y GET DECIMAL EXPONENT.

ADDA #8 ADD THE NUMBER OF DECIMAL +1 TO THE EXPONENT.

* WAS THE ORIGINAL NUMBER > 9999999?

BMI FLTASC8 YES. MUST BE REPRESENTED IN SCIENTIFIC NOTATION.

CMPA #8 WAS THE ORIGINAL NUMBER < 1?

BHS FLTASC8 YES. MUST BE REPRESENTED IN SCIENTIFIC NOTATION.

DECA NO. NUMBER CAN BE REPRESENTED IN 7 DIGITS.

STAA 3,Y MAKE THE DECIMAL EXPONENT THE DIGIT COUNT BEFORE

* THE DECIMAL POINT.

LDAA #2 SETUP TO ZERO THE DECIMAL EXPONENT.

FLTASC8 SUBA #2 SUBTRACT 2 FROM THE DECIMAL EXPONENT.

STAA 2,Y SAVE THE DECIMAL EXPONENT.

TST 3,Y DOES THE NUMBER HAVE AN INTEGER PART? (EXP. >0)

BGT FLTASC9 YES. GO PUT IT OUT.9

LDAA #'. NO. GET DECIMAL POINT.

LDX 0,Y GET POINTER TO BUFFER.

STAA 0,X PUT THE DECIMAL POINT IN THE BUFFER.

INX POINT TO NEXT BUFFER LOCATION.

TST 3,Y IS THE DIGIT COUNT TILL EXPONENT =0?

BEQ FLTASC18 NO. NUMBER IS <.1

LDAA #'0 YES. FORMAT NUMBER AS .0XXXXXXX

STAA 0,X PUT THE 0 IN THE BUFFER.

INX POINT TO THE NEXT LOCATION.

FLTASC18 STX 0,Y SAVE NEW POINTER VALUE.

FLTASC9 LDX #DECDIG POINT TO THE TABLE OF DECIMAL DIGITS.

LDAA #7 INITIALIZE THE THE NUMBER OF DIGITS COUNT.

STAA 5,Y

FLTASC10 CLR 4,Y CLEAR THE DECIMAL DIGIT ACCUMULATOR.

FLTASC11 LDD FPACC1MN+1 GET LOWER 16 BITS OF MANTISSA.

SUBD 1,X SUBTRACT LOWER 16 BITS OF CONSTANT.

STD FPACC1MN+1 SAVE RESULT.

LDAA FPACC1MN GET UPPER 8 BITS.

SBCA 0,X SUBTRACT UPPER 8 BITS.

STAA FPACC1MN SAVE RESULT. UNDERFLOW?

BCS FLTASC12 YES. GO ADD DECIMAL NUMBER BACK IN.

INC 4,Y ADD 1 TO DECIMAL NUMBER.

BRA FLTASC11 TRY ANOTHER SUBTRACTION.

FLTASC12 LDD FPACC1MN+1 GET FPACC1 MANTISSA LOW 16 BITS.

ADDD 1,X ADD LOW 16 BITS BACK IN.

STD FPACC1MN+1 SAVE THE RESULT.

LDAA FPACC1MN GET HIGH 8 BITS.

ADCA 0,X ADD IN HIGH 8 BITS OF CONSTANT.

STAA FPACC1MN SAVE RESULT.

LDAA 4,Y GET DIGIT.

ADDA #$30 MAKE IT ASCII.

PSHX SAVE POINTER TO CONSTANTS.

LDX 0,Y GET POINTER TO BUFFER.

STAA 0,X PUT DIGIT IN BUFFER.

INX POINT TO NEXT BUFFER LOCATION.

DEC 3,Y SHOULD WE PUT A DECIMAL POINT IN THE BUFFER YET?

BNE FLTASC16 NO. CONTINUE THE CONVERSION.

LDAA #'. YES. GET DECIMAL POINT.

STAA 0,X PUT IT IN THE BUFFER.

INX POINT TO THE NEXT BUFFER LOCATION.

FLTASC16 STX 0,Y SAVE UPDATED POINTER.

PULX RESTORE POINTER TO CONSTANTS.

INX POINT TO NEXT CONSTANT.

INX

INX

DEC 5,Y DONE YET?

BNE FLTASC10 NO. CONTINUE CONVERSION OF "MANTISSA".

LDX 0,Y YES. POINT TO BUFFER STRING BUFFER.

FLTASC13 DEX POINT TO LAST CHARACTER PUT IN THE BUFFER.

LDAA 0,X GET IT.

CMPA #$30 WAS IT AN ASCII 0?

BEQ FLTASC13 YES. REMOVE TRAILING ZEROS.

INX POINT TO NEXT AVAILABLE LOCATION IN BUFFER.

LDAB 2,Y DO WE NEED TO PUT OUT AN EXPONENT?

BEQ FLTASC15 NO. WE'RE DONE.

LDAA #'E YES. PUT AN 'E' IN THE BUFFER.

STAA 0,X

INX POINT TO NEXT BUFFER LOCATION.

LDAA #'+ ASSUME EXPONENT IS POSITIVE.

STAA 0,X PUT PLUS SIGN IN THE BUFFER.

TSTB IS IT REALLY MINUS?

BPL FLTASC14 NO. IS'S OK AS IS.

NEGB YES. MAKE IT POSITIVE.

LDAA #'- PUT THE MINUS SIGN IN THE BUFFER.

STAA 0,X

FLTASC14 INX POINT TO NEXT BUFFER LOCATION.

STX 0,Y SAVE POINTER TO STRING BUFFER.

CLRA SET UP FOR DIVIDE.

LDX #10 DIVIDE DECIMAL EXPONENT BY 10.

IDIV

PSHB SAVE REMAINDER.

XGDX PUT QUOTIENT IN D.

ADDB #$30 MAKE IT ASCII.

LDX 0,Y GET POINTER.

STAB 0,X PUT NUMBER IN BUFFER.

INX POINT TO NEXT LOCATION.

PULB GET SECOND DIGIT.

ADDB #$30 MAKE IT ASCII.

STAB 0,X PUT IT IN THE BUFFER.

INX POINT TO NEXT LOCATION.

FLTASC15 CLR 0,X TERMINATE STRING WITH A ZERO BYTE.

PULX CLEAR LOCALS FROM STACK.

PULX

PULX

JSR PULFPAC2 RESTORE FPACC2.

PULA

STAA MANTSGN1

PULX RESTORE FPACC1.

STX FPACC1MN+1

PULX

STX FPACC1EX

PULX POINT TO THE START OF THE ASCII STRING.

RTS RETURN.

*

*

DECDIG EQU *

FCB $0F,$42,$40 DECIMAL 1,000,000

FCB $01,$86,$A0 DECIMAL 100,000

FCB $00,$27,$10 DECIMAL 10,000

FCB $00,$03,$E8 DECIMAL 1,000

FCB $00,$00,$64 DECIMAL 100

FCB $00,$00,$0A DECIMAL 10

FCB $00,$00,$01 DECIMAL 1

*

*

P9999999 EQU * CONSTANT 999999.9

FCB $94,$74,$23,$FE

*

N9999999 EQU * CONSTANT 9999999.

FCB $98,$18,$96,$7F

*

CONSTP5 EQU * CONSTANT .5

FCB $80,$00,$00,$00

*

*

FLTCMP EQU *

TST MANTSGN1 IS FPACC1 NEGATIVE?

BPL FLTCMP2 NO. CONTINUE WITH COMPARE.

TST MANTSGN2 IS FPACC2 NEGATIVE?

BPL FLTCMP2 NO. CONTINUE WITH COMPARE.

LDD FPACC2EX YES. BOTH ARE NEGATIVE SO COMPARE MUST BE DONE

CPD FPACC1EX BACKWARDS. ARE THEY EQUAL SO FAR?

BNE FLTCMP1 NO. RETURN WITH CONDITION CODES SET.

LDD FPACC2MN+1 YES. COMPARE LOWER 16 BITS OF MANTISSAS.

CPD FPACC1MN+1

FLTCMP1 RTS RETURN WITH CONDITION CODES SET.

FLTCMP2 LDAA MANTSGN1 GET FPACC1 MANTISSA SIGN.

CMPA MANTSGN2 BOTH POSITIVE?

BNE FLTCMP1 NO. RETURN WITH CONDITION CODES SET.

LDD FPACC1EX GET FPACC1 EXPONENT & UPPER 8 BITS OF MANTISSA.

CPD FPACC2EX SAME AS FPACC2?

BNE FLTCMP1 NO. RETURN WITH CONDITION CODES SET.

LDD FPACC1MN+1 GET FPACC1 LOWER 16 BITS OF MANTISSA.

CPD FPACC2MN+1 COMPARE WITH FPACC2 LOWER 16 BITS OF MANTISSA.

RTS RETURN WITH CONDITION CODES SET.

*

*

*

TTL INT2FLT ----- Original Message -----
From:
To:
Sent: Thursday, December 26, 2002 8:56 PM
Subject: Re: [m68HC11] Re: A2D binary to Ascii conversion to terminal In a message dated 12/26/02 5:36:31 AM Eastern Standard Time,
writes:

> .As i know , the A2D results will store into ADR1-ADR4 register ($1031 to
> $1034).Isnt each register just hold 2 bit data ? Does i need to combine
> each register (ADR1 + ADR2+ ADR3 +ADR4 = 8 bit binary data) and keep as 8
> bit binary data . May i know that what is the meaning of " MC68HC11
> Floating Point Package" ? software code or hardware? If the measured analog
> data is 3.58 V(V max = 5V) , isnt the 6811 A2D will automaticlly convert it
> as a floating point binary output or just a decimal output only ?Since the
> RS232 just accept Ascii code, so how can i convert the A2D result to ASCII
> code ( let said 3.58 in ascii code format),I hope sir can show me the
> example in asembly code for me .Thank you Each register holds an 8 bit byte...one a/d conversion result. There are 8
channels on the multiplexer.... you can read 8 different analog voltages. The
Floating Point Package is a subroutine library to do single precision
floating point in software...Many would say this is unnecessary... the same
computations can be done using integer arithmetic... the a/d converter just
gives an 8 bit result 0 to 255... if you need this in volts, you must call
the floating point routines to convert the integer to ploating point, call
the floating point multiply/add/divide routines as needed.... all this detail
is tedious in assembler... rather than spend days learning all this low level
stuff, spend a couple days learning to compile and burn some one page c
programs... you'll be more productive in the long run.... [Non-text portions of this message have been removed] To unsubscribe from this group, send an email to:

Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service.
[Non-text portions of this message have been removed]


______________________________
Stellaris® MCU Family: New Parts, New Package, New Price.


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

Re: Re: A2D binary to Ascii conversion to terminal - Robert Smith - Dec 26 9:18:00 2002

I have been watching this thread with interest and have become concerned
that the author has been exposed to some serious misunderstandings with
regard to the operation of the 'HC11 A/D Converter Subsystem, 'HC11 data
formats, and the operation of RS-232 serial data systems in general. Below,
I will inject some comments intended to help him with his project.

Bob Smith --- Avoid computer viruses, Practice safe hex ---

-- Specializing in small, cost effective
embedded control systems -- Robert L. (Bob) Smith
Smith Machine Works, Inc.
9900 Lumlay Road
Richmond, VA 23236 804/745-1065
----- Original Message -----
From: "Liew Ban Wui" <>
To: <>
Cc: <>
Sent: Thursday, December 26, 2002 5:29 AM
Subject: Re: [m68HC11] Re: A2D binary to Ascii conversion to terminal > Hi ,
> Thanks for giving me the advice. Since i am still a beginner for
MC68HC11,i hope sir can give me some advice for this problem.I am using
MC68HC11A0P F92J for the project in expanded mode .

This does not seem like a familiar 'HC11A0 part number, particularily the
"PF92J" part of it. Since it seems to be an 'A0' part, I will proceed on
that basis.

BUT, WARNING, the 'A0 family has been obsoleted by Motorola and is in short
supply. I recommend immediate conversion to the E family devices. Motorola
has an Engineering Bullentin on A to E family conversion considerations at
the web site.

As i know , the A2D results will store into ADR1-ADR4 register ($1031 to
$1034).Isnt each register just hold 2 bit data ?

Major misconception! Each A/D result register returns an 8 bit unsigned
binary number (In the range of $00 to $FF). The result returned is related
to the A/D input voltage for the specified input channel according to the
following formula:

Rx = Vx / (Vrh - Vrl) *256

Where:

Rx = The converted value from the A/D result register number x.

Vx = The voltage applied to the selected input pin (PE[0:3]).

Vrh = The voltage applied to the Vrh (Reference High) pin of the A/D
subsystem.

Vrl = The voltage applied to the Vrl (Reference Low) pin of the A/D
subsystem.

What the above equation is trying to say in plain language is that the range
(Vrh - Vrl) of the reference volatage is divided into 256 equal increments
and is being compared to the unknown input voltage (Vx).
Then, using successive approximation techniques, the nearest increment is
selected and the result is expressed as number of the increment in the range
of 0 - 255 (decimal). For Vx equal to or greater than Vrh, the result will
always be 255. For Vx <= Vrl, the result will always be 0.

Note - As explained in the Pink Book, Section 12, the HC11 A/D converter
subsystem is a successive approximation converter using a
"charge-redistribution" (as opposed to the usual R/R2 resitive ladder)
technology. The operation of this interesting A/D converter is thoroughly
and well explained in the Pink Book, Section 12, "Analog to Digital
Converter Subsystem".

Further Note - Due to historical precedence, I will continue to refer to
Motorola Document M68HC11RM/D, "M68HC11 Reference Manual" as the "Pink
Book", even though the latest edition, Rev. 6, 4/2002, has (believe it or
not!) _white_ covers!!!!! (Heresy, I shout, heresy!!) Caution - there are
substantial differences in page numbers and section numbering between recent
editions. All references in this post are with respect Rev. 6.

Does i need to combine each register (ADR1 + ADR2+ ADR3 +ADR4 = 8 bit
binary data) and keep as
8 bit binary data .

Another misconception. No, each result register returns a full eight bit
result, no combining is needed.

May i know that what is the meaning of " MC68HC11 Floating Point Package" ?
software code or hardware?

I am not personally familiar with this package, but will observe that there
is no such thing as floating point hardware for the MC68HC11 family devices.
As for floating point software, I have never needed it for the 'HC11. Any
"real number" calculations that I have needed have been handled in C (ICC11
See http://www.imagecraft.com ). Given the somewhat limited computational
power of the 'HC11 I avoid floating point calculations at all costs.

If the measured analog data is 3.58 V(V max = 5V) , isnt the 6811 A2D will
automaticlly convert it as a floating point binary output or just a decimal
output only ?

A further misconception -- The A/D subsystem only outputs fixed point binary
numbers in the range of 0 to 255 (decimal), see the Pink Book Section 12 for
further information.

Since the RS232 just accept Ascii code,

This is also a misconception, RS-232 serial links can handle any arbitrary
data format, it is entirely up to the programmer(s) involved to determine
the format of the data transmitted. The 'HC11 SC1 can, in fact, transmit as
many as 9 bits of data per character so that 8 bit data with parity can be
transmitted to any terminal device capable of accepting it. It _is_ true
that the 'HC11 SCI doesn't include a parity generator, but this can easily
be handled in software if desired. (For critical applications, however, I
prefer to provide data integrity using CRC checks as opposed to simple
parity checks.

so how can i convert the A2D result to ASCII code ( let said 3.58 in ascii
code format),

See above, there is no need to convert the A/D result to ASCII format. Just
transmit the 8 bit result directly to the receiver (much simplier and
results is much more efficient use of the serial link).

For example, using the formula given above, 3.58 V input should convert to
(assuming a 5 V reference):

3.58 / (5.00 - 0.00) * 256 = 183 (decimal) or $B7 (hexidecimal)

Just transmit the $B7 via the SCI link.

Now, here is an old technique that you may find useful.

It is common practice to operate the A/D using Vdd and Vss for Vrh and Vrl
respectively (with an appropriate low pass filter (See the Pink Book,
Section 2.4.7, "A/D Reference and Port E Pins".

Using a nominal 5.000 V supply, this results in an A/D conversion resolution
increment of 19.531 millivolts per increment, a rather inconvenient step to
work with if you intend to present your conversion results in plain
language, decimal format increments.

It is also well known that the 'HC11 devices will operate with a supply
voltage range of 4.5 to 5.5 (+/-10%) (See the M68HC11 E Series Technical
Data, Table A-3).

Now, this suggests raising the supply voltage to the 'HC11 slightly to 5.120
V. With 5.120 V applied to (Vrh - Vrl) the increment for an A/D converter
step will now be a neat 20.0 millivolts per increment. Thus, conversion to
plain language requires a simple shift operation. To restate your example
with a 5.12 Volt reference:

3.58 / 5.12 * 256 = 179 (decimal)

Now shift left one, 179 * 2 = 358 (Note that 16 bit precision is required,
a simple operation on the 'HC11)

(Rounding and truncation considerations are left as an excercise to the
student)

I hope sir can show me the example in asembly code for me.

Sorry, I am willing to lead you to knowledge, but I won't do your work for
you. If you require further design and conslulting services, feel free to
contact me for rates and availability.

Best wishes on your project.

Thank you

> ----- Original Message -----
> From: Gordon Couger
> To:
> Sent: Thursday, December 26, 2002 3:09 PM
> Subject: Re: [m68HC11] Re: A2D binary to Ascii conversion to terminal > Why convert it to flotating point in the first place. Read the A/D
register
> as a short, int or long as approiate and and send it as is. If you are
> going to use it on an Intel or other machine you will have to reverse
the
> byte in the case of an int and I don't rember how to handle a long.
>
> If you don't need floating point don't link it in. It is SLOOOOOOW. I
woked
> whith a 68HC11 for 7 years professionaly and never had to use floating
> point. I had to use some awkward fractions and such but I never could
afford
> the speed loss that F.P. cost.
>
> I printed them out in hex on a termial because they were 8 bit A/C
converers
> and hex kept them in orderly rows. I used somting like witten from
memory
> the sentax may not be correct but you should get the idea..
>
> char *hexstr ="0123456789ABCDEF"
> void print-hex(char a)
> {
> char [3] s;
> s[2] =0;
> s[0]=hex-str[ a%16]; /* mod 16 I may have the operater wrong and the
order
> reversed */
> s[1]=hex-str[a/16];
> puts(s);
> }
>
> It's crude but small and fast and the string s was often a pointer to a
> global string that I have for an output line insted of a local variable.
> Again not clean but fast and small.
>
> Gordon
>
> Gordon Couger
> Stillwater, OK
> www.couger.com/gcouger
> ----- Original Message -----
> From: <>
> To: <>
> Sent: Wednesday, December 25, 2002 9:55 AM
> Subject: [m68HC11] Re: A2D binary to Ascii conversion to terminal > > --- In , BobGardner@a... wrote:
> > > In a message dated 12/25/02 12:31:21 PM Eastern Standard Time,
> > > liewbw@m... writes:
> > >
> > > > >unsigned char addat;
> > > > >float volts;
> > > > >
> > > > >addat=readadchan(); //read a/d
> > > > >volts=addat*5.0/255.0; //convert to floating point
> > > > >printf("%7.3f\n"); //print out sci terminal
> > > >
> > >
> > > Life's too short to remember which variable is in which register.
> > If you
> > > really have to see what the assembly looks like, dl the imagecraft
> > compiler,
> > > compile it, then look at the compiler generated assembly
> > language..... I
> > > can't imagine anything needing assembler anymore... that's right
> > you guys...
> > > a challenge... bring it on... send the spec and your tightest
> > assembly
> > > code...
> > >
> > >
> > > [Non-text portions of this message have been removed]
> >
> >
> >
> >
> > Herer is my project run
> >
> > Sensor --> MC68HC11 (A2D) ---> RS232 ---> Computer
> > Below is the part of the asembly code for link the measured out to
> > port E :
> >
> > *=====================================================================
> > * Init A2D: Initialize the Analog to Digital convertor
> > *=====================================================================
> > INIT_A2D:
> > LDX #$1000 ; needed for the BRCLR command
> > LDAA #%10010000 ; Power up A/D with clock delay
> > STAA $39,x
> > RTS
> >
> >
> > *=====================================================================
> > * Read A2D values:
> > *=====================================================================
> > Read_A2D:
> > LDAA #%00000000 ; single scan, multi-mode, pins e0-3
> > STAA $30,x ; WRITE staRTS conversion
> >
> >
> >
> > CONVERSION_NOT_DONE
> > BRCLR $30,x $80 CONVERSION_NOT_DONE
> > LDAA $31,x ; GET VALUE FORM PIN PE0
> > PULX
> > RTS
> >
> >
> > *=====================================================================
> > * WRITE A2D: WRITE the 8 A2D values in Ram to the TERMinal.
> > *=====================================================================
> > WRITE_A2D:
> > LDAA A2D0
> > LDAB #'0
> > BSR WRITE_A2D_BYTE
> > LDAA A2D1
> > INCB
> > BSR WRITE_A2D_BYTE
> > LDAA A2D2
> > INCB
> > BSR WRITE_A2D_BYTE
> > LDAA A2D3
> > INCB
> > BSR WRITE_A2D_BYTE
> > LDAA A2D4
> > INCB
> > BSR WRITE_A2D_BYTE
> > LDAA A2D5
> > INCB
> > BSR WRITE_A2D_BYTE
> > LDAA A2D6
> > INCB
> > BSR WRITE_A2D_BYTE
> > LDAA A2D7
> > INCB
> > BSR WRITE_A2D_BYTE
> > RTS
> >
> > WRITE_A2D_BYTE:
> > psha
> > pshb
> > BSR WRITE_TERM
> > LDAB #':
> > BSR WRITE_TERM
> > TAB
> > lsrb
> > lsrb
> > lsrb
> > lsrb
> > LDY #WA2D_TABle ; 4-bits to HEX
> > aby
> > LDAB $00,y
> > BSR WRITE_TERM
> > TAB
> > andb #$0F
> > LDY #WA2D_TABle
> > aby
> > LDAB $00,y
> > JSR WRITE_TERM
> > LDAB #$20 ; Space
> > JSR WRITE_TERM
> > pulb
> > pula
> > RTS
> > WA2D_TABle:
> > fcc "0123456789ABCDEF"
> >
> >
> >
> > *=====================================================================
> > * WRITE 2 TERMinal:
> > * Input: ASCII data in the B register.
> > * Action: Wait until transmit buffer is empty, then
> > * transmit the data in the B register.
> > *=====================================================================
> > WRITE_TERM:
> > BRCLR $2e,x %10000000 WRITE_TERM ; check Transmit-empty
> > STAB $2f,x
> > RTS
> >
> >
> >
> >
> >
> >
> >
> > ==============================================
> > What i have done is convert the analog measurement data and sent to
> > Port PE0 for conversion. The Voltage reference is 5 V for high and 0
> > v for low.So, how to take the converted data from A2D result and
> > shift into a 8 bit binary data and then convert to ascii code . The
> > ascii code will transmit to SCI port.Thank you
> >
> >
> >
> >
> >
> >
> >
> >
> > To unsubscribe from this group, send an email to:
> >
> >
> >
> >
> >
> > To unsubscribe from this group, send an email to:






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

Re: Re: A2D binary to Ascii conversion to terminal - MAOS - Dec 26 10:05:00 2002

On Thursday 26 December 2002 08:18, Robert Smith wrote:
> I have been watching this thread with interest and have become concerned
> that the author has been exposed to some serious misunderstandings with
> regard to the operation of the 'HC11 A/D Converter Subsystem, 'HC11 data
> formats, and the operation of RS-232 serial data systems in general.
> Below, I will inject some comments intended to help him with his project.
>
> Bob Smith

I too have been following this thread, and agree your comments were needed.

I am a student and have a basic understanding of the 6811 so I could not have
provided such good infomation. I want to take the time to thank you Bob Smith
for taking the time to explain all that you did. Your comments are always
helpful. Of course that goes for everyone else that posts here.

Happy Holidays

Thanks,
Bob Davis




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

Re: Re: A2D binary to Ascii conversion to terminal - Gordon Couger - Dec 26 16:15:00 2002

In a 68HC11 the A/D converter returns a 8 bit variable that can be handled
as a char or short it the compiler suoprts it. The value of the variable it
its numeric contents times 1/256 time the refferece voltage for the A/D
converter. The refferce voltage is usualy 5 volts but can be lowered to 2.5
volts for better resolution. At no time is it floating point unless you
convert to floation point.

Considering the low resoluton of the A/D converter using 16 bit intergs and
fixed point math is a much faster and uses less memory. You scale every
thing by a factor of 10 or 100 and divide by the scaling factor at the end.
If you need even faster code
scale be a power of 2 so you can us shifts insted of divide instrution to
get you results. The divide instruction is one of the slowest instructions
on the 68hc11.

If you are serious about working with microprocessors I suggest you learn C
and develop a set of libraies for common needs. Using C for embeded system
is different than using it on PCs. The large slow function like scanf()
printf() and functins that alocate memory should be used with extreem
caution. They are slow, eat memory and in the case of function that alocat
memory can cause real problems in system using small amouts of RAM. A copy
of Phluger's(sp) Standard C Liberay is great invetment to see what the
library functions are doing and some of the best example C code in the
world.

For the student there are ports of GCC to the 68hc11, Dunfield's C Compiler
and Introl's C compiler all for about 100 UDS. There may be some free GCC
compilers but getting them running may be worth the $100 dollars. I have
extensively used Dunfield's and Introl and can recomend them with out
reservation. Dunfieilds is a full commerical copy for $99 while Introls is
a non comercial only version. Dunfiled handles longs a little different than
most compilers his can be defiend any size you wish but come with a speed
penalty. The real up side to Dunfields compiler is the techical support you
get it from the guy that wrote ever line of the code and he makes his living
progaming embeded systems. It is an abosluty solid compiler.

Using C as scafold for assembly language is the fastest way I have found to
deveop programs C is fast enough for 95% of what you do and all the
compilers I know of allow for assembly instructions to be included in the C
compilers.

Here is the set up I use. http://www.couger.com/gcouger/newmicros.html
The editor is out of date and no longer supported. There might be some nicer
solution to the ROM emulator and I would do any new work on a 68HC12
probably using this board
http://www.newmicros.com/index2.php?url=http%3A%2F%2Fwww.newmicros.com%2Fcgi
-bin%2Fstore%2Forder.cgi%3Fform%3Dprod_detail%26part%3DNMIX-0022-OEM and I
would get the FORTH on it to act as a moniter for debuging hardware. There
is nothing like having something you know works that you can load in to test
for bugs. This chip comes with CAN and the equilivent for pasenger car
networks in place of the extra RS232.

That is a very inexpensive set up that give very fast edit, compile, link,
load, run, crash, compile times on order of 20 seconds for the compile, link
load and run. It is fast enough that it enocourges bad practics of not
thinking beforeyou try something. Gordon

Gordon Couger
Stillwater, OK
www.couger.com/gcouger
----- Original Message -----
From: "Liew Ban Wui" <>
To: <>
Cc: <>
Sent: Thursday, December 26, 2002 2:29 AM
Subject: Re: [m68HC11] Re: A2D binary to Ascii conversion to terminal > Hi ,
> Thanks for giving me the advice. Since i am still a beginner for
MC68HC11,i hope sir can give me some advice for this problem.I am using
MC68HC11A0P F92J for the project in expanded mode .As i know , the A2D
results will store into ADR1-ADR4 register ($1031 to $1034).Isnt each
register just hold 2 bit data ? Does i need to combine each register (ADR1 +
ADR2+ ADR3 +ADR4 = 8 bit binary data) and keep as 8 bit binary data . May i
know that what is the meaning of " MC68HC11 Floating Point Package" ?
software code or hardware? If the measured analog data is 3.58 V(V max = 5V)
, isnt the 6811 A2D will automaticlly convert it as a floating point binary
output or just a decimal output only ?Since the RS232 just accept Ascii
code, so how can i convert the A2D result to ASCII code ( let said 3.58 in
ascii code format),I hope sir can show me the example in asembly code for me
.Thank you
> ----- Original Message -----
> From: Gordon Couger
> To:
> Sent: Thursday, December 26, 2002 3:09 PM
> Subject: Re: [m68HC11] Re: A2D binary to Ascii conversion to terminal > Why convert it to flotating point in the first place. Read the A/D
register
> as a short, int or long as approiate and and send it as is. If you are
> going to use it on an Intel or other machine you will have to reverse
the
> byte in the case of an int and I don't rember how to handle a long.
>
> If you don't need floating point don't link it in. It is SLOOOOOOW. I
woked
> whith a 68HC11 for 7 years professionaly and never had to use floating
> point. I had to use some awkward fractions and such but I never could
afford
> the speed loss that F.P. cost.
>
> I printed them out in hex on a termial because they were 8 bit A/C
converers
> and hex kept them in orderly rows. I used somting like witten from
memory
> the sentax may not be correct but you should get the idea..
>
> char *hexstr ="0123456789ABCDEF"
> void print-hex(char a)
> {
> char [3] s;
> s[2] =0;
> s[0]=hex-str[ a%16]; /* mod 16 I may have the operater wrong and the
order
> reversed */
> s[1]=hex-str[a/16];
> puts(s);
> }
>
> It's crude but small and fast and the string s was often a pointer to a
> global string that I have for an output line insted of a local variable.
> Again not clean but fast and small.
>
> Gordon
>
> Gordon Couger
> Stillwater, OK
> www.couger.com/gcouger
> ----- Original Message -----
> From: <>
> To: <>
> Sent: Wednesday, December 25, 2002 9:55 AM
> Subject: [m68HC11] Re: A2D binary to Ascii conversion to terminal > > --- In , BobGardner@a... wrote:
> > > In a message dated 12/25/02 12:31:21 PM Eastern Standard Time,
> > > liewbw@m... writes:
> > >
> > > > >unsigned char addat;
> > > > >float volts;
> > > > >
> > > > >addat=readadchan(); //read a/d
> > > > >volts=addat*5.0/255.0; //convert to floating point
> > > > >printf("%7.3f\n"); //print out sci terminal
> > > >
> > >
> > > Life's too short to remember which variable is in which register.
> > If you
> > > really have to see what the assembly looks like, dl the imagecraft
> > compiler,
> > > compile it, then look at the compiler generated assembly
> > language..... I
> > > can't imagine anything needing assembler anymore... that's right
> > you guys...
> > > a challenge... bring it on... send the spec and your tightest
> > assembly
> > > code...
> > >
> > >
> > > [Non-text portions of this message have been removed]
> >
> >
> >
> >
> > Herer is my project run
> >
> > Sensor --> MC68HC11 (A2D) ---> RS232 ---> Computer
> > Below is the part of the asembly code for link the measured out to
> > port E :
> >
> > *=====================================================================
> > * Init A2D: Initialize the Analog to Digital convertor
> > *=====================================================================
> > INIT_A2D:
> > LDX #$1000 ; needed for the BRCLR command
> > LDAA #%10010000 ; Power up A/D with clock delay
> > STAA $39,x
> > RTS
> >
> >
> > *=====================================================================
> > * Read A2D values:
> > *=====================================================================
> > Read_A2D:
> > LDAA #%00000000 ; single scan, multi-mode, pins e0-3
> > STAA $30,x ; WRITE staRTS conversion
> >
> >
> >
> > CONVERSION_NOT_DONE
> > BRCLR $30,x $80 CONVERSION_NOT_DONE
> > LDAA $31,x ; GET VALUE FORM PIN PE0
> > PULX
> > RTS
> >
> >
> > *=====================================================================
> > * WRITE A2D: WRITE the 8 A2D values in Ram to the TERMinal.
> > *=====================================================================
> > WRITE_A2D:
> > LDAA A2D0
> > LDAB #'0
> > BSR WRITE_A2D_BYTE
> > LDAA A2D1
> > INCB
> > BSR WRITE_A2D_BYTE
> > LDAA A2D2
> > INCB
> > BSR WRITE_A2D_BYTE
> > LDAA A2D3
> > INCB
> > BSR WRITE_A2D_BYTE
> > LDAA A2D4
> > INCB
> > BSR WRITE_A2D_BYTE
> > LDAA A2D5
> > INCB
> > BSR WRITE_A2D_BYTE
> > LDAA A2D6
> > INCB
> > BSR WRITE_A2D_BYTE
> > LDAA A2D7
> > INCB
> > BSR WRITE_A2D_BYTE
> > RTS
> >
> > WRITE_A2D_BYTE:
> > psha
> > pshb
> > BSR WRITE_TERM
> > LDAB #':
> > BSR WRITE_TERM
> > TAB
> > lsrb
> > lsrb
> > lsrb
> > lsrb
> > LDY #WA2D_TABle ; 4-bits to HEX
> > aby
> > LDAB $00,y
> > BSR WRITE_TERM
> > TAB
> > andb #$0F
> > LDY #WA2D_TABle
> > aby
> > LDAB $00,y
> > JSR WRITE_TERM
> > LDAB #$20 ; Space
> > JSR WRITE_TERM
> > pulb
> > pula
> > RTS
> > WA2D_TABle:
> > fcc "0123456789ABCDEF"
> >
> >
> >
> > *=====================================================================
> > * WRITE 2 TERMinal:
> > * Input: ASCII data in the B register.
> > * Action: Wait until transmit buffer is empty, then
> > * transmit the data in the B register.
> > *=====================================================================
> > WRITE_TERM:
> > BRCLR $2e,x %10000000 WRITE_TERM ; check Transmit-empty
> > STAB $2f,x
> > RTS
> >
> >
> >
> >
> >
> >
> >
> > ==============================================
> > What i have done is convert the analog measurement data and sent to
> > Port PE0 for conversion. The Voltage reference is 5 V for high and 0
> > v for low.So, how to take the converted data from A2D result and
> > shift into a 8 bit binary data and then convert to ascii code . The
> > ascii code will transmit to SCI port.Thank you
> >
> >
> >
> >
> >
> >
> >
> >
> > To unsubscribe from this group, send an email to:
> >
> >
> >
> >
> >
> > To unsubscribe from this group, send an email to:




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