Solved

Precise timing in Visual Basic 6 program - Interrupts??? (for the experts)

Posted on 2007-11-22
1
1,325 Views
Last Modified: 2012-08-14
Here is one for the real experts...

I have a gadget that measures a value which must be continuously updated in a very smooth scrolling graph.
----------------------------------------------

I have to scroll a graph across a screen (pixel by pixel) displaying a graphical representation of real-time data I am measuring.  
I have been able to accomplish it... kind of.

The original programming is in VisualBasic6

The program monitors real-Time data (data input to PC is smooth)
The problem I am faced with is displaying the data without 'hick-ups' in the smooth scrolling graphs I create.

Problem:
I have to display a scrolling (constantly Updated) picture  at a pre-selected Update Rate without allowing the screen to pause or jump.
AND The updates must be at displayed at precise (selectable) times.  
Current solution:
In order to make the Scrolling smooth I have chosen to Scroll all the pixels across the screen at every 'update' using BitBlt function.  
I simply add a new pixel Line at the beginning and Remove the last pixel Line from the display. (i.e. I am adding one pixel line and moving the existing graph (picture) up by one pixel line) This gives the appearancee of a nice, smooth scrolling graph.

I am willing to work with timer interrupts or anything else that would fix the problem.

I now have to add a print function so I don't like two thing in my current solution.  

Here is the Pseudo-code for my current solution.
-------------------------------------

'All setup stuff done....

DelayTime = ...(read DelayTime setting)
Do
   'the value 'DelayTime' is what determines the Scrolling Speed  
   ' (each graph line update is simply timed by waiting until the for - next loop counts down)
   For delayCount = 1 to DelayTime
        DoEvents
   Next
   
   'the Scroll Speed may have been changed at any time so i read the value every loop.
   DelayTime = ...(check to see if DelayTime was updated since last loop)
   
   'Then I Read a new value from my gadget so I can add to the next reading to the scrolling graph display.
   NewReading = input value
   
   'I then call a function to change the value into a representative pixel line for the next graph update
   Call makeGraph(NewReading)
   
   'Now I BitBlt the entire existing graph (picture box) over by one pixel and add the new pixel line to the beginning of the graph
   Call BitBlt routines to update graph...
   
   --------
   I need to add a 'Print Graph' function here...
   --------
   
   'Check for EscKey which indicated someone wants to end scrolling graph.
   ' (the program will continue scrolling data until this happens)
   read Esc - If Pressed then jump to Getout:
Loop
 Getout:
    Out of scroll display loop now....
------------------------------------

This works great without the new 'Print Function' - When I add the print function I now have a hick-up during scrolling while the 'print function makes a copy of the current Picture box (I am actually printing to a file, not a printer).  I may need to fix this with an interrupt.  This ISR would have to have a higher priority then the Print function to smoothly to update the graph.

I know I said the current solution works great and it does 'functionally'.  The problem is that the CPU runs at 100% usage because of the For Next loop.  The Interrupt solution would fix that too (I think)  I would really like to find a way to time this loop w/o burning up the processor.

Unfortunately, I can't use the built-in Timer function because I need to be able to adjust the scroll speed of about 3 millisecond increments. (Timer function has approx 17ms increments).. Too slow dag nabit!

Anybody have an interrupt solution that would preempt the Print function? (maybe based on the 8251 hardware timer chips)

Thank You for your help!
DannyHop
0
Comment
Question by:dannyhop
1 Comment
 
LVL 6

Accepted Solution

by:
Taconvino earned 500 total points
Comment Utility
Hi!

http://www.compuphase.com/vbtiming.htm

That should have a resolution of 1ms, but the Sleep() function may add a 5ms error to that.  Still, very close.  I'm not sure how this could prevent your "hick-up" problem, as it is probably caused by the IO process.  Maybe I didn't understood your question completely... you need to lower the IO (print) process priority?

TCV
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now