ooPIC Logo

ooPIC Programmer's Guide

 Chapter 7 - Your first Virtual Circuit 

Back to top of page What is a Virtual Circuit
 A Virtual Circuit is a background process that happens while your program is doing something else.

A Virtual Circuit is composed of a set of objects that interact with each other.  Some of the object in this set are used to move, modify or otherwise update values in the other object in the set.

Virtual Circuits are created by programmatically linking together a set of ooPIC Objects. Once created, each individual part of the virtual circuit can be manipulated or evaluated by the program.

Virtual Circuits are used to perform functions that provide continuous processes. A real-world example of a continuous process function would be the electrical circuit between a flashlight's switch and its light bulb. The function of the flashlight's switch is to provide continuous control over its light bulb. In an ooPIC application, things that need to be continuously updated or monitored, can be done by using a Virtual Circuit.

Back to top of page Steps to Creating Your First Virtual Circuit
 

There are 5 steps involved in creating an application for the ooPIC

  1. Create an ooPIC application framework, your workspace file in the IDE.
  2. Select hardware and functions applicable to Virtual Circuits like I/O lines, Analog to Digital conversion and math or compare functions.
  3. Work out the Virtual Circuits schematic by drawing with pencil and paper or your favorite graphical drawing package.
  4. Add and link the Virtual Circuits together in your application.
Back to top of page Creating an ooPIC Application
 In Chapter 2, an ooPIC application was created that blinks an LED.  A Do/Loop construct was created that constantly turned on then turned off the LED.  But what if we want the program to do something else and still have the LED turn of an on?  This can be done with a Virtual Circuit.

In this chapter, instructions are given on how to modify the application from Chapter 2 to use a Virtual Circuit to blink the LED.

Back to top of page Identify Functions Applicable to Virtual Circuits
 In the ooPIC application in Chapter 2, a process that continuously turns a LED on and then off takes up the program's time. The function of this process is similar to that of the electrical circuit between a light switch and a light.  The TurnOn method sets the LED object's Operate property to 1 and the TurnOff method sets it to 0.  The LED object cause an I/O Line to turn on or off depending on whether the Operate property is 1 or 0.

One of the ooPIC's Processing Objects, the oGate Object or oWire object, is capable of providing that same function that the ooPIC application is now doing with code, thus modifying the program to use a Virtual Circuit with this Object will allow the application's program to go do other things.

Back to top of page Work out the Virtual Circuit Schematic
 When creating a Virtual Circuit, a schematic is the best way to represent its functionality. Unlike a program, which uses a flowchart to represent the program's flow, a circuit Virtual Circuit uses a schematic to help clarify the function that the Virtual Circuit performs.

For our First Virtual Circuit, an oWire Object will be used to update an oDio1 Object's State property to the value of the ooPIC.Hz1 property.

Begin the schematic by drawing the Icon for the ooPIC, Next draw the icon for an oWire Object, and lastly, draw the Icon for the oDio1 Object.

Next, draw arrows between the Object's properties to represent the data flow between the Objects.

First draw an arrow from the ooPIC Object to the oWire Object. Label this arrow "Hz1" on the ooPIC Object and "Input" on the oWire Object. Next draw an arrow from the oWire Object to the oDio1 Object. Label this arrow "Output" on the oWire Object and "Value" on the oDio1 Object.

Back to top of page Add and Link the Virtual Circuit to the Application
 Adding the Virtual Circuit to the ooPIC application is done programmatically with lines of code.

Our wxample will start with a program that will turn an I/O line on and off with a do/loop construct.

Dim LED As New oDIO1

Sub Main()
  LED.IOLine = 7
  LED.Direction = cvOutput
  Do
    LED.State = ooPIC.Hz1
  Loop
End Sub

As previously detailed, the Virtual Circuit will use an oWire Object to provide the same function that the ooPIC application is now doing with code. Starting at the first line of code, insert a blank line and type the following statement:

Dim WIRE As New oWire

This instructs the ooPIC to create an instance of an oWire Object with the name "WIRE". The oWire Object is classified as a "Processing Object". This simply means that the Object will manipulate the values of other Objects in some predefined way. The function of an oWire  Object is to read a property from one or more Objects, perform a specified logic function, and store the resulting value of that function into yet another Object's property

Next, the application's Do…Loop structure needs to be removed because its function is going to be replaced by the Virtual Circuit. Beginning with the Do statement, remove the following 3 lines of code.

  Do
    LED.State = ooPIC.Hz1
  Loop

Replace them with the following 3 lines of code.

WIRE.Input.Link(ooPIC.Hz1)
WIRE.Output.Link(LED.State)
WIRE.Operate = cvTrue

The first line, "WIRE.Input.Link(ooPIC.Hz1)", instructs the "WIRE" Object to link its Input property to the ooPIC.Hz1 property. The second line, "WIRE.Output.Link(LED.Value)", instructs the "WIRE" Object to link its Output property to the State property of the "LED" Object. And the third line, "WIRE.Operate = cvTrue", sets the "WIRE" Object's Operate property to 1 (the value of cvTrue) which instructs it to start operating.

After the program executes these 3 lines of code, the Virtual Circuit begins to operate in the following manner;

  1. The value of the ooPIC.Hz1 property will be loaded by the oWire Object.
  2. The oWire will then use that value in a logical OR operation with its other inputs. In this application, only one input was used, so the result of the logical OR function will always equal the input.
  3. The LED.Value is set to the result of the logical OR function.

This procedure operates in the background and will continue to operate until the WIRE.Operate property is set back to a value of 0 (cvOff).

The following code shows the complete code listing written as instructed in the previous paragraphs.

Dim WIRE As New oWire
Dim LED As New oDIO1

Sub Main()
  LED.IOLine = 7
  LED.Direction = cvOutput
  WIRE.Input.Link(ooPIC.Hz1)
  WIRE.Output.Link(LED.State)
  WIRE.Operate = cvTrue
End Sub
Back to top of page Downloading and Running the Virtual Circuit Application
 Downloading and running the Virtual Circuit Application is no different than download and running any other ooPIC application.

Pressing the F5 key will compile the program and then download the "oex" file to the ooPIC. If any errors are encountered, they will be reported and the compilation will stop. If no errors were encountered, an "oex" (ooPIC Executable) file is generated. If you have not saved the program or you have changed it since the last time you have saved it, the compiler will ask you to save it. If this is the first time the program is going to be saved, the compiler will ask you for a program name. In this case, let's call the program "FirstVC". Type "FirstVC" in the "File name" area of the "Save As" dialog box and hit Enter.

In order for the executable to be downloaded to the ooPIC, the programming cable must be connected to the PC and properly configured. It also needs to be connected to the ooPIC's programming connector and an adequate power supply must be attached to the ooPIC. See the "Programming Cable" section for more information.


ooPIC Compiler Ver 6.0 (c) Copyright 1997 - 2007 Savage Innovations, LLC.