Code: Select all
Register.TCF1_CCA = 100 ' set the initial compare match value (large enough to handle initialization)
Code: Select all
Register.TCF1_CCA = 100 ' set the initial compare match value (large enough to handle initialization)
Code: Select all
ElseIf ((state And 1) = 0) Then ' data bit, low segment
' wait for the marker
Do While ((Register.TCF1_INTFLAGS And CCAF) = 0)
Loop
' set the bit low
port.OutClr = pinMask
' compute the duration of this segment
If ((data And dataMask) = 0) Then
delta = Delta_20uS
Else
delta = Delta_10uS
End If
Else ' data bit, high segment
' wait for the marker
Do While ((Register.TCF1_INTFLAGS And CCAF) = 0)
Loop
' set the bit high
port.OutSet = pinMask
' compute the duration of this segment
If ((data And dataMask) = 0) Then
delta = Delta_10uS
Else
delta = Delta_20uS
End If
' shift the mask for the next data bit
dataMask = Shr(dataMask, 1)
That is one of the pre-defined structures available in ZBasic. The Port_t structure represents the collection of registers comprising an I/O port of an AVR device, containing the data direction register, the input register, the output register and (for xmega devices) several other registers. Atmel's application note AVR1313 - Using the XMEGA IO Pins may be useful to get a better understanding of the various registers (e.g. OUTCLR) used.twesthoff wrote:What is "port_t"?
Yes.twesthoff wrote:Near the bottom of page 153 there is the title: ATmega-based ZX Devices for the second set of structures. Is this supposed to be ATXmega?
Notice, however, the similarity. Each of the timers has an INTCTRLA register. If you refer to them via the Register.<reg-name> construct, the various INTCTRLA registers must somehow be distinguished - that is the purpose of the prefix like TCF1_. The prefix has the form TC<letter><number>_ where <letter> ranges from A to F (depending on the particular xmega device) and <number> ranges from 0 to 1. The xmega32A4 has timers named TCC0, TCC1, TCD0, TCD1 and TCE0 while the xmega128A1 has all of those plus TCE1, TCF0 and TCF1. The "type 0" timers have four compare registers while the "type 1" timers have only two compare registers. Beyond that difference, the two timer types are virtually identical.twesthoff wrote:[T]he individual elements do not have names like in your code is TCF1_INTCTRLA = 0, and on p.154 it is INTCTRLA = 0
Yes, but note that TCD1 is the only timer that can be used for the software UART channels. If you know that you won't be using any software UART channels it is acceptable to use TCD1. See the Timers section of the ZBasic System Library Manual for more information on timer usage.twesthoff wrote:Your program has Register.TCF1_INTCTRLA = 0 if I change all of the TCF1 to TCD1 will it work for Timer D1 on the ZX-24x.
So I took that to mean that the exact structure would be included in the program just as if I had typed it in. I would have expected an error because the element names in the structure would not be the same as those used in the program.One or more of the pre-defined structures may be added to your application with the Option Include directive using the structure names below.
I think that some confusion remains. In the code that I originally posted, the timer registers are accessed directly using the Register.<reg-name> construct. In contrast, the port registers are accessed indirectly with the via a pre-defined Port_t structure based at an address determined at run-time.twesthoff wrote:I understood what the prefix was doing, but I was confused that the element names were not the same.
Yes, because it provides a uniform starting point upon which all subsequent time marks are based. The "start bit" is output from immediately after that loop until the first even-numbered state, a duration of approximately 10uS as you had specified. In summary, then, the output due to a particular state begins when the output is set in that state (right after the compare match is detected) and lasts until the compare match detection in the subsequent state.twesthoff wrote:Is the first Do-While-Loop necessary in (state = 1)?
By that time, the timer's CNT register will be at some non-zero value (the timer began running with the write to CTRLA). Consequently, setting CCA to zero would cause a very long wait at the wait loop in state 1 the first time, until the timer wraps around. Remember, a compare match flag is set when the timer's CNT register matches a compare register, e.g. CCA.twesthoff wrote:What would happen if that first Do-While loop was replaced with: Register.TCD1_CCA = 0
Code: Select all
If (state = 1) Then ' start bit
' set the threshold for the next state
Register.TCD1_CCA = Delta_10us
delta = 0
' set the bit high and start the timer
port.OutSet = pinMask
Register.TCD1_CTRLA = 1 ' use the 1X prescaler
That is what I was trying to do, but I had the wrong register.Another alternative would be to set the CNT register to zero in state=1.
Excellent.twesthoff wrote:I got it working successfully!
True enough. However, a 10uS bit time would be equivalent to 100K baud on the serial channel. That speed is too high to be supported in the way that the software UARTs are implemented (timer interrupt at 4X the maximum bit rate).twesthoff wrote:This code seems very similar as what would be done for the software UARTS if they were expanded to be 68bits at a speed of 10us per bit.