Author Topic: 9S08 assembly code  (Read 2429 times)

0 Members and 1 Guest are viewing this topic.

Offline JohnnyPTopic starter

  • Regular Contributor
  • *
  • Posts: 66
  • Country: us
    • J&S Electronics
9S08 assembly code
« on: April 26, 2015, 12:40:50 pm »
Something weird is happening.

I'm trying to update a memory location but it doesn't change.

To verify, I tried writing to that location immediately following something I know works.

In my project, I increment and decrement a digital pot and save the wiper voltage.

      bclr 3,    PTBD     ; Controls INC* to move the wiper
      lda      #$02
                sta      ADSC1   ; Set up to read wiper voltage
wait      brclr 7,   ADSC1, wait   ; wait for conversion complete
      sta      Wiper
      sta      test

"Wiper" is updated as expected but "test" never changes.

"test" is not used anywhere else.

I moved "test" to a different memory location and it still doesn't change.
Thinking is hard work
 

Offline Bruce Abbott

  • Frequent Contributor
  • **
  • Posts: 627
  • Country: nz
    • Bruce Abbott's R/C Models and Electronics
Re: 9S08 assembly code
« Reply #1 on: April 26, 2015, 09:07:14 pm »
"Wiper" is updated as expected but "test" never changes.
You are not reading the ADC result register, so both "Wiper" and "test" should become $02 (previous contents of accumulator). Is that what you expected, or is some code missing?

It might be easier to help if you show us all the relevant code (including code and data memory locations, interrupt routines etc.). You can make the listing easier to read by surrounding it with 'Insert Code' tags ('#' button), like this:-

Code: [Select]
bclr 3, PTBD  ; Controls INC* to move the wiper
lda #$02
                sta ADSC1 ; Set up to read wiper voltage
wait brclr 7, ADSC1, wait ; wait for conversion complete
sta Wiper
sta test

 

Offline JohnnyPTopic starter

  • Regular Contributor
  • *
  • Posts: 66
  • Country: us
    • J&S Electronics
Re: 9S08 assembly code
« Reply #2 on: April 27, 2015, 09:16:53 am »
Bruce:

Actually I am loading the result, I just forgot to type it here.

This is part of an interrupt routine.  I was trying to change the upper and lower limits on something but they aren't changing.

 I bypassed most of the routine and it's still running.

It acts like there is another routine that is actually running.

As far as I can tell there is only one "main" and one MCUinit file.
Thinking is hard work
 

Offline Bruce Abbott

  • Frequent Contributor
  • **
  • Posts: 627
  • Country: nz
    • Bruce Abbott's R/C Models and Electronics
Re: 9S08 assembly code
« Reply #3 on: April 27, 2015, 07:49:05 pm »
Quote
Actually I am loading the result, I just forgot to type it here.
I want to help, but it's very difficult without knowing what's actually in your code.

If 'sta wiper' is immediately followed by 'sta test' in the interrupt routine then both variables must be updating to the same number. You say that "test" is not used anywhere else, but if it is reverting back to its original value then some other part of your code must be affecting it. Without seeing that code I can only guess what might be causing the problem. 

Quote
As far as I can tell there is only one "main" and one MCUinit file.
The compiler or assembler should ensure that this code is only included once, but a bug could cause some of it to be executed more than once. Is your main code written in C, or assembler? If it's C then most obvious errors should be flagged by the compiler, but you must be careful when interfacing to assembler code. If it is all assembly code then any little mistake could be fatal. In either case it may help to have another pair of eyes look over your code.
 
Quote
It acts like there is another routine that is actually running.
Interrupts occur asynchronously relative to your main code, which can cause problems with shared variables because they can change at any time.  Disable all code (including interrupts) except the minimum required to update "test". If that works then re-enable the other code bit by bit, until it fails. Then examine that last bit to see what it is doing wrong. If you can't get it to work at all then you have a more fundamental error.     
 

Offline JohnnyPTopic starter

  • Regular Contributor
  • *
  • Posts: 66
  • Country: us
    • J&S Electronics
Re: 9S08 assembly code
« Reply #4 on: May 03, 2015, 06:57:18 am »
Bruce:

I got it working last week; been sick in bed with a sore throat so I haven't been around.

As I had suspected, I was working with the wrong file.

I must have done a "save as", re-named it, and saved it to an archive folder.  The original version was the actual code being run.
Thinking is hard work
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf