Found - RTCC undocumented behaviour!!!
We are launching a new product that uses SX28 micros and have encountered an undocumented feature of the SX that has been causing problems for the last week.
I am using the rtcc to count the number of instructions through pieces of code of different lengths so that it can be used to calculate how many more clocks are required to complete a set delay. The number of clocks to enter into the section of code is deterministic, so I set the rtcc to the value I want (mov rtcc,#7). I then let it run through the code before it comes to check the value of rtcc to see how much delay is left (mov w,rtcc). I have found that the rtcc stops counting after the "mov rtcc,#7" instruction. It will then recommence counting again after 4 instructions.
The code below shows where rtcc will read an incremented value. I just output the value to ra and rb to view the pins value.
Any help or information as to why this occurs would be greatly appreciated. We need to understand the functionality of the SX28 fully for our time critical application.
Cheers,
Andy
I am using the rtcc to count the number of instructions through pieces of code of different lengths so that it can be used to calculate how many more clocks are required to complete a set delay. The number of clocks to enter into the section of code is deterministic, so I set the rtcc to the value I want (mov rtcc,#7). I then let it run through the code before it comes to check the value of rtcc to see how much delay is left (mov w,rtcc). I have found that the rtcc stops counting after the "mov rtcc,#7" instruction. It will then recommence counting again after 4 instructions.
The code below shows where rtcc will read an incremented value. I just output the value to ra and rb to view the pins value.
mov w,#7 mov rtcc,w ;move rtcc with cycles since op0 was set (1) nop ;rtcc = 7 here nop ;rtcc = 7 here nop ;rtcc = 7 here nop ;rtcc = 7 here mov w,rtcc ;rtcc = 8 here (started counting again) mov isr_temp,w mov ra,isr_temp swap isr_temp mov m,#$0f mov !rb,#$f0 mov rb,isr_temp jmp $-1
Any help or information as to why this occurs would be greatly appreciated. We need to understand the functionality of the SX28 fully for our time critical application.
Cheers,
Andy
Comments
A couple of things...
Firstly I believe this is due to the pipeline architecture, but am not positive of that.
Secondly, I do believe there is a very brief reference to this in the device spec sheetes, although I can't recall offhand exactly where. Third, this loss of ticks will happen any time you access the RTCC with instructions that operate in a "read-modify-write" manner, but not with those that work in a true "read" manner.
Fourth, I thought that the number of lost counts was three, not four.
Fifth, the IDE in debug will not always indicate the correct count in the RTCC, so please be aware of that. The method you are using; employing the I/O pins to indicate the value is a proper approach.
Cheers,
Peter (pjv)
I had a thread about this RTCC behavour but I cannot find it now.
I think you lose 3 RTCC counts when you modify RTCC.
I would suggest you just offset the value you assign to RTCC to account for this.
Note that if the prescaler is used, the lost counts are different.
Bean.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
www.iElectronicDesigns.com
·
The thread was located here...
http://forums.parallax.com/showthread.php?p=708045
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
Yeah that was the thread I was looking for.
Bean.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
www.iElectronicDesigns.com
·
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
· As I point out in the original thread RTCC seems to act differently depending on the RTCC prescaler setting:
··· If the prescaler is 1:1 then 3 cycles are lost
··· If the prescaler is 1:2 or 1:4 then 5 cycles are lost
··· If the prescaler is 1:8 or higher then 1 cycle is lost (the cycle modifing RTCC doesn't get counted)
Bean
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
www.iElectronicDesigns.com
·
Cheers,
Andy
· I cannot explain exactly WHY this happens. I know it has to do with the 4 stage pipe-line of instructions.
· I think it is more important to know that it DOES happen and it IS predicable.
· As long as you are not changing the RTCC precaler at runtime, you should only need to offset the value you putting into RTCC to account for the lost counts.
Bean.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
www.iElectronicDesigns.com
·