Forum Index
HomeZBasic Home   Forum RulesForum Rules   Forum FAQForum FAQ   MemberlistMemberlist   UsergroupsUsergroups   RSS FeedRSS Feed
Site SearchSite Search   LinksLinks   DownloadDownload   Digests and SubscriptionsDigests and Subscriptions
ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in   RegisterRegister
WaitForInterrupt in a Task
Goto page Previous  1, 2
 
Post new topic   Reply to topic    Forum Index -> ZBasic Language
Author Message
dkinzer
Site Admin


Joined: 03 Sep 2005
Posts: 2593
Location: Portland, OR

Posted: 24 July 2006, 17:31 PM    Post subject: Reply with quote

One solution to a time-critical problem like this is to add some external hardware that can capture data from or otherwise respond to the event. In this particular case, data needs to be read from the TW-523 in a window from 100uS to 900uS following the zero crossing signal edge and stored until the ZX can read it. In this case, the repetition rate is fairly low - the ZX would need to read the sampled data with in 8.3mS of its capture.

The sampling circuit can be relatively simple as illustrated in the attached schematic. Here, a '123 one-shot, U2, provides the timing from the zero-crossing edge to the sample point - about 550uS. It is triggered by the edge detector, U1. The output from the one-shot not only clocks the flip-flop, U3, to capture the data but it can also be used as an edge-sensitive input to WaitForInterrupt() to tell the ZX that it is time to read the sampled data from the flip-flop.



X10-sample.jpg
 Description:
 Filesize:  22.31 KB
 Viewed:  5103 Time(s)

X10-sample.jpg


Back to top
DH*
Guest





Posted: 24 July 2006, 17:58 PM    Post subject: Reply with quote

In my case, it makes more sense to offload this task to a PIC and then interface with the PIC via RS232. That's true multi-tasking. Very Happy

Also, while I did not get a screen capture, there were instances (probably when there was traffic on COM1) when 2-3 consecutive ZC periods were missed entirely.

However, it occurs to me that a simple 555 pulse stretcher circuit can accomplish the same thing as your circuit.
Back to top
dkinzer
Site Admin


Joined: 03 Sep 2005
Posts: 2593
Location: Portland, OR

Posted: 24 July 2006, 18:28 PM    Post subject: Reply with quote

dhouston wrote:
[...]it occurs to me that a simple 555 pulse stretcher circuit can accomplish the same thing as your circuit.

Indubitably. All you need is a circuit to provide the timing for the sample signal (the one-shot shown here or a 555) and something to hold the sampled data (the flip-flop). You also need a circuit to generate a trigger signal on both edges of the zero crossing signal (the R-C and XOR).
Back to top
DH*
Guest





Posted: 24 July 2006, 18:47 PM    Post subject: Reply with quote

I think just the 555 is sufficient. Normally, if there's a data pulse from the TW523, it's a 1mS pulse that immediately follows the ZC transition. The problem is that WaitForInterrupt sometimes lags the ZC transition by more than 1mS, missing the pulse. Stretching the data pulse to ~3mS will allow the lagging interrupt to catch it.

Don't be misled by the 1mS pulses in my screen capture as those are just marker pulses I generate to indicate when WaitForInterrupt gets triggered.
Back to top
stevech



Joined: 23 Feb 2006
Posts: 688

Posted: 24 July 2006, 19:36 PM    Post subject: Reply with quote

dhouston wrote:
In my case, it makes more sense to offload this task to a PIC and then interface with the PIC .

You meant a TinyAVR, rather than PIC, right?

Very Happy

you could also just use a CM11A for X10 send/receive and connect its RS232 port to the ZX24/40. The protocol is available as I recall.
Back to top
DH*
Guest





Posted: 24 July 2006, 20:07 PM    Post subject: Reply with quote

No, I mean a PIC.

A CM11A will not interface with the high-end Home Automation controllers like JDS Stargate, HomeVision, HAI, Leopard, etc. which expect to be talking to a TW523.

