9S08QG8 TABS READ

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

9S08QG8 TABS READ

2,593 Views
fuma
Contributor I
Hello!
I'm new in the forum and I have a little problem with assembly code for a MC9S08QG8 microcontroller.
I cannot read a table with dates of a one byte with the LDX command, I wrong command or I to do use other instruction? I change from ST6 and 80198 to 9S08 family but in this micro I have a big problem.
I don't understand way it doesn't work, so if any body can help me I will appreciate it.

Thank you very much!
FABIO FUMAGALLI
Labels (1)
0 Kudos
5 Replies

410 Views
peg
Senior Contributor IV
Hi Fabio,
 
Welcome to the forums.
You seem to have posted the same question 3 times???
 
How about you give us a sample of the code you are trying and tell us how big the table is etc and we might be able to point you in the right direction.
 
0 Kudos

410 Views
bigmac
Specialist III
Welcome to the forum Fabio.
 
I think you should post a sample of your assembly code that is not working correctly.  Then we will be able to better diagnose your problem, without the need for a lot of guesswork.
 
Regards,
Mac
 
0 Kudos

410 Views
bigmac
Specialist III
Hello Fabio,
 
When I suggested you post your assembly code, I did not actually mean to send me the code via PM.  The purpose of the forum is to provide for open discussion of the topics raised, with the assumption that any answers given might possibly help others, as well as yourself.
 
With this in mind, the following is the contents of the PM -

Fabio wrote:
 
Hello!
hanks for the respost and excuse me for 3 times of the identical question.
I cannot read a table with dates of a one byte with the LDX command, I wrong command or I to do use other command/instruction.
The tabs in future is 256 byte for generate a PWM 8 bit sine, the tab in the attach is only for example of data read.
I don't understand way it dosen't work, so if any body can help me I will appreciate it.

Thank you very much!

Fabio

mainLoop:
; Insert your code here

   LDHX #$F4
   STHX TPMC1V
   MOV #$28,TPMSC

mainLoop1
   NOP

   ldX #TabSin-1
   aix #1
   pshh
   pshx
   lda x

   STHX TPMC1V
   MOV #$28,TPMSC

   pulx
   pulh

   feed_watchdog
      STA SRS ; feed the watchdog
   BRA mainLoop1

XDEF TabSin

; tabella generazione sinusoide
TabSin:
   ds.b 10
   dc.w 50
   dc.w 50
 

 

Firstly, your requirements for TPM use are totally unclear to me.  There seems to be some confusion about timer overflow operation, and timer channel operation.  Substantial revision of the code in this area is likely to be necessary.

 

But to address your actual query concerning reading byte values from a data table ...

  1. If the table is to consist of data bytes (not words), the directive dc.b must be used consistently, not ds.b or dc.w as you currently have.  Note that dc.b  10,50,50 is also permissible, to reduce the number of lines.  You will need to refer to the CW assembler manual for information about assembler directives.
  2. The most straighforward way to read a single byte value from the table (of size not exceeding 256 bytes) -
    Firstly set X-register to the table index value that you require (0-255), then use the following instructions to fetch the byte value in the accumulator.
      CLRH
      LDA   TabSin,X

After processing each byte, if you then need to increment the index value in order to read the next byte, either of the following instructions could be used, even though operation is a little different  in each case -
       INCX
or
       AIX   #1

Regards,
Mac

 



Message Edited by bigmac on 2007-06-02 03:10 AM
0 Kudos

410 Views
peg
Senior Contributor IV
Hi Fabio,
 
Further to what Mac has said...
 
Reasons why your code won't work:
 
1. Your initialising the index register inside the loop instead of before you go into it. Never will walk through the table but just always read the first entry.
 
2. lda x should be lda ,x. Does CW accept this?
 
3. You never use the value obtained from the table that is held in A.
 
4. If you want to automatically roll around in a 256 byte table you should use INCX rather than AIX
 
5. You have not initialised the H register. Works here as never touched but should be done.
 
6. You are pushing and pulling H for no apparent reason.
 
7. No offset indexing mode is no good to you for a 256 byte table as you do not have all of page zero available to you. The low end of page zero is occupied by the registers. You need to follow Mac's
suggestion here and use INCX.
 
8. You most likely need something to 'pace' the loop otherwise it is going to spin around very fast.
 
I am not going to try to figure out what you are trying to do with the timers.
 
0 Kudos

410 Views
fuma
Contributor I
Ok, thanks to all for the help,
today I check it.
 
Regards
Fabio
0 Kudos