|
|
| Author |
Message |
stevech
Joined: 23 Feb 2006
Posts: 688
|
|
Posted: 16 October 2006, 6:27 AM Post subject: |
|
|
Don - yeah, I know- a chip would be better. But (a) I'm lazy and (b) there's no more room on the board.
I don't need to sample both signals simultaneously.
I tried out CountTransitions() for a 6 mSec inteval (instead of WaitForInterrupt). Worked fine. But it doesn't do the longer averaging. I hate to sample much longer - as it impacts interrupt latency in the VM as I understand. The signals I'm sampling are low duty cycle - pulse low for like 5%. |
|
| Back to top |
|
 |
spamiam
Joined: 13 Nov 2005
Posts: 689
|
|
Posted: 16 October 2006, 13:16 PM Post subject: |
|
|
I was going to suggest considering some extra logic, but I then figured he wanted to minimize the extra hardware. Personally, I would have used extra stuff because it seems "better". But "best" is what works and does it in the simplest way....
Of course I am one for added complexity, just for the fun of it.
-Tony |
|
| Back to top |
|
 |
spamiam
Joined: 13 Nov 2005
Posts: 689
|
|
Posted: 16 October 2006, 15:31 PM Post subject: |
|
|
| stevech wrote: | and (b) there's no more room on the board.
|
Hmmm, time for a bigger board? Mike P is a big fan of "strip board" types. They do seem to be really nice for something 1 step up from a breadboard, and it makes for a compact layout when planned properly.
-Tony |
|
| Back to top |
|
 |
stevech
Joined: 23 Feb 2006
Posts: 688
|
|
Posted: 16 October 2006, 15:48 PM Post subject: |
|
|
regarding use of CountTransitions() for a 6 mSec inteval (instead of WaitForInterrupt)...
The ZBasic documentation says that during the CountTransitions() measurement interval, interrupts are disabled and task switching is blocked, but the RTC ticks accumulate none the less. I wonder if this means that all interrupts except timer ticks are blocked? Or some scheme is used to keep counting in a timer chip on the AVR, then after the measurement interval, read the tallied count and update the time of day. I suppose that ALL interrupts have to be disabled for the sake of measurement accuracy.
Using things that disrupt interrupts is something I tend to avoid - as in the future, some new feature might be infeasbile - such as use of a software UART. These are tradeoffs.
re using timer 2 as a count accumulator: I noted that TOSC on the ZX24 is connected to a port bit by the module's wiriing. |
|
| Back to top |
|
 |
dkinzer Site Admin
Joined: 03 Sep 2005
Posts: 2593
Location: Portland, OR
|
|
Posted: 16 October 2006, 15:57 PM Post subject: |
|
|
| stevech wrote: | | I tried out CountTransitions() for a 6 mSec inteval (instead of WaitForInterrupt). Worked fine. But it doesn't do the longer averaging. |
There are alternatives to using CountTransitions(). If you aren't using Com3-Com6 you could use Timer2 to count cycles on C.6. The width of Timer2 will limit the period over which you can count. You could do the same with Timer1, counting cycles on C.7 (connected to B.1) but this would preclude the use of a wider array of functions.
Along the same lines, if you had board space you could use an external counter to accumulate cycles over a given period. |
|
| Back to top |
|
 |
spamiam
Joined: 13 Nov 2005
Posts: 689
|
|
Posted: 16 October 2006, 16:19 PM Post subject: |
|
|
| dkinzer wrote: | | ...you could use Timer2 to count cycles on C.6. The width of Timer2 will limit the period over which you can count. You could do the same with Timer1, counting cycles on C.7 (connected to B.1) but this would preclude the use of a wider array of functions. |
I am not sure how to properly clock T/C2. Does TOSC1 get clocked while TOSC2 is held low? ViceVersa? Something else?
The reason I am concerned is that TOSC2 (pin C7 on the M32), is also connected to T1 (pin B1). Therefore if you need to clock TOSC1 (pin B5 on the M32), TOSC2 probably needs to be held low. But TOSC2 might be getting clocked for the T1 pin. So it is conceivable that both are getting clocked at the same time and there would be no differential across TOSC1 and TOSC2, therefore T/C2 might not get incremented.
An external counter sounds better and better, but then you have to deal with THAT chip's interface. SPI? I2C? Parallel? I2C sounds good to me.
These are real issues when you are pushing the limits of a certain platform.
The ZX-40 might provide better access to the individual M32's pins.
-Tony |
|
| Back to top |
|
 |
dkinzer Site Admin
Joined: 03 Sep 2005
Posts: 2593
Location: Portland, OR
|
|
Posted: 16 October 2006, 17:30 PM Post subject: |
|
|
| spamiam wrote: | | I am not sure how to properly clock T/C2. Does TOSC1 get clocked while TOSC2 is held low? |
TOSC1 and TOSC1 are intended for a 32.768KHz crystal. TOSC1 is the input the the internal crystal oscillator amplifier and TOSC2 is the output from that amplifier. However, you can input a clock signal directly into TOSC1 and ignore the TOSC2 output. Here is some simple test code to demonstrate the setup:
| Code: | Sub Main()
Register.ASSR = &H08 ' enable the async osc.
Register.TCCR2 = 1 ' divide by 1
Do
Debug.Print CStrHex(Register.TCNT2)
Call Delay(0.5)
Loop
End Sub |
In my test setup, I connected the output of a 555 timer running at about 250Hz to the TOSC1 input.
Note that if you enable the asynchronous oscillator you lose the use of both C.6 and C.7. Because of the onboard connections on the ZX-24/a, you also lose the use of INT0 (D.2) and T1 (B.1) as well. |
|
| Back to top |
|
 |
|