My device already interfaces with a CM11A, MR26A, MR26X (has a different PIC to handle security RF), internal RF receiver, internal wide-band IR receiver, CM15X (CM15A with a daughterboard I designed to extend its capability), 2414S (Insteon), UPB PIM, Ocelot, Leopard and several other devices. It's an update of the BX24-AHT that I designed a few years ago. The ZX-40 has the interrupt driven software UARTs which really extend my original design.
Back to top
DH*
Guest





Posted: 24 July 2006, 21:45 PM    Post subject: Reply with quote

stevech wrote:
May I respectfully suggest that if you need an assured task switch latency of 200uSec or less, then either (a) reconsider a hardware interface approach which is not so stringent or (b) perhaps a VM-based microprocessor isn't appropriate. Indeed, a non-VM based micro would assure 200uSec only if you are very careful about how long nested IRQs can execute and how long the application level might disable interrupts to manipulate linked lists, etc.
May I respectfully suggest that I understand what I'm doing and fully realize that this could better be done with other hardware. However, this is a DIY project and I try to design DIY projects to use readily available hardware that can be understood (and even programmed) by beginners. I will probably offload this task to a 4 MHz (internal oscillator) 8-pin PIC12F629 where I can handle the interrupts with about 75µS latency using compiled Basic.

Quote:
We can't expect miracles - super fast interrupts as well as the sophistication of the VM.
I haven't requested any miracles. I'm merely trying to find the limits of the ZX VM and having found them, communicate them to other users. I don't think you'll find any posts from me that are critical of the ZX products. I think Don has done a great job of squeezing performance out of the hardware. If you review my posts, you'll find I've made a dozen or so suggestions, most of which Don has implemented. I've pointed out a bug or two that he has then fixed.

Quote:
I might add that the timing diagram, above, is a bit of a worst-case, what with the several software UARTs running.
Gee, I've always thought that creating worst cases is how you find the limts. Don and I exchanged a few emails before I posted here today. In the first one, I told Don that I was trying to create a worst case and I think he fully understands what I'm trying to accomplish. Anyways, this really isn't worst case as my device will normally have something connected to each serial port (sometimes including an RS485 network of devices on one). I don't charge anything for the DIY projects I develop so I try to avoid designing for best cases only to find a few hundred users irate with me because it fails under the worst case. Mayhaps your design philosophy is different.

Quote:
I worked extensively in real time operating systems in the 80's on the then-state-of-the-art minicomputers - like Data General Novas - 16 bit, 32KB core memory. The performance and sophistication in that era with a computer that in today's dollars would have been about $100K, versus on these little $5 AVRs, is amazing.
I'm equally awed by what can be done with today's hardware. I can handle offloading this task with a $1 PIC.

Quote:
PS: As I recall, I did this work on Novas as an intern from pre-school. :wink:
You must be Andy's centenarian neighbor.

What I'm trying to do is extend the capability of the ZX and think I can actually accomplish X-10 input with a TW523 in a background task by adding a 555 pulse stretcher. As it is, the laggard interrupts occur irregularly. Sometimes I see two within a few mS and other times I only find one in 240 ZC transitions.

Now, if Don can find room to add extended dims to X10Cmd, it will be the best choice for DIY X-10.
Back to top
JC



Joined: 20 Feb 2006
Posts: 56
Location: Hudson,OH

Posted: 24 July 2006, 23:19 PM    Post subject: Reply with quote

