View previous topic :: View next topic |
Author |
Message |
Triplett
Joined: 28 Feb 2010 Posts: 52 Location: Maryland
|
Posted: Fri Mar 17, 2017 2:45 am Post subject: |
|
|
OK. Here is evidence that the routine that decides when to jump into Sectic is doing nothing wrong.
Comments are below the code.
Code: | $regfile = "xm32A4Udef.dat"
$crystal = 2000000
$hwstack = 64
$swstack = 40
$framesize = 40
Config Clock = Soft , Rtc = 1khz_32khz_crystosc , Gosub = Sectic ' Use 32 KHz crystal oscillator for RTC.
Config Sysclock = 2MHz
Config Com1 = 115200 , Mode = Asynchroneous , Parity = None , Stopbits = 1 , Databits = 8
Config PortE.1 = Output ' LED
Config Priority = Static , Vector = Application , Lo = Enabled
Enable Interrupts
Print "OSC_CTRL = "; BIN(OSC_CTRL)
Print "OSC_STATUS = "; BIN(OSC_XOSCCTRL)
Print "OSC_XOSCCTRL = "; BIN(OSC_XOSCCTRL)
Do
Wait 1
Toggle PortE.1 ' Toggle LED.
Print Time$
Loop
Sectic:
' Nop
Return
|
This code shows that Time$ is not being changed each second.
The Do Loop prints it each second, but it only changes every two minutes.
We can deduce that the RTC config needs attention.
Something is giving the RTC a large value to count before rolling over.
This causes Time$ to update slowly, and Sectic to be called slowly. |
|
Back to top |
|
|
Triplett
Joined: 28 Feb 2010 Posts: 52 Location: Maryland
|
Posted: Fri Mar 17, 2017 3:55 am Post subject: |
|
|
Here is a window into the contents of the RTC registers:
Code: | $regfile = "xm32A4Udef.dat"
$crystal = 2000000
$hwstack = 64
$swstack = 40
$framesize = 40
Config Osc = Enabled, 32KHzosc = Disabled
Config Clock = Soft , Rtc = 1khz_32khz_crystosc , Gosub = Sectic
Config Sysclock = 2MHz
Config Com1 = 115200 , Mode = Asynchroneous , Parity = None , Stopbits = 1 , Databits = 8
Config PortE.1 = Output ' LED
Config Priority = Static , Vector = Application , Lo = Enabled
Enable Interrupts
Dim I as Byte
Wait 3
For I = 1 to 3
Wait 1
Toggle PortE.1 ' Toggle LED.
Print "CLK_RTCCTRL = "; BIN(CLK_RTCCTRL)
Print "RTC_CTRL = "; BIN(RTC_CTRL)
Print "RTC_STATUS = "; BIN(RTC_STATUS)
Print "RTC_INTCTRL = "; BIN(RTC_INTCTRL)
Print "RTC_INTFLAGS = "; BIN(RTC_INTFLAGS)
Print "RTC_TEMP = "; BIN(RTC_TEMP)
Print "RTC_CNT = "; BIN(RTC_CNT)
Print "RTC_PER = "; BIN(RTC_PER)
Print "RTC_COMP = "; BIN(RTC_COMP)
Print
Next I
End
Sectic:
' Nop
Return
' Output is as follows:
'(
CLK_RTCCTRL = 00000011
RTC_CTRL = 00000001
RTC_STATUS = 00000000
RTC_INTCTRL = 00000001
RTC_INTFLAGS = 00000010
RTC_TEMP = 00000000
RTC_CNT = 0000000000101110
RTC_PER = 0000000011111111
RTC_COMP = 0000001100000000
CLK_RTCCTRL = 00000011
RTC_CTRL = 00000001
RTC_STATUS = 00000000
RTC_INTCTRL = 00000001
RTC_INTFLAGS = 00000010
RTC_TEMP = 00000000
RTC_CNT = 0000000000111100
RTC_PER = 0000000011111111
RTC_COMP = 0000001100000000
CLK_RTCCTRL = 00000011
RTC_CTRL = 00000001
RTC_STATUS = 00000000
RTC_INTCTRL = 00000001
RTC_INTFLAGS = 00000010
RTC_TEMP = 00000000
RTC_CNT = 0000000001001101
RTC_PER = 0000000011111111
RTC_COMP = 0000001100000000
') |
I would love to see how any of these registers is behaving differently
on the A1U when running the same code. |
|
Back to top |
|
|
Meister
Joined: 27 May 2010 Posts: 319
|
Posted: Fri Mar 17, 2017 12:10 pm Post subject: |
|
|
This is the output on the Xplained board:
(Can't get rid easily of the controll characters).
CLK_RTCCTRL = 00000011<\r>
<\n>RTC_CTRL = 00000001<\r>
<\n>RTC_STATUS = 00000000<\r>
<\n>RTC_INTCTRL = 00000001<\r>
<\n>RTC_INTFLAGS = 00000010<\r>
<\n>RTC_TEMP = 00000000<\r>
<\n>RTC_CNT = 0000000011110111<\r>
<\n>RTC_PER = 0000001111111111<\r>
<\n>RTC_COMP = 0000001100000000<\r>
<\n><\r>
<\n>CLK_RTCCTRL = 00000011<\r>
<\n>RTC_CTRL = 00000001<\r>
<\n>RTC_STATUS = 00000000<\r>
<\n>RTC_INTCTRL = 00000001<\r>
<\n>RTC_INTFLAGS = 00000010<\r>
<\n>RTC_TEMP = 00000000<\r>
<\n>RTC_CNT = 0000000000000110<\r>
<\n>RTC_PER = 0000000011111111<\r>
<\n>RTC_COMP = 0000001100000000<\r>
<\n><\r>
<\n>CLK_RTCCTRL = 00000011<\r>
<\n>RTC_CTRL = 00000001<\r>
<\n>RTC_STATUS = 00000000<\r>
<\n>RTC_INTCTRL = 00000001<\r>
<\n>RTC_INTFLAGS = 00000010<\r>
<\n>RTC_TEMP = 00000000<\r>
<\n>RTC_CNT = 0000000000010101<\r>
<\n>RTC_PER = 0000000011111111<\r>
<\n>RTC_COMP = 0000001100000000<\r> |
|
Back to top |
|
|
Triplett
Joined: 28 Feb 2010 Posts: 52 Location: Maryland
|
Posted: Fri Mar 17, 2017 12:20 pm Post subject: |
|
|
I am not sure what to make of this.
We see that RTC_CNT seems to be incremented.
The number of ticks it is incremented seems to
vary greatly. In decimal equivalent values, the
increment is 14 ticks during the first printed
second, and 17 ticks during the next. |
|
Back to top |
|
|
Triplett
Joined: 28 Feb 2010 Posts: 52 Location: Maryland
|
Posted: Fri Mar 17, 2017 12:27 pm Post subject: |
|
|
That was for the A4U.
Based on Meister's result for the A1U, the RTC_CNT
is very different. In decimal it is first 247, then 6, then 21.
It doesn't seem to increment.
Thanks, Meister.
Happy St. Patrick's day. |
|
Back to top |
|
|
Triplett
Joined: 28 Feb 2010 Posts: 52 Location: Maryland
|
Posted: Fri Mar 17, 2017 12:37 pm Post subject: |
|
|
Update. Here is another possibility.
For the A1U it could be seen to increment the same as the A4U.
Meister just happened to catch it before and after it had rolled over.
The value became smaller, and then started growing again.
Increment value was 15 ticks for the A1U, and it rolled over at 256.
I will watch the A4U to see that it also rolls over at 256.
Thanks again, Meister. |
|
Back to top |
|
|
Triplett
Joined: 28 Feb 2010 Posts: 52 Location: Maryland
|
Posted: Fri Mar 17, 2017 12:45 pm Post subject: |
|
|
RTC_CNT could be rolling over many times during each one second interval.
That would explain what seems to be variation from 14 to 17 ticks per second
when values are sampled at a rate of once each second.
These results are encouraging. It looks as if I can already apply the A4U to a
design, and perhaps later it will be possible to make use of Time$ and Sectic
at warp speed instead of half impulse. |
|
Back to top |
|
|
Meister
Joined: 27 May 2010 Posts: 319
|
Posted: Fri Mar 17, 2017 12:52 pm Post subject: |
|
|
It would not be too difficult to tap wires haha from the xtal to the default Pins, since there are those Jumper, isn't it? |
|
Back to top |
|
|
Triplett
Joined: 28 Feb 2010 Posts: 52 Location: Maryland
|
Posted: Fri Mar 17, 2017 1:23 pm Post subject: |
|
|
For the A4U, the RTC_CNT rolls over at 1024, vice 256 for Meister's A1U.
At 115200 baud, the loop below is able to sample and print RTC_CNT very quickly.
It grabs and prints about 26 samples during each tick of RTC_CNT.
Code: | $regfile = "xm32A4Udef.dat"
$crystal = 2000000
$hwstack = 64
$swstack = 40
$framesize = 40
Config Osc = Enabled, 32KHzosc = Disabled
Config Clock = Soft , Rtc = 1khz_32khz_crystosc , Gosub = Sectic
Config Sysclock = 2MHz
Config Com1 = 115200 , Mode = Asynchroneous , Parity = None , Stopbits = 1 , Databits = 8
Config PortE.1 = Output ' LED
Config Priority = Static , Vector = Application , Lo = Enabled
Enable Interrupts
Dim I as Word
Wait 10
For I = 1 to 26000
Print "RTC_CNT = "; RTC_CNT
Next I
End
Sectic:
' Nop
Return
' With results in decimal, an extract from the output is as follows:
'(
RTC_CNT = 1023
RTC_CNT = 1023
RTC_CNT = 1023
RTC_CNT = 1023
RTC_CNT = 1023
RTC_CNT = 1023
RTC_CNT = 1023
RTC_CNT = 1023 [This happens at 73 seconds after RTC_CNT had been zero.]
RTC_CNT = 0
RTC_CNT = 0
RTC_CNT = 0
RTC_CNT = 0
RTC_CNT = 0
RTC_CNT = 0
RTC_CNT = 0
RTC_CNT = 0
RTC_CNT = 0
RTC_CNT = 0
RTC_CNT = 0
RTC_CNT = 0
RTC_CNT = 0
RTC_CNT = 0
RTC_CNT = 0
RTC_CNT = 0
RTC_CNT = 0
RTC_CNT = 0
RTC_CNT = 0
RTC_CNT = 0
RTC_CNT = 0
RTC_CNT = 0
RTC_CNT = 0
RTC_CNT = 0
RTC_CNT = 0
RTC_CNT = 0
RTC_CNT = 1
RTC_CNT = 1
RTC_CNT = 1
RTC_CNT = 1
RTC_CNT = 1
') |
|
|
Back to top |
|
|
Triplett
Joined: 28 Feb 2010 Posts: 52 Location: Maryland
|
Posted: Fri Mar 17, 2017 1:33 pm Post subject: |
|
|
Making the entire processor be hard-wired to run at 32.768 KHz would not be OK.
Goal is to run the micro at high speed during brief recurring moments, then have
the main processor go to sleep to save power while the 32.768 KHz crystal RTC
continues to run independently and awaken the processor each second for a brief
period of high-speed work, then have the micro go back to sleep.
RTC crystal clock consumes very little battery current, and keeps very accurate
record of elapsed time. System needs to know exactly how much time has passed
during sleep/suspend. Internal 32.768 KHz oscillator is nice, but not good enough
for the application. It's a timey wimey wibbly wobbly science thing.
This job can be done using the smaller A4U. Although with Time$ and Sectic not
working, I may be forced to put a much larger than necessary pin-count device
into the design as a way to get around the problem. |
|
Back to top |
|
|
Meister
Joined: 27 May 2010 Posts: 319
|
Posted: Fri Mar 17, 2017 6:05 pm Post subject: |
|
|
This comes out with the Xplained board ($regfile = "xm128a1Udef.dat"):
RTC_CNT = 968<\r>
<\n>RTC_CNT = 971<\r>
<\n>RTC_CNT = 975<\r>
<\n>RTC_CNT = 978<\r>
<\n>RTC_CNT = 982<\r>
<\n>RTC_CNT = 986<\r>
<\n>RTC_CNT = 989<\r>
<\n>RTC_CNT = 993<\r>
<\n>RTC_CNT = 996<\r>
<\n>RTC_CNT = 1000<\r>
<\n>RTC_CNT = 1003<\r>
<\n>RTC_CNT = 1007<\r>
<\n>RTC_CNT = 1011<\r>
<\n>RTC_CNT = 1014<\r>
<\n>RTC_CNT = 1018<\r>
<\n>RTC_CNT = 1022<\r>
<\n>RTC_CNT = 1<\r>
<\n>RTC_CNT = 5<\r>
<\n>RTC_CNT = 8<\r>
<\n>RTC_CNT = 12<\r>
<\n>RTC_CNT = 15<\r>
<\n>RTC_CNT = 18<\r> |
|
Back to top |
|
|
Triplett
Joined: 28 Feb 2010 Posts: 52 Location: Maryland
|
Posted: Fri Mar 17, 2017 9:04 pm Post subject: |
|
|
That is useful. It looks as if the A1U RTC counter is behaving exactly like the A4U. It was a little confusing at first, because the print to COM is not updated as frequently. The RTC registers seem to be the same, so this puts us back to square one without seeing why the Time$ and Septic are visited so much more slowly on the A4U. |
|
Back to top |
|
|
MWS
Joined: 22 Aug 2009 Posts: 2262
|
Posted: Fri Mar 17, 2017 10:51 pm Post subject: |
|
|
I would suggest to use a more coordinated approach and not the aimless and random botchery, which can be seen here.
Before suspecting the compiled assembly, it is rather easy to proceed from a known working basis.
Known working is the internal rc-oscillator, the only difference between rc- and external oscillator is to change two bits.
Using this approach one can make sure, that the assembled code for external crystal is working in its whole.
Code: | $regfile = "xm32A4Udef.dat"
$crystal = 2000000
$hwstack = 64
$swstack = 40
$framesize = 40
$noramclear
Config Sysclock = 2MHz
Config PortE.1 = Output
Config Priority = Static , Vector = Application , Lo = Enabled
Enable Interrupts
Config Clock = Soft , Rtc = 1khz_32khz_crystosc , Gosub = Sectic
' RTCSRC: 001 1024kHz from 32.768kHz crystal oscillator on TOSC
Dim rtcctrl_tmp As Byte
Const RTCSRC_0 = 1
Const RTCSRC_1 = 2
Const RTCSRC_2 = 3
rtcctrl_tmp = CLK_RTCCTRL
rtcctrl_tmp = rtcctrl_tmp And NBits(RTCSRC_2 , RTCSRC_1 , RTCSRC_0) ' clear RTCSRC[2..0]
rtcctrl_tmp = rtcctrl_tmp Or Bits(RTCSRC_1) ' set RTCSRC bit 1
CLK_RTCCTRL = rtcctrl_tmp
' RTCSRC: 010 1024kHz from 32.768kHz internal oscillator
Do
Loop
Sectic:
Toggle PortE.1
Return |
If that works ok, it would make sense to look up whether Atmel/Microchip provides some errata regarding this issue.
The ATXMega32A4U is on the market long enough, a quite serious issue of not working low frequency crystals and failing RTC would be known in the meantime.
However, no erratas concerning this issue can be found.
Next, respectively it should have been done at the very start, check oscillation on the amplifier output TOSC2 with an oscilloscope. If no oscilloscope is at hand, somebody else may provide this service.
It should be even possible to use the XMega's ADCs to build some code for sampling the waveform on the TOSCs into SRam, write it to file on PC then and run some software to display the waveform.
Finally, the result will show that either the controller of the MT-DB-X4 is partly dead, or more likely the 32768Hz crystal is, nothing uncommon.
The most simple thing to do would have been to connect a fresh clock crystal between J18.2 and J19.2 and check out what happens.
Instead it is riddled, assumed and read from tea leaves without any effect.
This reminds me of the joke, where a guy is asked why he looks in the bright spot for an item lost, instead of the dark corner, where he may have likely lost it.
The answer simply was: I can not see well, where it's dark. LOL
This thread looks exactly the same. |
|
Back to top |
|
|
Triplett
Joined: 28 Feb 2010 Posts: 52 Location: Maryland
|
Posted: Sat Mar 18, 2017 12:11 am Post subject: |
|
|
One of the scopes in my lab showed 32.768 KHz, of course. I am sure you will be able to solve the puzzle, eventually.
RTC is running exactly at 1/122 of expected speed, which is the same ratio as 32.768 KHz / 2 MHz. All registers seem to match between the two micros. When I can get back to this, I will be doing testing using Studio, which would be off topic here.
Remember to drink some green beer. |
|
Back to top |
|
|
MWS
Joined: 22 Aug 2009 Posts: 2262
|
Posted: Sat Mar 18, 2017 8:16 am Post subject: |
|
|
Triplett wrote: | One of the scopes in my lab showed 32.768 KHz, of course. |
Such information is important, and it's not an "of course", if not checked, it can be anything.
Quote: | I am sure you will be able to solve the puzzle, eventually. |
I'm not so sure, especially as I do not have this exact hardware here. While I found this discussion ineffective, I did some work, looked at the disassembly, checked status of the registers in AVR-Studio after configuration, everything looks ok.
Simulation lacks a bit, cycles between ISR-calls were a bit more than 2000000, afair ISR also was triggered if registers set to external crystal, AVR-Studio's simulation capabilities are limited.
Quote: | RTC is running exactly at 1/122 of expected speed, which is the same ratio as 32.768 KHz / 2 MHz. |
If I'd suspect a connection there, I'd shut off the 2MHz and switch to another clock source.
Quote: | I will be doing testing using Studio, which would be off topic here. |
Why this would be OT? I would even use disassemble a C-source, if that would help.
It may be - my suspicion - that it is a hardware issue, then it's not Bascom-code related and can be moved.
Till then, as in war and in love, all is fair.
To check about Bascom's code, you may try out my last posted one, you may even modify it to switch back to TOSC and see what happens then. |
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You cannot download files in this forum
|
|