9S08 assembly code - Page 1
Forum section: electronics / general

author: JohnnyP
author_rank: Regular Contributor
timestamp: April 26, 2015, 12:40:50 pm
content: 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 wiperlda #$02sta ADSC1 ; Set up to read wiper voltagewait brclr 7, ADSC1, wait ; wait for conversion completesta Wipersta 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.

author: Bruce Abbott
author_rank: Frequent Contributor
timestamp: April 26, 2015, 09:07:14 pm
content: Quote from: JohnnyP on April 26, 2015, 12:40:50 pmYou 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 usallthe 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:bclr 3,PTBD; Controls INC* to move the wiperlda#$02staADSC1; Set up to read wiper voltagewaitbrclr 7,ADSC1, wait; wait for conversion completestaWiperstatest

author: JohnnyP
author_rank: Regular Contributor
timestamp: April 27, 2015, 09:16:53 am
content: 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.

author: Bruce Abbott
author_rank: Frequent Contributor
timestamp: April 27, 2015, 07:49:05 pm
content: QuoteI 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 variablesmustbe 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.QuoteThe 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.QuoteInterrupts occur asynchronously relative to your main code, which can cause problems with shared variables because they can changeat 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 workat allthen you have a more fundamental error.

author: JohnnyP
author_rank: Regular Contributor
timestamp: May 03, 2015, 06:57:18 am
content: 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.