Another possible approach.
I understand your desire to maximize the performance of the ZX and software, and minimize the addition of extra hardware, such as a pic, etc., which increases the complexity of the design, board, and intra-cpu communications, etc.
If the main processor, the ZX-xx, is not heavily burdened regarding its workload, and does not have other significantly time sensitive tasks to simultaneously perform, one could consider a Task which is tracking the zero-crossing occurrences, and when it runs in a time slice within N mSec of the Next anticipated ZC it locks its task, and awaits the ZC by polling the bit. This gives rapid identification of the ZC, whereupon you then execute your required processing, unlock the Task, and move on.
Down side is 120 times a sec your system has to tolerate this one task temporarily suspending multi-tasking, albeit briefly. Up-side is no additional hardware/pics.
The Task can re-synch its timer/counter/RTC with each ZC.
The Task can be very brief if it has no data to process.
How soon BEFORE the next ZC this task has to seize the system and begin watching for the ZC is dependent upon how many TASKs can possible be queued, etc., and if it is likely (guaranteed) to run again before the next ZC occurs.
This technique might be enhanced by shortening the duration of each time slice. This would provide more slices within each ZC, allowing one to potentially seize the system closer to the ZC. This could increase the percentage of time spent in multi-tasking mode, at the expense of more time spent in task switching overhead. How soon to seize the system and lock out task switching would best be empirically measured.
Just a thought.
JC
Back to top
DH*
Guest





Posted: 25 July 2006, 0:13 AM    Post subject: Reply with quote

JC wrote:
Down side is 120 times a sec your system has to tolerate this one task temporarily suspending multi-tasking, albeit briefly.
I think the downside is that I would have to dedicate 100% of the processor time to this. AFAIK there is no way to create a Timer interrupt other than with WaitForInterval which has resolution that is too crude for this task. OTOH I can do it with the PIC.

In this particular case my board is designed both for this application but also as a general purpose development board for the ZX-40. I do not want to add hardware that is specific to this task because it will limit the usefulness of the board for other purposes.

Now, because I do not want owners of $1000 JDS Stargate systems blaming my board should there be problems, I will design a small module with opto-isolators to go between the Stargate (and other, similar controllers) and my board. Adding a $1 PIC or a $0.50 timer chip to this module is no big deal. I will probably try the 555 first since it's simpler for DIYers. The PIC does have the advantage that it offloads all the processing.
Back to top
zbasicandy



Joined: 26 Jan 2006
Posts: 193

Posted: 25 July 2006, 0:51 AM    Post subject: Reply with quote

You must be Andy's centenarian neighbor
I resemble that remark.
There is no Stevech on my street!
Very Happy Very Happy Very Happy
Back to top
JC



Joined: 20 Feb 2006
Posts: 56
Location: Hudson,OH

Posted: 25 July 2006, 1:38 AM    Post subject: Reply with quote

I may not have stated the concept clearly. The Task is not interrupt driven. It does require a timer, / counter / RTC / Tic value to anticipate when the next ZC will occur. This task runs simultaneously, with all other tasks, during its allocated time slots. Then, as the time closely approaches a ZC it temporarily stops multi-tasking, hence maintaining control of the CPU. It then precisely detects the ZC, processes whatever, and then resumes multi-tasking until it is almost time for the next ZC. It is not interrupt driven / triggered / controlled.

That said, the hardware option may be easier, especially if the CPU has other time critical tasks to perform. It is, however, always nice to have several options to evaluate, before committing to a specific one.
JC
Back to top
DH*
Guest





Posted: 25 July 2006, 2:08 AM    Post subject: Reply with quote

JC wrote:
I may not have stated the concept clearly. The Task is not interrupt driven. It does require a timer, / counter / RTC / Tic value to anticipate when the next ZC will occur. This task runs simultaneously, with all other tasks, during its allocated time slots. Then, as the time closely approaches a ZC it temporarily stops multi-tasking, hence maintaining control of the CPU. It then precisely detects the ZC, processes whatever, and then resumes multi-tasking until it is almost time for the next ZC. It is not interrupt driven / triggered / controlled.
I don't think there's any way to accomplish that without monitoring the counter (or whatever) full time, taking up all of the processor time.
Back to top
Display posts from previous:   
Post new topic   Reply to topic    Forum Index -> ZBasic Language Time synchro. with the server - Timezone/DST with your computer
Goto page Previous  1, 2
Page 2 of 2

 


All content Copyright © 2005-2012 Elba Corp. All Rights Reserved.
Opinions expressed in posts are those of the author and not necessarily those of Elba Corp.
Powered by phpBB © 2001, 2005 phpBB Group