<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Eugene Hutorny</title>
	<atom:link href="http://hutorny.in.ua/feed" rel="self" type="application/rss+xml" />
	<link>http://hutorny.in.ua</link>
	<description>Programming in a small</description>
	<lastBuildDate>Fri, 15 Jan 2010 19:52:10 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Exercise on implementing collaborations with ObjectTeams/Java</title>
		<link>http://hutorny.in.ua/java/exercise-on-implementing-collaborations-with-objectteams-java</link>
		<comments>http://hutorny.in.ua/java/exercise-on-implementing-collaborations-with-objectteams-java#comments</comments>
		<pubDate>Tue, 29 Dec 2009 15:41:10 +0000</pubDate>
		<dc:creator>Eugene</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[account]]></category>
		<category><![CDATA[cash]]></category>
		<category><![CDATA[collaboration]]></category>
		<category><![CDATA[objectteams]]></category>
		<category><![CDATA[role]]></category>
		<category><![CDATA[withdraw]]></category>

		<guid isPermaLink="false">http://hutorny.in.ua/?p=189</guid>
		<description><![CDATA[Introduction
ObjectTeams/Java (OT/J) is an extension to Java programming language that facilitates roles and collaborations as the first class language constructs. This article is an exercise on using (OT/J) for implementing collaborations.
Subject area
This exercise considers two bank operations – money transfer and fund cashing. The course of events for these two operations is very similar in [...]]]></description>
			<content:encoded><![CDATA[<h3>Introduction</h3>
<p><a href="http://www.objectteams.org/">ObjectTeams/Java</a> (OT/J) is an extension to Java programming language that facilitates roles and collaborations as the first class language constructs. This article is an exercise on using (OT/J) for implementing collaborations.</p>
<h3>Subject area</h3>
<p>This exercise considers two bank operations – money transfer and fund cashing. The course of events for these two operations is very similar in basic and differs in details. Considering this, it is implemented as an abstract withdraw routine leaving detail differences to concrete implementations.<br />
<span id="more-189"></span></p>
<h3>An abstract withdraw routine</h3>
<table border="0" cellspacing="0" cellpadding="0" width="160" align="right" style="padding-left:10px;">
<tbody>
<tr>
<td><a href="http://hutorny.in.ua/wp-content/uploads/2009/12/CollaborationDiagram.png" rel="thumbnail"><img src="http://hutorny.in.ua/wp-content/uploads/2009/12/CollaborationDiagram-150x150.png" alt="Figure 1" title="Figure 1" width="150" height="150" class="alignnone size-thumbnail wp-image-192" /></a></td>
</tr>
<tr>
<td align="center"><b>Figure 1</b></td>
</tr>
</tbody>
</table>
<p>A withdraw routine executed in a bank allows to move funds from one account to another. The bank, which executes this operation, charges some fee, applied to the credit account and debited onto the bank&#8217;s operational account. When the currency of the operation is not the same as the bank&#8217;s native currency, the bank converts the fee to the native currency.<br />
A collaboration diagram for this operation is given on <a href="http://hutorny.in.ua/wp-content/uploads/2009/12/CollaborationDiagram.png" rel="thumbnail">Figure 1</a>. The collaboration steps and reiterated below:</p>
<ol>
<li>Calculate a fee for this operation</li>
<li>Charge the amount+fee from the credit account</li>
<li>Put the money on the debit account, which is      expected to accept any currency</li>
<li>If the currency of the operation differs from      the currency of the banks&#8217; operational account conversion is applied to the fee</li>
<li>Put the fee is on the operational account</li>
</ol>
<p>A function that implements this code is given below (for a complete class please refer to the <a href="http://hutorny.in.ua/wp-content/uploads/2009/12/exer1/src/ua/in/hutorny/otj/exer1/accounting/WithdrawCollaboration.java">source</a>):</p>
<pre class="brush: java;">
	protected final void withdraw(BigDecimal amount, CreditAccount creditAccount, DebitAccount debitAccount,
			OperationalAccount operationalAccount, CurrencyConverter currencyConvertor) {
		BigDecimal fee =  calculateFee(amount);
		creditAccount.credit(amount.add(fee));
		debitAccount.debit(amount,creditAccount.currency());
		if( creditAccount.currency() != operationalAccount.currency())
			fee = currencyConvertor.convert(creditAccount.currency(), operationalAccount.currency(), fee);
		operationalAccount.debit(fee);
	}
</pre>
<p>In this exercise, this method is implemented in scope of a team class Withdraw Collaboration and the parameter types are defined as role classes in the team. This class is pretty isolated and depends only on Currency class, so it can be reused in other applications. Details of the account implementations are hidden behind the roles.</p>
<h3>Concrete withdrawal routines</h3>
<p>A bank that implements concrete withdrawal routines, gives its clients two interfaces &#8211; the Cashier interface that allows people to get some cash from they accounts, and the Wire Operator interface that allows them to transfer funds from the account they have in this bank to any other account. In scope of this exercise, these two interfaces are implemented by two collaboration, both extending the Withdraw Collaboration. Each collaboration is instantiated in the bank for a given account and then returned to the client. Once the interface is provided, the client may execute more than one operation with the current account.<br />
Since there could be a rather long thinking time, the bank can not provide an operational account at the time when the interface is acquired, but instead the operation account should be determined at the moment of transaction execution. To achieve this, these collaborations are extended with an additional role – Operator which provides access to the available operational account at the moment of transaction execution.<br />
Additional complications with implementing the Cashier that there is not debit account available, since the money are given to a person and the person cannot accept a decimal value, he/she can only take cash, so the digits should be converted to cash. Code snippet for this operation is given below (for a complete class please refer to the <a href="http://hutorny.in.ua/wp-content/uploads/2009/12/exer1/src/ua/in/hutorny/otj/exer1/bank/GetCashFromBankCollaboration.java">source</a>):</p>
<pre class="brush: java;">
	public void giveCashTo(Person person, double amount) {
		BigDecimal value = new BigDecimal(amount);
		reserved = bank.acquireCash(value, account.currency());
		try {
			cashOperation(new BigDecimal(amount), account, person, bank, bank);
		}
		finally {
			if( reserved.value().signum() != 0 ) {
			// Recipient did not take the money
				bank.returnCash(reserved);
			}
		}
	}
</pre>
<p>To match the Person entity with the DebitAccount interface, a new role is defined as below:</p>
<pre class="brush: java;">
	protected class CashRecipient extends DebitAccount playedBy Person {

		void takes(Cash cash) -&gt; void takes(Cash cash);

		protected void debit(BigDecimal amount, Currency currency) {
			assert reserved.value() == amount &amp;&amp; reserved.currency() == currency;
			takes(reserved);
		}
	}
</pre>
<h3>Bank</h3>
<p>In this exercise a bank has an internal operational account, and a safe, where all cash is kept. It provides methods for opening accounts (credit and current) and access to two already mentioned interfaces Cashier and Wire Operator. BankAccount is an protected inner class of the Bank to ensure that no one can create a bank account outside of a bank (for a complete class please refer to the <a href="http://www.hutorny.in.ua/wp-content/uploads/2009/12/exer1/src/ua/in/hutorny/otj/exer1/bank/Bank.java">source</a>).</p>
<h3>Cash</h3>
<p>If everyone would be able to create cash in their own, there would be no need for banks and accounts <img src='http://hutorny.in.ua/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> . Also, when cash is being added or subtracted, its behavior differs very much from adding two numbers. To model these features of the cash, a dedicated class is provided. The only public constructor it provides creates zero cash. The add operation accepts Cash as the addendum and clears it after adding. The subtract operation accepts a number and creates a new cash for the amount of subtrahend. Also it provides an instruction to the garbage collector to report any occurrence of valuable cash in the garbage (for a complete class please refer to the <a href="http://hutorny.in.ua/wp-content/uploads/2009/12/exer1/src/ua/in/hutorny/otj/exer1/money/Cash.java">source</a>).</p>
<h3>Modeling the plan</h3>
<p>With the mentioned above classes (and some additional) we can now model Tom and Mary’s plan:<br />
Entities that are assumed to exist:</p>
<pre class="brush: java;">
	Bank spicer  = new Bank(&quot;JVM-Spicer,MN &quot;, Currency.USD);
	Bank willmar = new Bank(&quot;OTJ-Willmar,MN&quot;, Currency.EUR);
	Bank bahama  = new Bank(&quot;Java-Bahamas  &quot;, Currency.BSD);

	Person tom  = new Person(&quot;Tom &quot;);
	Person mary = new Person(&quot;Mary&quot;);
</pre>
<p>The plan:</p>
<pre class="brush: java;">
		Account credit = spicer.openCreditAccount(1000000, Currency.USD);
		Cashier cashier = spicer.cashier(credit);
		cashier.giveCashTo(tom, 970000);

		mary.takes(	tom.gives(965000, Currency.USD) );

		Account deposit = willmar.openAccount(mary.gives(960000,Currency.USD));

		Account bahamamama = bahama.openAccount(mary.gives(1000,Currency.USD));

		WireTransfer wire = willmar.wireOperator(deposit);
		wire.wireTo(bahamamama, 950000);

		cashier = bahama.cashier(bahamamama);
		cashier.giveCashTo(mary, 923000);

		tom.takes( mary.gives(461000, Currency.USD) );
</pre>
<p>All sources are available for downloading as a single <a href='http://hutorny.in.ua/wp-content/uploads/2009/12/exer1-src.zip'>archive</a> under The GNU Lesser General Public License (LGPLv3).</p>
<h3>Conclusion</h3>
<p>Collaboration design pattern is a useful abstraction for designing the application. Implementing collaborations with a new, promising Java language extension facilitates using of the first class language constructs (teams) and significantly improves the separation of concerns letting the developer to concentrate on one task at a time.</p>
]]></content:encoded>
			<wfw:commentRss>http://hutorny.in.ua/java/exercise-on-implementing-collaborations-with-objectteams-java/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using Java langauge constructs to define static graphs and trees</title>
		<link>http://hutorny.in.ua/java/using-java-langauge-constructs-to-define-static-graphs-and-trees</link>
		<comments>http://hutorny.in.ua/java/using-java-langauge-constructs-to-define-static-graphs-and-trees#comments</comments>
		<pubDate>Wed, 09 Dec 2009 10:13:01 +0000</pubDate>
		<dc:creator>Eugene</dc:creator>
				<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://hutorny.in.ua/?p=120</guid>
		<description><![CDATA[This article suggests an approach on adapting the Java programming language for defining static graphs and trees, gives an exercise on defining a microwave finite state automaton (FSA) using this approach and provides code sample for processing graph definitions]]></description>
			<content:encoded><![CDATA[<p>Graphs, networks and trees are commonly used to model application domains. In some cases these structures are highly dynamic and can not be defined at design time. Yet there are also cases when they are rather static and do not change during the application life cycle. An example of such static structure is a finite state automaton – defined as a part of design, it remains unchanged at the run-time.<br />
<span id="more-120"></span><br />
However, programming languages do not provide facilities that would make creation of graphs (trees) an easy task. Most common approach is to use XML with a custom schema and encode a graph (a tree) with XML tags. Unfortunately, development tools does not provide the same degree of support for editing an XML file as they do for many wide spread programming languages – detecting typos as  you type, reference navigation with one mouse click, etc. Additionally, using an XML requires a utility to process the XML and build a model corresponding to the definition. Another approach to define a graph &#8211; instantiating objects and establishing references among them “by hands”. The code created with this approach is burdened with poor readability and maintainability. An ideal solution would be using a domain specific language for these purposes, however cost of creating such a language is tremendous at present time.<br />
This article suggests an approach on adapting the Java programming language for defining static graphs, trees.</p>
<h3>The idea</h3>
<p>If we look at Java classes, interfaces and references among them at the high level of abstraction, their appear to be a linked graph where classes/interfaces can be thought as nodes and references – as links between them. These thoughts, being turned inside out, lead to the following rationales: a graph can be represented as a set of interfaces where an interface represents a node and a reference to another interface represents a link. Such references, for instance, could be return types of methods defined in the interface.</p>
<h3>Rationales</h3>
<p>The following table lists rationales on graph representation.</p>
<table border="1" cellspacing="0" cellpadding="0" width="100%" style="border-collapse:collapse;">
<tbody>
<tr>
<td width="199" valign="top"><em>FSA primitive</em></td>
<td width="458" valign="top"><em>Represented as</em></td>
</tr>
<tr>
<td width="199" valign="top"><strong>State chart</strong></td>
<td width="458" valign="top">A Java class that includes definition of all its states</td>
</tr>
<tr>
<td width="199" valign="top"><strong>State</strong></td>
<td width="458" valign="top">An interface extending <strong>State</strong> interface</td>
</tr>
<tr>
<td width="199" valign="top">Set of <strong>On Enter</strong> actions</td>
<td width="458" valign="top">One or more methods returning <strong>void</strong> and annotated with <strong>@OnEnter</strong></td>
</tr>
<tr>
<td width="199" valign="top"><strong>On Enter Action</strong></td>
<td width="458" valign="top">A parameter type extending <strong>Action</strong> of a method mentioned above</td>
</tr>
<tr>
<td width="199" valign="top">Set of <strong>On Leave</strong> actions</td>
<td width="458" valign="top">One or   more methods returning <strong>void</strong> and annotated with <strong>@OnLeave</strong></td>
</tr>
<tr>
<td width="199" valign="top"><strong>On Leave Action</strong></td>
<td width="458" valign="top">A parameter type extending <strong>Action</strong> of a method mentioned above</td>
</tr>
<tr>
<td width="199" valign="top"><strong>Transition</strong></td>
<td width="458" valign="top">A method returning interface corresponding to the “<strong>To</strong>” state</td>
</tr>
<tr>
<td width="199" valign="top"><strong>Condition</strong></td>
<td width="458" valign="top">A   parameter type extending <strong>Condition</strong> of a method mentioned above</td>
</tr>
<tr>
<td width="199" valign="top"><strong>Action</strong></td>
<td width="458" valign="top">A   parameter type extending <strong>Action</strong> of   a method mentioned above</td>
</tr>
</tbody>
</table>
<p></p>
<table border="0" cellspacing="0" cellpadding="0" width="160" align="right" style="padding-left:10px;">
<tbody>
<tr>
<td>
<a href="http://hutorny.in.ua/wp-content/uploads/2009/12/microwave.png" rel="thumbnail"><img src="http://hutorny.in.ua/wp-content/uploads/2009/12/microwave-150x150.png" alt="Microwave Automaton" title="microwave" width="150" height="150" class="size-thumbnail wp-image-127" /></a></td>
</tr>
<tr>
<td align="center"><b>Figure 1</b></td>
</tr>
</tbody>
</table>
<h3>Microwave automaton</h3>
<p>Lets consider a simple microwave with one push-button and a knob timer. This microwave starts heating when the user pushes the button and the door is closed and the timer is set. Pushing button again stops heating, opening the door suspends heating until the door is closed again. A state chart for this microwave is shown on <a href="http://hutorny.in.ua/wp-content/uploads/2009/12/microwave.png" rel="thumbnail"><b>Figure 1</b></a>. The following code snippet shows how this state chart can be represented with the rationales given above.</p>
<table border="0" cellspacing="0" cellpadding="0" width="100%" >
<tbody>
<tr>
<td>&nbsp;</td>
</tr>
</tbody>
</table>
<pre class="brush: java;">
public class MicrowaveStateMachine {
  /**
   * In Door Open State MW waits until the door is closed
   */
  interface DoorOpenState extends State {
	  @OnEnter void enter	(DoDing a);                            	// on entering Door Open State issue a Ding action
	  WaitingState  idle   	(OnDoorClose e, IfTimerIsSet a);  		// on Door Close Event transit to Waiting State
	  HeatingState  resume 	(OnDoorClose e, IfTimerIsNotSet a); 	// on Door Close Event transit to Waiting State
	  DoorOpenState ignore 	(OnPushButton e, DoBeep a);          	// on Push Button Event issue a Beep and remain in DoorOpenState
	  @OnLeave void leave	(DoDong a);								// on entering Door Close State issue a Dong
  }
  /**
   * In Waiting State MW waits until a button is pushed
   * If timer is set, it starts heating, otherwise it beeps
   */
  interface WaitingState extends State {
	  HeatingState  start   (OnPushButton e, IfTimerIsSet c);		// on Push Button Event if timer is set transit to heating
	  WaitingState  beep    (OnPushButton e, IfTimerIsNotSet c, DoBeep a); // otherwise issue a Beep and remain in waiting
	  DoorOpenState open    (OnDoorOpen e);							// on Door Open Event transit to Door Open State
  }
  /**
   * In Heating state it actually heats.
   * On entering this state MW starts the heater and the cook timer;
   * On leaving this state MW stops the heater and suspends the cook timer
   */
  interface HeatingState extends State {
	  @OnEnter void enter	(DoStartHeater a, DoStartCookTimer t); 	// on entering HeatingState State issue Start Heater Action
	  WaitingState  timer	(OnCookTimerExpired e);					// on Timer Expired Event transit to Waiting State
	  WaitingState  stop	(OnPushButton e);						// on Push Button Event transit to WaitingState State
	  DoorOpenState open	(OnDoorOpen e);							// on Door Open Event transit to Door Open State
	  @OnLeave void leave	(DoStopHeater a, DoSuspendCookTimer b);	// on leave issue DoStopHeater
  }
}
</pre>
<h3>Constructing run-time artifacts</h3>
<p>Obviously, this is only definition and it requires, as well as an XML definition, some code to turn it into a run-time artifact. Java Reflection API provides all necessary means for examining the definition but producing a valuable output is an application specific task. In other words, the task is split on two concerns &#8211; (1) examining the definition and (2) generating the output. The source code sample <a href="#attachments">attached</a> to this article provides a utility class that implements first concern (<code>Walker</code>) and an application class (<code>MicrowaveSample</code>) that generates microwave automaton assembler code for a PICmicro MCU (see sample output below). <code>Walker</code> class exposes one method <code>processAutomaton</code> accepting a state chart definition class and communicates with <code>MicrowaveSample</code> via <code>WalkerCallback</code> interface implemented by <code>MicrowaveSample</code>.</p>
<pre class="brush: picmicro; collapse: true; light: false; toolbar: true;">
;-----------------------------------------------------
DoorOpenState
    call DoDing
DoorOpenState_begin
    call sleepAndWaitEvents
DoorOpenState_0
    btfss OnDoorClose    ; resume
    bra DoorOpenState_1
    btfss IfTimerIsNotSet
    bra DoorOpenState_1
    call DoorOpenState_leave
    bra HeatingState
DoorOpenState_1
    btfss OnDoorClose    ; idle
    bra DoorOpenState_2
    btfss IfTimerIsSet
    bra DoorOpenState_2
    call DoorOpenState_leave
    bra WaitingState
DoorOpenState_2
    btfss OnPushButton    ; ignore
    bra DoorOpenState_3
    call DoBeep
    call DoorOpenState_leave
    bra DoorOpenState
DoorOpenState_3
DoorOpenState_end
    bra DoorOpenState_begin
DoorOpenState_leave
    call DoDong
    return
HeatingState
    call DoStartHeater
    call DoStartCookTimer
HeatingState_begin
    call sleepAndWaitEvents
HeatingState_0
    btfss OnPushButton    ; stop
    bra HeatingState_1
    call HeatingState_leave
    bra WaitingState
HeatingState_1
    btfss OnDoorOpen    ; open
    bra HeatingState_2
    call HeatingState_leave
    bra DoorOpenState
HeatingState_2
    btfss OnCookTimerExpired    ; timer
    bra HeatingState_3
    call HeatingState_leave
    bra WaitingState
HeatingState_3
HeatingState_end
    bra HeatingState_begin
HeatingState_leave
    call DoStopHeater
    call DoSuspendCookTimer
    return
WaitingState
WaitingState_begin
    call sleepAndWaitEvents
WaitingState_0
    btfss OnPushButton    ; start
    bra WaitingState_1
    btfss IfTimerIsSet
    bra WaitingState_1
    bra HeatingState
WaitingState_1
    btfss OnDoorOpen    ; open
    bra WaitingState_2
    bra DoorOpenState
WaitingState_2
    btfss OnPushButton    ; beep
    bra WaitingState_3
    btfss IfTimerIsNotSet
    bra WaitingState_3
    call DoBeep
    bra WaitingState
WaitingState_3
WaitingState_end
    bra WaitingState_begin
</pre>
<table border="0" cellspacing="0" cellpadding="0" width="160" align="right" style="padding-left:10px;">
<tbody>
<tr>
<td><a href="http://hutorny.in.ua/wp-content/uploads/2009/12/microwave-new.png" rel="thumbnail"><img src="http://hutorny.in.ua/wp-content/uploads/2009/12/microwave-new-150x150.png" alt="microwave-new" title="microwave-new" width="150" height="150" class="alignnone size-thumbnail wp-image-149" /></a></td>
</tr>
<tr>
<td align="center"><b>Figure 2</b></td>
</tr>
</tbody>
</table>
<h3>Extending state charts</h3>
<p>Now, lets image that we have this microwave automaton in full production, and R&#038;D department came up with a innovative and conceptual design of a microwave with <b>two</b> buttons <img src='http://hutorny.in.ua/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  and sales department insisted on adding a &#8216;polite reminder&#8217; feature. State chart for the new microwave automaton is given on <a href="http://hutorny.in.ua/wp-content/uploads/2009/12/microwave-new.png" rel="thumbnail"><b>Figure 2</b></a> where blue color indicates new state and transitions and red cross denotes transition no longer needed. A big part of the state chart remains the same as in previous version one and, thus, can be reused in a new state chart. With the approach that this article suggests, a state chart can be extended by means of Java inheritance, e.g. new state chart <code>extends</code> the previous. With very little efforts the new automaton is defined as given below. </p>
<table border="0" cellspacing="0" cellpadding="0" width="100%" >
<tbody>
<tr>
<td>&nbsp;</td>
</tr>
</tbody>
</table>
<pre class="brush: java;">
/**
 * State machine of a microwave oven with two buttons and polite reminder feature:
 * when cooked and door was not open - beep every N seconds during M minutes
 */
public class ModernMicrowaveStateMachine extends MicrowaveStateMachine {
	  /**
	   * This machine introduces several new events and actions
	   */
	  interface OnPushStopButton extends Event {}
	  interface OnPoliteBeepTimer extends Event {}
	  interface OnPoliteOffTimer extends Event {}
	  interface DoStartPoliteBeepTimer extends Action {}
	  interface DoStopPoliteBeepTimer extends Action {}
	  interface DoStartPoliteOffTimer extends Action {}
	  interface DoStopPoliteOffTimer extends Action {}
	  interface DoAddOneMinuteCookTimer extends Action {}

	  /**
	   * Alter the inherited Heating State
	   */
	  interface HeatingState extends MicrowaveStateMachine.HeatingState {
		  HeatingState	add		(OnPushButton e, DoAddOneMinuteCookTimer a);  // add one minute to the timer when push button is pressed
		  @Disable
		  WaitingState	timer	(OnCookTimerExpired e);					// disable this transition inherited from the old MW
		  CookedState   cooked	(OnCookTimerExpired e);					// introduce new transition on Timer Expired Event transit to CookedState State
		  WaitingState  stop	(OnPushStopButton e);					// on Push Stop Button Event transit to WaitingState State
		  @Disable
		  WaitingState  stop	(OnPushButton e);						// disable this transition inherited from the old MW
	  }
	  /**
	   * Add new state to provide polite beep reminder
	   */
	  interface CookedState extends State {
		  @OnEnter void onEnter	(DoStartPoliteBeepTimer a, DoStartPoliteOffTimer b ); // on enter start timers Polite Beep and Polite Off
		  DoorOpenState stop	(OnDoorOpen e);							// on Door Open Event transit to Door Open State
		  HeatingState  start1	(OnPushButton e, IfTimerIsNotSet i, DoAddOneMinuteCookTimer t); // on Push Button Event transit to WaitingState State
		  HeatingState  start	(OnPushButton e, IfTimerIsSet i);  		// on Push Button Event transit to WaitingState State
		  WaitingState  stop	(OnPushStopButton e); 					// on Push Stop Button Event transit to WaitingState State
		  WaitingState  idle	(OnPoliteOffTimer e); 					// stop beeping after M minutes
		  CookedState   beep	(OnPoliteBeepTimer e); 					// beep every N seconds
		  @OnLeave void onleave	(DoStopPoliteBeepTimer a, DoStopPoliteOffTimer b ); 	// on leave stop timers
	  }
}
</pre>
<p>There is one new annotation added: <code>@Disabled</code>. It is used to indicate a deletion of unused links that were inherited from the original chart. Output for this automaton is following</p>
<pre class="brush: picmicro; collapse: true; light: false; toolbar: true;">
;-----------------------------------------------------
CookedState
    call DoStartPoliteBeepTimer
    call DoStartPoliteOffTimer
CookedState_begin
    call sleepAndWaitEvents
CookedState_0
    btfss OnPushButton    ; start
    bra CookedState_1
    btfss IfTimerIsSet
    bra CookedState_1
    call CookedState_leave
    bra HeatingState
CookedState_1
    btfss OnPushStopButton    ; stop
    bra CookedState_2
    call CookedState_leave
    bra WaitingState
CookedState_2
    btfss OnDoorOpen    ; stop
    bra CookedState_3
    call CookedState_leave
    bra DoorOpenState
CookedState_3
    btfss OnPoliteOffTimer    ; idle
    bra CookedState_4
    call CookedState_leave
    bra WaitingState
CookedState_4
    btfss OnPoliteBeepTimer    ; beep
    bra CookedState_5
    call CookedState_leave
    bra CookedState
CookedState_5
    btfss OnPushButton    ; start1
    bra CookedState_6
    btfss IfTimerIsNotSet
    bra CookedState_6
    call DoAddOneMinuteCookTimer
    call CookedState_leave
    bra HeatingState
CookedState_6
CookedState_end
    bra CookedState_begin
CookedState_leave
    call DoStopPoliteBeepTimer
    call DoStopPoliteOffTimer
    return
HeatingState
    call DoStartHeater
    call DoStartCookTimer
HeatingState_begin
    call sleepAndWaitEvents
HeatingState_0
    btfss OnPushButton    ; add
    bra HeatingState_1
    call DoAddOneMinuteCookTimer
    call HeatingState_leave
    bra HeatingState
HeatingState_1
    btfss OnPushStopButton    ; stop
    bra HeatingState_2
    call HeatingState_leave
    bra WaitingState
HeatingState_2
    btfss OnCookTimerExpired    ; cooked
    bra HeatingState_3
    call HeatingState_leave
    bra CookedState
HeatingState_3
HeatingState_end
    bra HeatingState_begin
HeatingState_leave
    call DoStopHeater
    call DoSuspendCookTimer
    return
DoorOpenState
    call DoDing
DoorOpenState_begin
    call sleepAndWaitEvents
DoorOpenState_0
    btfss OnDoorClose    ; resume
    bra DoorOpenState_1
    btfss IfTimerIsNotSet
    bra DoorOpenState_1
    call DoorOpenState_leave
    bra HeatingState
DoorOpenState_1
    btfss OnDoorClose    ; idle
    bra DoorOpenState_2
    btfss IfTimerIsSet
    bra DoorOpenState_2
    call DoorOpenState_leave
    bra WaitingState
DoorOpenState_2
    btfss OnPushButton    ; ignore
    bra DoorOpenState_3
    call DoBeep
    call DoorOpenState_leave
    bra DoorOpenState
DoorOpenState_3
DoorOpenState_end
    bra DoorOpenState_begin
DoorOpenState_leave
    call DoDong
    return
WaitingState
WaitingState_begin
    call sleepAndWaitEvents
WaitingState_0
    btfss OnPushButton    ; start
    bra WaitingState_1
    btfss IfTimerIsSet
    bra WaitingState_1
    bra HeatingState
WaitingState_1
    btfss OnDoorOpen    ; open
    bra WaitingState_2
    bra DoorOpenState
WaitingState_2
    btfss OnPushButton    ; beep
    bra WaitingState_3
    btfss IfTimerIsNotSet
    bra WaitingState_3
    call DoBeep
    bra WaitingState
WaitingState_3
WaitingState_end
    bra WaitingState_begin
</pre>
<h3>Representing other graph and tree-alike structures</h3>
<p>Although, this article is focused on finite state automatons, similar approach can be applied for defining other kind of graphs and trees. The author has a proof of concept for using nested classes as a representation of a web-application URI structure and mapping HTTP requests issued by very complex but strictly structured HTML forms.</p>
<p><a id="attachments"></a></p>
<h3>Attachments</h3>
<p><a href='http://hutorny.in.ua/wp-content/uploads/2009/12/FSA-Sources.zip'>FSA-Sources</a></p>
<table border="0" cellspacing="0" cellpadding="0" width="100%" >
<tbody>
<tr>
<td>&nbsp;</td>
</tr>
</tbody>
</table>
]]></content:encoded>
			<wfw:commentRss>http://hutorny.in.ua/java/using-java-langauge-constructs-to-define-static-graphs-and-trees/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>A convenient approach on keeping SQL in Java</title>
		<link>http://hutorny.in.ua/java/a-convenient-approach-on-keeping-sql-in-java</link>
		<comments>http://hutorny.in.ua/java/a-convenient-approach-on-keeping-sql-in-java#comments</comments>
		<pubDate>Tue, 24 Nov 2009 12:00:45 +0000</pubDate>
		<dc:creator>Eugene</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[comments]]></category>
		<category><![CDATA[queries]]></category>
		<category><![CDATA[SQL]]></category>

		<guid isPermaLink="false">http://hutorny.in.ua/?p=109</guid>
		<description><![CDATA[Where to keep SQL statements? This question arises almost for any more-less sophisticated Java application that accesses DBMS. Two most common approaches are: (1) as string constants in Java and (2) as text in external files. Both these approaches have significant drawbacks. Java strings get complicated when a string is too long to fit in [...]]]></description>
			<content:encoded><![CDATA[<p>Where to keep SQL statements? This question arises almost for any more-less sophisticated Java application that accesses DBMS. Two most common approaches are: (1) as string constants in Java and (2) as text in external files. Both these approaches have significant drawbacks. Java strings get complicated when a string is too long to fit in one line, leading to a difficult to read and hard to maintain SQL code. SQL in external files are not easy to lookup and require some mapping technique to associate statement in the external file with a place in Java where it is needed. Also, as development goes, the text file adheres with more and more orphan SQL statements and there is no easy way to clean them up. This article suggests an approach that combines two mentioned above and inherits their strong sides.<br />
<span id="more-109"></span>The idea is very simple – keep SQL statements in the source Java file as comments following the definition of a string member, load them at run-time and assign to the corresponding member. The following example gives a grasp on this technique.</p>
<pre class="brush: java;">
public class SQLpeople {
  public static final String sqlSELECTall = Comments.load();
  /*--
    SELECT * FROM people;
    --*/
}
</pre>
<p>To make it available at run-time, this source file should be packaged together with the class file. That&#8217;s everything you need to make SQL statements loaded&#8230;<br />
Well, almost everything <img src='http://hutorny.in.ua/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> . One minor thing left is an implementation of Comments.load(). You may implement it in your own or download from <a href="http://sourceforge.net/projects/commentsload/files/">SourceForge</a> an open source implementation (under <a href="http://www.opensource.org/licenses/lgpl-3.0.html">LGPLv3 license</a>).</p>
<h3>Dialectism</h3>
<p>If your application is designed to run with different DBMS engines, maintaining SQL in different dialects may become a challenge. The Comments class proposes a solution as illustrated below:</p>
<pre class="brush: java; wrap-lines: false;">
public class SQLpeople {
  public static final String sqlSELECTtopN = Comments.load(getCurrentDBMS());
  /*--
    --: pgsql
    SELECT * FROM people LIMIT ?;
    --: mssql
    SELECT TOP ? * FROM people;
    --*/
}
</pre>
<p>Where getCurrentDBMS() is your static function that returns name of the current DBMS, and <code>--:</code> pgsql and <code>--:</code> mssql are discriminator values designating statements appropriate for different DBMS.</p>
<h3>How it works</h3>
<p>The <em>Comments</em> class just a friendly decorator created for the sake of convenience. Its method load() uses StackFrame to gather information about invocation point and passes name of the source file, line number (<em>N</em>), and class name to the CommentRetriever.retrieve(), which opens the source file as a resource stream, skips <em>N</em> lines, reads content until it finds <strong><code>--*/</code></strong> in the line and then uses regex to extract content between <strong><code>/*--</code></strong> and <strong><code>--*/</code></strong>. If the <em>discriminator</em> parameter is null, <em>retrieve</em> returns extracted content. Otherwise it finds designators <strong><code>--:</code> &lt;discriminator&gt;</strong> and tests its equity against the parameter. If they are equal method returns content of the section between the current discriminator and the next one or end of the block. If block contains no discriminator equal to the parameter, it returns content before the first discriminator, unless default values are disabled by <i>NODEFAULTS</i> option.<br />
That’s all you need to start using this class, for advanced topics please refer to <a href="http://hutorny.in.ua/common/commentsload/javadoc/">Java docs</a>.</p>
<h3>Guidelines on authoring comments</h3>
<p>There should be no characters between the end of the load() line and sequence <code>/*--</code> that opens the block, except, of course, white spaces (space, tab, new line).</p>
<pre class="brush: java; wrap-lines: false;">
public class SQLpeople {
  /*
   * allowed comment
   */

  public static final String sqlSELECTall = Comments.load(); -- allowed comment

  /* disallowed comment */
  /*--
    SELECT * FROM people;
    --*/

}
</pre>
<p>Discriminator takes entire line, there should be no other text in this line</p>
<h3>Errors</h3>
<p>By default error messages are returned as output value and prepended with <code>"--"</code>, are returned as the result of load() method. Although, this behavior can be opted (see <a href="http://hutorny.in.ua/common/commentsload/javadoc/">Java docs</a> for details).</p>
]]></content:encoded>
			<wfw:commentRss>http://hutorny.in.ua/java/a-convenient-approach-on-keeping-sql-in-java/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Theoretical aspects of dimming an incandescent lamp</title>
		<link>http://hutorny.in.ua/research/theoretical-aspects-of-dimming-an-incandescent-lamp</link>
		<comments>http://hutorny.in.ua/research/theoretical-aspects-of-dimming-an-incandescent-lamp#comments</comments>
		<pubDate>Thu, 23 Jul 2009 12:49:26 +0000</pubDate>
		<dc:creator>Eugene</dc:creator>
				<category><![CDATA[Research]]></category>

		<guid isPermaLink="false">http://hutorny.in.ua/research/theoretical-aspects-of-dimming-an-incandescent-lamp</guid>
		<description><![CDATA[Abstract
A dimmer is an electronic device that controls alternate voltage applied to a lamp through delivering a selected portion of the mains sinusoid. Engineer, designing a dimmer needs to estimate how big this portion should be to get a desired luminance level. This article uses a model of incandescent lamp, tungsten resistivity, and human eye [...]]]></description>
			<content:encoded><![CDATA[<h1 class="Heading1">Abstract</h1>
<p>A dimmer is an electronic device that controls alternate voltage applied to a lamp through delivering a selected portion of the mains sinusoid. Engineer, designing a dimmer needs to estimate how big this portion should be to get a desired luminance level. This article uses a model of incandescent lamp, tungsten resistivity, and human eye spectral efficiency to derive dependency of produced luminous flux over the voltage, gives a simple analytical function that describes this dependency with good accuracy (&plusmn;2% comparing to the model).</p>
<p><span id="more-105"></span></p>
<p align="right"><small><a href="http://hutorny.in.ua/ta/Theoretical-aspects-of-dimming-an-incandescent-lamp.pdf">Download PDF version of this article</a></small></p>
<h1 class="Heading1">Structured Abstract</h1>
<table border=1 cellspacing=0 cellpadding=0 style='border-collapse:collapse;border:solid windowtext 1.0pt'>
<tr>
<td width=235 valign=top style='width:176.4pt;border:solid windowtext 1.0pt; border-top:solid windowtext 1.0pt;padding:0cm 2pt 0cm 2pt'>
<p>Purpose</p>
</td>
<td width=482 valign=top style='width:361.35pt;border-top:solid windowtext 1.0pt;border-left:none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;padding:0cm 2pt 0cm 2pt'>
<p>To discover a dependency of luminous flux produced by an incandescent lamp on the applied voltage</p>
</td>
</tr>
<tr>
<td width=235 valign=top style='width:176.4pt;border:solid windowtext 1.0pt; border-top:none;padding:0cm 2pt 0cm 2pt'>
<p>Methodology/Approach</p>
</td>
<td width=482 valign=top style='width:361.35pt;border-top:none;border-left:none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;padding:0cm 2pt 0cm 2pt'>
<p>Numerical analysis on a theoretical model of an incandescent lamp</p>
</td>
</tr>
<tr>
<td width=235 valign=top style='width:176.4pt;border:solid windowtext 1.0pt; border-top:none;padding:0cm 2pt 0cm 2pt'>
<p>Findings</p>
</td>
<td width=482 valign=top style='width:361.35pt;border-top:none;border-left: none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt; padding:0cm 2pt 0cm 2pt'>
<p>Analytical function for approximate estimating of luminous flux for the applied voltage with &plusmn;2% accuracy</p>
</td>
</tr>
<tr>
<td width=235 valign=top style='width:176.4pt;border:solid windowtext 1.0pt; border-top:none;padding:0cm 2pt 0cm 2pt'>
<p>Research limitations/implications</p>
</td>
<td width=482 valign=top style='width:361.35pt;border-top:none;border-left: none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt; padding:0cm 2pt 0cm 2pt'>
<p>Model does not encounter thermal conduction and convection in the lamp.</p>
</td>
</tr>
<tr>
<td width=235 valign=top style='width:176.4pt;border:solid windowtext 1.0pt; border-top:none;padding:0cm 2pt 0cm 2pt'>
<p>Practical implications (if applicable)</p>
</td>
<td width=482 valign=top style='width:361.35pt;border-top:none;border-left: none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt; padding:0cm 2pt 0cm 2pt'>
<p>Provided function has some degree of dependency on the lamp&#8217;s design (namely, nominal filament temperature)</p>
</td>
</tr>
</table>
<p></p>
<h1 class="Heading1">Definitions</h1>
<p>Process of controlling some output value (such as voltage <i><code>U</code></i> or luminous flux <i><code>L</code></i>) we will denote as a control function <img src="/ta/image001.gif" width=104 height=20 align="absmiddle"/>, defined on the control parameter&nbsp;<img src="/ta/image002.gif" width=76 height=20 align="absmiddle"/>:</p>
<table width="100%" border="0" cellspacing="0" cellpadding="0" class=".TableHidden">
<tr>
<td width="90%" align="center"><img src="/ta/image003.gif"/>&nbsp;</td>
<td width="10%" align="right"><span class=FormulaNum style='font-size:12.0pt'>(1)</span></td>
</tr>
</table>
<p>Each of <img src="/ta/image004.gif" width=29 height=20 align="absmiddle"/>&nbsp;monotonously increase on the defined range. Control functions defined on a different (other than <img src="/ta/image005.gif" width=13 height=16 align="absmiddle"/>) argument we will denote in this article as <img src="/ta/image006.gif" width=28 height=23 align="absmiddle"/>.</p>
<p>Commonly used are linear (<img src="/ta/image007.gif" width=141 height=21 align="absmiddle"/>) and logarithmic (<img src="/ta/image008.gif" width=157 height=21 align="absmiddle"/>) control functions. To implement a desired control function <img src="/ta/image009.gif" width=39 height=23 align="absmiddle"/>, we needs to know what is <img src="/ta/image010.gif" width=45 height=24 align="absmiddle"/>&nbsp;dependency.&nbsp;<br />
The following chapters give an attempt to derive <img src="/ta/image011.gif" width=44 height=24 align="absmiddle"/>&nbsp;using a model suggested in (Agraval 1996).</p>
<p></p>
<h1 class="Heading1">Incandescent Lamp Model</h1>
<p>An incandescent lamp is characterized with few nominal values: <span class=Formula>P<sub>N</sub></span> &#8211; power consumption, <span class=Formula>U<sub>N</sub></span> &#8211; nominal voltage, <span class=Formula>L<sub>N</sub></span> &#8211; nominal luminous flux, produced by the lamp at nominal voltage. The flux is produced by filament, incandesced to nominal working temperature <span class=Formula>T<sub>N</sub></span>.<br />
When lower voltage <span class=Formula>U&lt;U<sub>N</sub></span> is applied, operating temperature <span class=Formula>T</span> of filament is lower <span class=Formula>T<sub>N</sub></span> and therefore it produces less luminosity <span class=Formula>L</span>.</p>
<h2 class="Heading2">Filament Resistance</h2>
<p>Power, consumed by a lamp, is expressed with Ohm low: </p>
<table width="100%" border="0" cellspacing="0" cellpadding="0" class=".TableHidden">
<tr>
<td width="90%" align="center"><img width=168 height=48 src="/ta/image012.gif"/>&nbsp;</td>
<td width="10%" align="right"><a name=e2><span class=FormulaNum style='font-size:12.0pt'>(2)</span></a></td>
</tr>
</table>
<p>where <img src="/ta/image013.gif" width=131 height=24 align="absmiddle"/>&nbsp;defines dependency of filament resistance over the temperature relatively to its nominal resistance <span class=Formula>R<sub>N</sub></span>, which can be evaluated via <span class=Formula>P<sub>N</sub></span> and <span class=Formula>U<sub>N</sub></span>:</p>
<table width="100%" border="0" cellspacing="0" cellpadding="0" class=".TableHidden">
<tr>
<td width="90%" align="center"><img width=64 height=48 src="/ta/image014.gif"/>&nbsp;</td>
<td width="10%" align="right"><span class=FormulaNum style='font-size:12.0pt'>(3)</span></td>
</tr>
</table>
<p>Dependency <img src="/ta/image015.gif" width=31 height=20 align="absmiddle"/>&nbsp;for tungsten is not linear in the working range of temperatures (1000-2500K). For this model we will use polynomial approximation of tungsten resistance <i><span style='font-size:12.0pt;font-family:"Times New Roman"'>&#961;</span></i>, [<a href="#ref_Harang_2003"><span style='color:windowtext; text-decoration:none'>Harang 2003</span></a>]:</p>
<table width="100%" border="0" cellspacing="0" cellpadding="0" class=".TableHidden">
<tr>
<td width="90%" align="center"><img border=0 width=161 height=27 src="/ta/image016.gif"/>&nbsp;</td>
<td width="10%" align="right"><span class=FormulaNum style='font-size:12.0pt'>(4)</span></td>
</tr>
</table>
<p class=FormulaP><img src="/ta/image015.gif" width=31 height=20 border=0 align="absmiddle"/>&nbsp;can be expressed via <img src="/ta/image017.gif" width=32 height=20 border=0 align="absmiddle"/>&nbsp;as the following:</p>
<table width="100%" border="0" cellspacing="0" cellpadding="0" class=".TableHidden">
<tr>
<td width="90%" align="center"><img border=0 width=92 height=45 src="/ta/image018.gif"/>&nbsp;</td>
<td width="10%" align="right"><span class=FormulaNum style='font-size:12.0pt'>(5)</span></td>
</tr>
</table>
<h2 class="Heading2">Filament Temperature</h2>
<p>During operation, filament radiates electromagnetic energy and dissipates heat via conduction and convection. To estimate radiation, filament is modeled [<a href="#ref_Agraval_1996"><span style='color:windowtext;text-decoration:none'>Agraval 1996</span></a>] as a simple non-ideal blackbody that obeys Plank&#8217;s radiation law:</p>
<table width="100%" border="0" cellspacing="0" cellpadding="0" class=".TableHidden">
<tr>
<td width="90%" align="center"><img border=0 width=261 height=57 src="/ta/image019.gif"/>&nbsp;</td>
<td width="10%" align="right"><span class=FormulaNum style='font-size:12.0pt'>(6)</span></td>
</tr>
</table>
<p>where <img src="/ta/image020.gif" width=72 height=20 border=0 align="absmiddle"/>&nbsp;is power radiated between wavelength&nbsp;<img src="/ta/image021.gif" width=15 height=19 border=0 align="absmiddle"/>&nbsp;and&nbsp;<img src="/ta/image022.gif" width=48 height=19 border=0 align="absmiddle"/>, <img src="/ta/image023.gif" width=49 height=21 border=0 align="absmiddle"/>&nbsp;- tungsten emittance, and <span class=Formula>A</span> is filament area. The total power emitted over all wavelengths is:</p>
<table width="100%" border="0" cellspacing="0" cellpadding="0" class=".TableHidden">
<tr>
<td width="90%" align="center"><img border=0 width=116 height=24 src="/ta/image024.gif"/>&nbsp;</td>
<td width="10%" align="right"><span class=FormulaNum style='font-size:12.0pt'>(7)</span></td>
</tr>
</table>
<p>where <b><i><code>&#963;</code></i></b> is the Stefan-Boltzman constant and <img src="/ta/image025.gif" width=29 height=20 border=0 align="absmiddle"/>&nbsp;is average emittance over all wavelengths, which is approximated as a second order polynomial (Harang 2003):</p>
<table width="100%" border="0" cellspacing="0" cellpadding="0" class=".TableHidden">
<tr>
<td width="90%" align="center"><img border=0 width=160 height=25 src="/ta/image026.gif"/>&nbsp;</td>
<td width="10%" align="right"><a name=e8><span class=FormulaNum style='font-size:12.0pt'>(8)</span></a></td>
</tr>
</table>
<p>In a steady-state operation, power applied to the lamp is in balance with power radiated and dissipated to outside ambient. Dissipation has two constituents &#8211; conduction and convection. Agraval in [<a href="#ref_Agraval_1996"><span style='color:windowtext;text-decoration: none'>Agraval 1996</span></a>] has suggested a reasonable way of accounting dissipation as a factor of input power:</p>
<table width="100%" border="0" cellspacing="0" cellpadding="0" class=".TableHidden">
<tr>
<td width="90%" align="center"><img border=0 width=95 height=21 src="/ta/image027.gif"/>&nbsp;</td>
<td width="10%" align="right"><span class=FormulaNum style='font-size:12.0pt'>(9)</span></td>
</tr>
</table>
<p>Solving&nbsp;<span class=FormulaRef>(8)&nbsp;</span>for <span class=Formula>P</span>:</p>
<table width="100%" border="0" cellspacing="0" cellpadding="0" class=".TableHidden">
<tr>
<td width="90%" align="center"><img border=0 width=105 height=44 src="/ta/image028.gif"/>&nbsp;</td>
<td width="10%" align="right"><a name=e10><span class=FormulaNum style='font-size:12.0pt'>(10)</span></a></td>
</tr>
</table>
<p>Substituting left side of <span class=FormulaRef></span><span class=FormulaNum style='font-size:12.0pt'>(10)</span>&nbsp;with right side of <span class=FormulaRef></span><span class=FormulaNum style='font-size:12.0pt'>(2)</span>:</p>
<table width="100%" border="0" cellspacing="0" cellpadding="0" class=".TableHidden">
<tr>
<td width="90%" align="center"><img border=0 width=321 height=48 src="/ta/image029.gif"/>&nbsp;</td>
<td width="10%" align="right"><a name=e11><span class=FormulaNum style='font-size:12.0pt'>(11)</span></a></td>
</tr>
</table>
<p>Using <span class=FormulaNum style='font-size:12.0pt'>(11)</span>, we may derive <img src="/ta/image030.gif" width=39 height=25 border=0 align="absmiddle"/>:</p>
<table width="100%" border="0" cellspacing="0" cellpadding="0" class=".TableHidden">
<tr>
<td width="90%" align="center"><img border=0 width=192 height=55 src="/ta/image031.gif"/>&nbsp;</td>
<td width="10%" align="right"><span class=FormulaNum style='font-size:12.0pt'>(12)</span></td>
</tr>
</table>
<p class=MsoNormal style='page-break-after:avoid'>Figure 1 illustrates dependency <img src="/ta/image032.gif" width=39 height=25 border=0 align="absmiddle"/></p>
<p class=MsoNormal align=center style='margin-top:12.0pt;text-align:center; page-break-after:avoid'><img border=0 width=366 height=336 src="/ta/image033.gif"/></p>
<p class=MsoCaption align=center style='text-align:center'><a name="_Ref164682915">Figure 1</a>. Dependency of <span class=Formula></span><span style='font-weight:normal;font-style:normal'>T</span> on fraction of applied voltage <span class=Formula></span><span style='font-weight:normal;font-style:normal'>&#958;<sub>U</sub></span> for different <span class=Formula></span><span style='font-weight:normal;font-style:normal'>T<sub>N</sub></span></p>
<h2 class="Heading2">Luminance</h2>
<p class=MsoNormal style='margin-top:12.0pt'>Not all power radiated by filament has its effect on luminous flux. Some of the energy is absorbed by bulb glass and dissipated as heat. Although, this absorption depends on <span class=Formula>&#955;</span>, we will simplify this absorption to a constant factor <span style='font-family:"Times New Roman"'>&#951;&lt;1</span>.</p>
<p>Major part of the emitted energy is not visible to human eye. This is described as spectral efficiency function <span class=Formula>S(&#955;)</span>, approximated as the following [<a href="#ref_Agraval_1996"><span style='color:windowtext;text-decoration:none'>Agraval 1996</span></a>]:</p>
<table width="100%" border="0" cellspacing="0" cellpadding="0" class=".TableHidden">
<tr>
<td width="90%" align="center"><img border=0 width=172 height=27 src="/ta/image034.gif"/>&nbsp;</td>
<td width="10%" align="right"><span class=FormulaNum style='font-size:12.0pt'>(13)</span></td>
</tr>
</table>
<p class=MsoNormal style='margin-top:12.0pt;page-break-after:avoid'>Thus, total luminous flux produced by a lamp can be defined as:</p>
<table width="100%" border="0" cellspacing="0" cellpadding="0" class=".TableHidden">
<tr>
<td width="90%" align="center"><img border=0 width=444 height=60 src="/ta/image035.gif"/>&nbsp;</td>
<td width="10%" align="right"><span class=FormulaNum style='font-size:12.0pt'>(14)</span></td>
</tr>
</table>
<p>where</p>
<table width="100%" border="0" cellspacing="0" cellpadding="0" class=".TableHidden">
<tr>
<td width="90%" align="center"><img border=0 width=161 height=60 src="/ta/image036.gif"/>&nbsp;</td>
<td width="10%" align="right"><span class=FormulaNum style='font-size:12.0pt'>(15)</span></td>
</tr>
</table>
<p>Thereby, control function <img src="/ta/image037.gif" width=19 height=23 border=0 align="absmiddle"/>&nbsp;can be expressed as a function of <span class=Formula>T</span>:</p>
<table width="100%" border="0" cellspacing="0" cellpadding="0" class=".TableHidden">
<tr>
<td width="90%" align="center"><img border=0 width=149 height=45 src="/ta/image038.gif"/>&nbsp;</td>
<td width="10%" align="right"><a name=e15><span class=FormulaNum style='font-size:12.0pt'>(16)</span></a></td>
</tr>
</table>
<p>For working range of temperatures and visible area, emissivity <span class=Formula>&#1108;(&#955;,T)</span> can be approximated as the following [<a href="#ref_Larrabee_1957"><span style='color:windowtext;text-decoration:none'>Larrabee&nbsp;1957</span></a>]:</p>
<table width="100%" border="0" cellspacing="0" cellpadding="0" class=".TableHidden">
<tr>
<td width="90%" align="center"><img border=0 width=445 height=66 src="/ta/image039.gif"/>&nbsp;</td>
<td width="10%" align="right"><a name=e16><span class=FormulaNum style='font-size:12.0pt'>(17)</span></a></td>
</tr>
</table>
<p class=MsoNormal style='page-break-after:avoid'>where <span class=Formula>T</span> is in &deg;K and <span class=Formula>&#955;</span> in nm. Substituting <span class=FormulaRef>(17)</span> in <span class=FormulaRef>(16)</span> and integrating numerically <span class=FormulaRef>(16)</span> we get dependency, shown on Figure 2:</p>
<p class=MsoNormal align=center style='margin-top:12.0pt;text-align:center;page-break-after:avoid'><img border=0 width=366 height=336 src="/ta/image040.gif"/></p>
<p class=MsoCaption align=center style='text-align:center'><a name="_Ref164327531">Figure 2</a>. Dependency <span class=Formula></span><span style='font-weight:normal;font-style:normal'>&#958;<sub>L</sub></span><span class=Formula></span><span style='font-weight:normal'>(</span><span class=Formula></span><span style='font-weight:normal;font-style:normal'>T</span><span class=Formula></span><span style='font-weight:normal'>)</span> for different <span class=Formula></span><span style='font-weight:normal'>T<sub>N</sub></span></p>
<p></p>
<h1 class="Heading1">Solving Luminance vs. Voltage</h1>
<p class=MsoNormal style='page-break-after:avoid'>Using <span class=Formula>T</span> as a parametric variable, we may numerically compute <span class=FormulaRef>(11)</span>, <span class=FormulaRef>(15)</span> and graphically solve dependency <span class=Formula>&#958;<sub>L</sub>(&#958;<sub>U</sub>)</span>, as shown on Figure 3:</p>
<p class=MsoNormal align=center style='margin-top:12.0pt;text-align:center; page-break-after:avoid'><img border=0 width=366 height=335 src="/ta/image041.gif"/></p>
<p class=MsoCaption align=center style='text-align:center'><a name="_Ref164328881">Figure </a>3. Dependency <span class=Formula></span><span style='font-weight:normal;font-style:normal'>&#958;<sub>L</sub></span><span class=Formula></span><span style='font-weight:normal'>(</span><span class=Formula></span><span style='font-weight:normal;font-style:normal'>&#958;<sub>U</sub></span><span class=Formula></span><span style='font-weight:normal'>) </span>for different <span class=Formula></span><span style='font-weight:normal;font-style:normal'>T<sub>N</sub></span></p>
<p>As Figure 3 indicates, <span class=Formula></span><span style='font-style:normal'>&#958;<sub>L</sub></span>(<span class=Formula></span><span style='font-style:normal'>&#958;<sub>U</sub></span>) is affected by a design factor &#8211; nominal temperature <span class=Formula>T<sub>N</sub></span>.</p>
<p></p>
<h1 class="Heading1">Approximation</h1>
<p class=MsoCaption align=center style='text-align:center;page-break-after: avoid'><img border=0 width=366 height=345 src="/ta/image042.gif"/></p>
<p class=MsoCaption align=center style='text-align:center'><a name="_Ref164331865">Figure </a>4. Dependency <span class=Formula></span><span style='font-weight:normal'>&#958;<sub>L</sub>(&#958;<sub>U</sub><sup>3</sup>)</span></p>
<p>As it appears (see Figure 4), dependency <span class=Formula>&#958;<sub>L</sub></span>(<span class=Formula>&#958;<sub>U</sub></span><span class=Formula><sup>3</sup>) </span>looks quite linear for <span class=Formula>&#958;<sub>U</sub></span><span class=Formula><sup>3</sup>&gt;0.2</span> and has some higher-order dependency for <span class=Formula>&#958;<sub>U</sub></span><span class=Formula><sup>3</sup>&lt;0.2</span>. Therefore we will try approximating <span class=Formula>&#958;<sub>L</sub></span>(<span class=Formula>&#958;<sub>U</sub></span>) as two polynoms:</p>
<table width="100%" border="0" cellspacing="0" cellpadding="0" class=".TableHidden">
<tr>
<td width="90%" align="center"><img border=0 width=160 height=51 src="/ta/image043.gif"/>&nbsp;</td>
<td width="10%" align="right"><span class=FormulaNum style='font-size:12.0pt'>(18)</span></td>
</tr>
</table>
<p>Value <span class=Formula></span><span style='font-style:normal'>&#958;<sub>L</sub></span>at <code>x=1</code> is equal to <code>1</code> by nature of <span class=Formula></span><span style='font-style:normal'>&#958;</span>, therefore <code>c</code>&nbsp;can be expressed via <code>k</code>:</p>
<table width="100%" border="0" cellspacing="0" cellpadding="0" class=".TableHidden">
<tr>
<td width="90%" align="center"><img border=0 width=205 height=25 src="/ta/image044.gif"/>&nbsp;</td>
<td width="10%" align="right"><span class=FormulaNum style='font-size:12.0pt'>(19)</span></td>
</tr>
</table>
<p>To solve <code>a</code> and <code>x</code><sub>0</sub>&nbsp;we will require continuality of <img src="/ta/image045.gif" width=17 height=23 border=0 align="absmiddle"/>&nbsp;and its derived function <img src="/ta/image046.gif" width=17 height=23 border=0 align="absmiddle"/>, this gives us two equations with three unknowns:</p>
<table width="100%" border="0" cellspacing="0" cellpadding="0" class=".TableHidden">
<tr>
<td width="90%" align="center"><img border=0 width=115 height=53 src="/ta/image047.gif"/>&nbsp;</td>
<td width="10%" align="right"><a name=e19><span class=FormulaNum style='font-size:12.0pt'>(20)</span></a></td>
</tr>
</table>
<p class=MsoNormal style='margin-top:12.0pt;page-break-after:avoid'>Solving <span class=FormulaRef>(20)</span> for <code>a</code>&nbsp;and <code>x</code><sub>0</sub> we get them expressed via <code>k</code>:</p>
<table width="100%" border="0" cellspacing="0" cellpadding="0" class=".TableHidden">
<tr>
<td width="90%" align="center"><img border=0 width=123 height=99 src="/ta/image048.gif"/>&nbsp;</td>
<td width="10%" align="right"><span class=FormulaNum style='font-size:12.0pt'>(21)</span></td>
</tr>
</table>
<p>Thereby, <sub><img src="/ta/image045.gif" width=17 height=23 border=0 align="absmiddle"/></sub>&nbsp;depends on a single constant <span class=Formula>k</span>, which is then wiggled around to find a value giving lowest RMS deviation <img src="/ta/image049.gif" width=99 height=25 border=0 align="absmiddle"/>. Table 1 lists selected values for few most common nominal temperatures <span class=Formula>T<sub>N</sub></span>, Figure 5 illustrates this dependency, and Figure 6 shows modeled curves and values, approximated with <span class=FormulaRef>(20)</span>.</p>
<p class=MsoCaption align=center style='text-align:center;page-break-after: avoid'><a name="_Ref164336487">Table 1</a>. <span class=Formula>k</span> values for some <span class=Formula></span><span style='font-weight:normal'>T<sub>N</sub></span></p>
<div align=center>
<table border=1 cellspacing=0 cellpadding=0 style='border-collapse:collapse;border:none;padding:1pt 1.5pt 1pt 1.5pt'>
<tr style='height:4.0pt'>
<td width=50 valign=top style='width:37.5pt;border:solid windowtext 1.0pt; padding:1pt 1.5pt 1pt 1.5pt;height:4.0pt'>
<p class=MsoNormal align=center style='text-align:center;text-autospace:none'><span style='font-family:"Courier New";color:black'>T<sub>N</sub></span></p>
</td>
<td width=60 valign=top style='width:45.0pt;border:solid windowtext 1.0pt; border-left:none;padding:1pt 1.5pt 1pt 1.5pt;height:4.0pt'>
<p class=MsoNormal align=center style='text-align:center;text-autospace:none'><span style='font-family:"Courier New";color:black'>k</span></p>
</td>
</tr>
<tr style='height:4.0pt'>
<td width=50 valign=top style='width:37.5pt;border:solid windowtext 1.0pt; border-top:none;padding:1pt 1.5pt 1pt 1.5pt;height:4.0pt'>
<p class=MsoNormal align=right style='text-align:right;text-autospace:none'><span style='color:black'>2800</span></p>
</td>
<td width=60 valign=top style='width:45.0pt;border-top:none;border-left:none; border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt; padding:1pt 1.5pt 1pt 1.5pt;height:4.0pt'>
<p class=MsoNormal align=right style='text-align:right;text-autospace:none'><span style='color:black'>1.067</span></p>
</td>
</tr>
<tr style='height:3.6pt'>
<td width=50 valign=top style='width:37.5pt;border:solid windowtext 1.0pt; border-top:none;padding:1pt 1.5pt 1pt 1.5pt;height:3.6pt'>
<p class=MsoNormal align=right style='text-align:right;text-autospace:none'><span style='color:black'>2900</span></p>
</td>
<td width=60 valign=top style='width:45.0pt;border-top:none;border-left:none; border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt; padding:1pt 1.5pt 1pt 1.5pt;height:3.6pt'>
<p class=MsoNormal align=right style='text-align:right;text-autospace:none'><span style='color:black'>1.054</span></p>
</td>
</tr>
<tr style='height:3.4pt'>
<td width=50 valign=top style='width:37.5pt;border:solid windowtext 1.0pt; border-top:none;padding:1pt 1.5pt 1pt 1.5pt;height:3.4pt'>
<p class=MsoNormal align=right style='text-align:right;text-autospace:none'><span style='color:black'>3000</span></p>
</td>
<td width=60 valign=top style='width:45.0pt;border-top:none;border-left:none; border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt; padding:1pt 1.5pt 1pt 1.5pt;height:3.4pt'>
<p class=MsoNormal align=right style='text-align:right;text-autospace:none'><span style='color:black'>1.043</span></p>
</td>
</tr>
<tr style='height:3.4pt'>
<td width=50 valign=top style='width:37.5pt;border:solid windowtext 1.0pt; border-top:none;padding:1pt 1.5pt 1pt 1.5pt;height:3.4pt'>
<p class=MsoNormal align=right style='text-align:right;text-autospace:none'><span style='color:black'>3100</span></p>
</td>
<td width=60 valign=top style='width:45.0pt;border-top:none;border-left:none; border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt; padding:1pt 1.5pt 1pt 1.5pt;height:3.4pt'>
<p class=MsoNormal align=right style='text-align:right;text-autospace:none'><span style='color:black'>1.034</span></p>
</td>
</tr>
</table>
</div>
<p class=MsoNormal align=center style='text-align:center;page-break-after:avoid'><img border=0 width=233 height=218 src="/ta/image050.gif"/></p>
<p class=MsoCaption align=center style='text-align:center'><a name="_Ref236117574">Figure 5</a>. <span style='font-family: "Courier New";font-weight:normal'>k</span> variations over <span class=Formula></span><span style='font-weight:normal'>T<sub>N</sub></span></p>
<p class=MsoNormal align=center style='text-align:center;page-break-after:avoid'><img border=0 width=366 height=304 src="/ta/image051.gif"/></p>
<p class=MsoCaption align=center style='text-align:center'><a name="_Ref164337059">Figure 6</a>. Modeled curves and approximated values (marks)</p>
<p>Since designer of a dimmer may not exactly know nominal temperature of the dimmed lamp, <code>k</code>can be selected for an average nominal temperature. Suggested value <code>k=1.05</code> gives &plusmn;2% error (against the model) for <span class=Formula>T<sub>N</sub></span> in range 2800-3100 &deg;K. For this <code>k</code>, equation <span class=FormulaRef>(20)</span> becomes practically concrete:</p>
<table width="100%" border="0" cellspacing="0" cellpadding="0" class=".TableHidden">
<tr>
<td width="90%" align="center"><img border=0 width=257 height=51 src="/ta/image052.gif"/>&nbsp;</td>
<td width="10%" align="right"><a name=e21><span class=FormulaNum style='font-size:12.0pt'>(22)</span></a></td>
</tr>
</table>
<p></p>
<h1 class="Heading1">Sine Wave Dimmer</h1>
<p>A sine wave dimmer implemented with pulse-width modulation controls applied voltage with a cycle duty, which we will denote as control function <span class=Formula></span><span style='font-style:normal'>&#958;<sub>t</sub></span>. Modulation frequency is usually chosen much higher than mains frequency. Therefore, RMS of output voltage is proportional to cycle duty, and control function <span class=Formula></span><span style='font-style:normal'>&#958;<sub>U</sub></span> as simple as:</p>
<table width="100%" border="0" cellspacing="0" cellpadding="0" class=".TableHidden">
<tr>
<td width="90%" align="center"><img border=0 width=123 height=23 src="/ta/image053.gif"/>&nbsp;</td>
<td width="10%" align="right"><a name=e22><span class=FormulaNum style='font-size:12.0pt'>(23)</span></a></td>
</tr>
</table>
<p class=MsoNormal style='margin-top:12.0pt'>To make <span class=Formula></span><span style='font-style:normal'>&#958;<sub>L</sub>(p)</span>, linear on parameter <span class=Formula></span><span style='font-style:normal'>p</span>, function <span class=Formula></span><span style='font-style:normal'>&#958;<sub>t</sub>(p)</span><span class=Formula></span><span style='font-family:"Trebuchet MS"'> should be defined as the following:</span></p>
<table width="100%" border="0" cellspacing="0" cellpadding="0" class=".TableHidden">
<tr>
<td width="90%" align="center"><img border=0 width=501 height=44 src="/ta/image054.gif"/>&nbsp;</td>
<td width="10%" align="right"><a name="e23_1"><span class=FormulaNum style='font-size:12.0pt'>(24)</span></a></td>
</tr>
</table>
<p>Applying <span class=FormulaNum style='font-size:12.0pt'>(24)</span> to equation <span class=FormulaNum style='font-size:12.0pt'>(22)</span> we get </p>
<table width="100%" border="0" cellspacing="0" cellpadding="0" class=".TableHidden">
<tr>
<td width="90%" align="center"><img border=0 width=259 height=53 src="/ta/image055.gif"/>&nbsp;</td>
<td width="10%" align="right"><span class=FormulaNum style='font-size:12.0pt'>(25)</span></td>
</tr>
</table>
<p></p>
<h1 class="Heading1">Phase Control Dimmer</h1>
<p>When implementing an AC dimmer based on phase control technique, one needs to tabulate cycle duty values <code>t<sub>i</sub></code> as a function of desired luminance level <code>p<sub>i</sub></code>.&nbsp;<br />
Following the same approach, we introduce control function <span class=Formula></span><span style='font-style:normal'>&#958;<sub>t</sub></span>:</p>
<table width="100%" border="0" cellspacing="0" cellpadding="0" class=".TableHidden">
<tr>
<td width="90%" align="center"><img border=0 width=117 height=45 src="/ta/image056.gif"/>&nbsp;</td>
<td width="10%" align="right"><span class=FormulaNum style='font-size:12.0pt'>(26)</span></td>
</tr>
</table>
<p>where <i><code>t</code></i> is cycle duty (time when the switch is on) and <i><code>t<sub>M</sub></code></i> is the mains half period, and <i><code>f</code></i>&nbsp;is the mains frequency. Average power <span class=Formula><sub><img border=0 width=15 height=16 src="/ta/image057.gif"/></sub></span>&nbsp;applied to the lamp, can be evaluated as the following:</p>
<table width="100%" border="0" cellspacing="0" cellpadding="0" class=".TableHidden">
<tr>
<td width="90%" align="center"><img border=0 width=360 height=51 src="/ta/image058.gif"/>&nbsp;</td>
<td width="10%" align="right"><a name=e23><span class=FormulaNum style='font-size:12.0pt'>(27)</span></a></td>
</tr>
</table>
<p>where <i><code>U<sub>A</sub></code></i> is voltage amplitude. Integrating <span class=FormulaRef>(27)</span> we can define <span class=Formula></span><span style='font-style:normal'>&#958;<sub>P</sub></span> as the following</p>
<table width="100%" border="0" cellspacing="0" cellpadding="0" class=".TableHidden">
<tr>
<td width="90%" align="center"><img border=0 width=321 height=48 src="/ta/image059.gif"/>&nbsp;</td>
<td width="10%" align="right"><a name=e24><span class=FormulaNum style='font-size:12.0pt'>(28)</span></a></td>
</tr>
</table>
<p class=MsoNormal style='margin-top:12.0pt'>Considering that <span class=Formula></span><span style='font-style:normal'><img src="/ta/image060.gif" width=48 height=25 border=0 align="absmiddle"/></span>, and substituting <span class=FormulaRef>(28)</span> to <span class=FormulaRef>(22)</span> we may estimate <img src="/ta/image061.gif" width=40 height=24 border=0 align="absmiddle"/>. </p>
<p class=MsoNormal align=center style='text-align:center;page-break-after:avoid'><img border=0 width=438 height=381 src="/ta/image062.gif"/></p>
<p class=MsoCaption align=center style='text-align:center'>Figure 7. Dimmer control functions <span class=Formula></span><span style='font-weight:normal'>&#958;<sub>L</sub></span> and <span class=Formula></span><span style='font-weight:normal'>&#958;<sub>U</sub></span></p>
<p>Applying approach used in <span class=FormulaRef>(24)</span> function <span class=Formula></span><span style='font-style:normal'>&#958;<sub>t</sub>(p)</span> is defined as following:</p>
<table width="100%" border="0" cellspacing="0" cellpadding="0" class=".TableHidden">
<tr>
<td width="90%" align="center"><img border=0 width=291 height=25 src="/ta/image063.gif"/>&nbsp;</td>
<td width="10%" align="right"><span class=FormulaNum style='font-size:12.0pt'>(29)</span></td>
</tr>
</table>
<p>Although, reverse function of <span class=FormulaRef>(28)</span> is not solvable analytically, it can be solved numerically.</p>
<p></p>
<h1 class="Heading1">Conclusions</h1>
<p>As a result of numerical modeling, the following approximation functions are suggested:</p>
<ul>
<li>Estimation of produced luminous flux over the voltage:</li>
</ul>
<p style='text-indent:36.0pt'><code>L = L0 * ((U/U0 &lt; 0.575) ? 1.369 * (U/U0) ^ 4 : (1.05 * (U/U0) ^ 3 - 0.05);</code></p>
<ul>
<li>Tabulation of cycle duty over the control parameter p</li>
</ul>
<p style='text-indent:36.0pt'><code>t = (p &lt; 0.1496) ? (0.925 * (p) ^ -4) : (0.984 * (p + 0.05) ^ -3);</code></p>
<p></p>
<h1 class="Heading1">References</h1>
<p class=MsoNormal align=left style='margin-left:28.0pt;text-align:left; text-indent:-28.0pt'><a name="ref_Agraval_1996"></a>Agraval D.C., Leff H.S., Monon V.J. (1996)<br />
&quot;Efficiency and efficacy of incandescent lamps&quot;<br />
<i>American Journal of Physics</i>, May 1996, Volume 64, Issue 5, pp. 649-654<br />
<a href="http://scitation.aip.org/getabs/servlet/GetabsServlet?prog=normal&amp;id=AJPIAS000064000005000649000001&amp;idtype=cvips&amp;gifs=yes">http://scitation.aip.org/getabs/servlet/GetabsServlet?prog=normal&amp;id=AJPIAS000064000005000649000001&amp;idtype=cvips&amp;gifs=yes</a></p>
<p class=MsoNormal align=left style='margin-left:28.0pt;text-align:left; text-indent:-28.0pt'><a name="ref_Harang_2003"></a>Harang O., Kosch M. J. (2003) &quot;Absolute Optical Calibration Using a Simple Tungsten<br />
Bulb&quot;<br />
<i>Sodankyl&auml; Geophysical Observatory Publications</i>, 2003, pp. 92:121-123<br />
<a href="http://spaceweb.oulu.fi/28AM/proc_papers/27_harang_et_al_calibration_with_tungsten_bulb.pdf">http://spaceweb.oulu.fi/28AM/proc_papers/27_harang_et_al_calibration_with_tungsten_bulb.pdf</a></p>
<p class=MsoNormal align=left style='margin-left:28.0pt;text-align:left; text-indent:-28.0pt'><a name="ref_Larrabee_1957"></a>Larrabee R.D. (1957) &quot;The spectral emissivity and optical properties of tungsten&quot;<br /> <br />
  Research Laboratory Of Electronics, Massachusetts Institute of Technology <br />
<a href="http://dspace.mit.edu/bitstream/1721.1/4755/1/RLE-TR-328-04734719.pdf">http://dspace.mit.edu/bitstream/1721.1/4755/1/RLE-TR-328-04734719.pdf</a></p>
]]></content:encoded>
			<wfw:commentRss>http://hutorny.in.ua/research/theoretical-aspects-of-dimming-an-incandescent-lamp/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Customizing ErWin templates for PostgreSQL</title>
		<link>http://hutorny.in.ua/misc/customizing-erwin-templates-for-postgresql</link>
		<comments>http://hutorny.in.ua/misc/customizing-erwin-templates-for-postgresql#comments</comments>
		<pubDate>Wed, 22 Jul 2009 16:20:06 +0000</pubDate>
		<dc:creator>Eugene</dc:creator>
				<category><![CDATA[Misc]]></category>

		<guid isPermaLink="false">http://hutorny.in.ua/misc/customizing-erwin-templates-for-postgresql</guid>
		<description><![CDATA[ErWin 7.2 does not provide  support for PostgreSQL, indeed with few tricks it still can be used to model  database and generate valid SQL code.
(Note: In ErWin 7.3 templates  look very different from 7.2, but nevertheless, I believe, similar approach  still can be applied).
Trick 1. Use Oracle 10.x as the target [...]]]></description>
			<content:encoded><![CDATA[<p>ErWin 7.2 does not provide  support for PostgreSQL, indeed with few tricks it still can be used to model  database and generate valid SQL code.</p>
<p><span id="more-99"></span>(Note: <em>In ErWin 7.3 templates  look very different from 7.2, but nevertheless, I believe, similar approach  still can be applied</em>).</p>
<p><strong>Trick 1. Use Oracle 10.x as the target DBMS</strong></p>
<p>PostgreSQL has common  ideology with Oracle and, in my opinion, is the best choice for PostgreSQL needs.</p>
<p><strong>Trick 2. Fix syntax differences</strong><br />
I have encoundered two syntax  differences &#8211; in the order designator in the column specifier of <code>CREATE INDEX</code> statement and extra parenthesis in <code>ALTER TABLE ADD CONSTRAINT</code></p>
<p>Following samples illustrate what causes PostgreSQL to fail with generated code:</p>
<p><code>CREATE INDEX Publisher_xIF1 ON Publisher (PublisherID <strong><del>ASC</del></strong>);</code></p>
<p><code>ALTER TABLE Publisher<br />
ADD <strong><del>(</del></strong>CONSTRAINT Publisher_fObject FOREIGN KEY (ObjectID) REFERENCES Object(ObjectID) ON DELETE CASCADE<strong><del>)</del></strong>;</code></p>
<p>This can be fixed by altering ErWin FE template as the following:</p>
<p>2.1. Copy and rename <code>Oracle.erwin_fe_template</code> to <code>Postgre.erwin_fe_template</code> and then open it in a text editor.</p>
<table width="100%" cellspacing="0" cellpadding="0" border="0">
<tr>
<td>
<p>2.2. Find<br />
		<code>SPItemBegin = KeyGroupMembers</code></p>
<p>2.3. Below that find and remove line containing <code>[" " PropertyValueX("Key Group Sort  Order")]</code></p>
</td>
<td valign="top" style="width: 130px"><a title="Key Group Sort Order" class="imagelink" href="http://hutorny.in.ua/wp-content/uploads/2009/07/postgress_fe1.PNG" rel="thumbnail"><img alt="Key Group Sort Order" id="image100" src="http://hutorny.in.ua/wp-content/uploads/2009/07/postgress_fe1.thumbnail.PNG" /></a></td>
</tr>
<tr>
<td>
<p>2.4. Find<code>"ADD "  "("  IsNotNullX(ExecuteX("FKConstraint"),"") ")"</code></p>
<p>2.5. Remove <code>"("  ")"</code>, so it looks like the following:<code>"ADD "  IsNotNullX(ExecuteX("FKConstraint"),"")</code></p>
<p>2.6. Switch you project to  use this template<br />
(Tools>Forward  Engineer>Scema Generation; Database template &#8211; Browse; select  Postgre.erwin_fe_template)</p>
<p>These two tricks are  essential to produce valid SQL code from an ErWin model that contain  no Oracle specific features, like table partitions, logging, validation, etc. If you already have an Oracle model which you prefer to keep intact and still be able to generate SQL for Postgress, you will need to void all parts of FE template responsible for Oracle specific features.</p>
</td>
<td valign="top"><a class="imagelink" title="Add constraint" href="http://hutorny.in.ua/wp-content/uploads/2009/07/postgress_fe2.PNG" rel="thumbnail"><img id="image101" alt="Add constraint" src="http://hutorny.in.ua/wp-content/uploads/2009/07/postgress_fe2.thumbnail.PNG" /></a></td>
</tr>
<tr>
<td>
<p><strong>Trick 3. Implement use of <code>INHERITS</code> for subtype relationships</strong><br />
This part is optional and  necessary if you really need to use table inheritance.</p>
<p>3.1. Find first occurrence of <code>[ExecuteX("EndOfStatementX")]</code> after <code>SPItemBegin = Create Entity</code></p>
</td>
<td></td>
</tr>
<tr>
<td>
<p>3.2. Add <code>[ExecuteX("Extra  Properties")]</code> before <code>[ExecuteX("EndOfStatementX")]</code></p>
<p><code>[ExecuteX("Table  Properties")]<br />
<ins>[ExecuteX("Extra Properties")]</ins><br />
[ExecuteX("EndOfStatementX")]<br />
</code></p>
</td>
<td valign="top"><a class="imagelink" title="Extra Properties" href="http://hutorny.in.ua/wp-content/uploads/2009/07/postgress_fe3.PNG" rel="thumbnail"><img id="image102" alt="Extra Properties" src="http://hutorny.in.ua/wp-content/uploads/2009/07/postgress_fe3.thumbnail.PNG" /></a></td>
</tr>
<tr>
<td>
<p>3.3. At the end of the file add</p>
</td>
<td></td>
</tr>
<tr>
<td>
<pre>SPItemBegin = Extra Properties
  10000:
  {#
  ForEachVectorReferenceX("Child Relations Ref")
  {
    [ IsPropertyEqual("Type","9")
        " INHERITS("

          [
              PushReferenceX("Parent Entity Ref")
              [ [OwnerX"."]PhysicalNameX ]
              PopX
          ]
       ")"
     ]
   }
   #}
   SPItemEnd
</pre>
</td>
<td valign="top"><a class="imagelink" title="Extra Properties Implemetation" href="http://hutorny.in.ua/wp-content/uploads/2009/07/postgress_fe4.PNG" rel="thumbnail"><img id="image103" alt="Extra Properties Implemetation" src="http://hutorny.in.ua/wp-content/uploads/2009/07/postgress_fe4.thumbnail.PNG" /></a></td>
</tr>
</table>
]]></content:encoded>
			<wfw:commentRss>http://hutorny.in.ua/misc/customizing-erwin-templates-for-postgresql/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Simplescope v1.1 released</title>
		<link>http://hutorny.in.ua/projects/w32/sisan/simplescope-v11-released</link>
		<comments>http://hutorny.in.ua/projects/w32/sisan/simplescope-v11-released#comments</comments>
		<pubDate>Wed, 14 Mar 2007 09:08:09 +0000</pubDate>
		<dc:creator>Eugene</dc:creator>
				<category><![CDATA[SISAN]]></category>

		<guid isPermaLink="false">http://hutorny.in.ua/projects/w32/sisan/simplescope-v11-released</guid>
		<description><![CDATA[This is a maintenance release of the product that includes the following fixes:
1. SISAN v 1.1
&#160;&#160;1.1.&#160;Added SISAM88 hardware schematic
&#160;&#160;1.2.&#160;Fixed TX/RX typo on SISAM690 schematic
&#160;&#160;1.3.&#160;Fixed issue with beam pattern affecting ruler pattern
2. SISAM1 v 1.1
&#160;&#160;2.1.&#160;Fixed diagnostic failure, which made product unusable if high baudrate cannot be set
&#160;&#160;2.2.&#160;Fixed issue with BREAK is not handled properly
Download Simplescope v1.1.

Read [...]]]></description>
			<content:encoded><![CDATA[<p>This is a maintenance release of the product that includes the following fixes:<br />
<strong>1. SISAN v 1.1</strong><br />
&nbsp;&nbsp;1.1.&nbsp;Added SISAM88 hardware schematic<br />
&nbsp;&nbsp;1.2.&nbsp;Fixed TX/RX typo on SISAM690 schematic<br />
&nbsp;&nbsp;1.3.&nbsp;Fixed issue with beam pattern affecting ruler pattern<br />
<strong>2. SISAM1 v 1.1</strong><br />
&nbsp;&nbsp;2.1.&nbsp;Fixed diagnostic failure, which made product unusable if high baudrate cannot be set<br />
&nbsp;&nbsp;2.2.&nbsp;Fixed issue with BREAK is not handled properly<br />
<a id=p97 href="http://hutorny.in.ua/wp-content/uploads/2007/03/Simplescope.v1.1.zip">Download Simplescope v1.1.</a></p>
<p><span id="more-96"></span><br />
Read more about <a href="http://hutorny.in.ua/projects/pic/sisam/sisam-overview">SISAM &#8211; SImple SAMpler</a> and <a href="http://hutorny.in.ua/projects/w32/sisan-overview">SISAN &#8211; SImlpe Signal Analyse</a></p>
]]></content:encoded>
			<wfw:commentRss>http://hutorny.in.ua/projects/w32/sisan/simplescope-v11-released/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MIHA675 &#8211; Multi Input Hall Automaton</title>
		<link>http://hutorny.in.ua/projects/pic/miha675-multi-input-hall-automaton</link>
		<comments>http://hutorny.in.ua/projects/pic/miha675-multi-input-hall-automaton#comments</comments>
		<pubDate>Thu, 07 Dec 2006 15:59:25 +0000</pubDate>
		<dc:creator>Eugene</dc:creator>
				<category><![CDATA[PIC]]></category>
		<category><![CDATA[VELOOS]]></category>

		<guid isPermaLink="false">http://hutorny.in.ua/projects/pic/miha675-multi-input-hall-automaton</guid>
		<description><![CDATA[Previous examples illustrated VELOOS  programming aspects. This post provides an example of using object oriented  paradigm for designing VELOOS application. Unlike the previous examples which  were purely programming exercises, this example is dedicated to a utilitarian  home appliance application and provides a &#34;reference design&#34; for  VELOOS applications.

Example3 &#8211; Designing MIHA [...]]]></description>
			<content:encoded><![CDATA[<p>Previous examples illustrated VELOOS  programming aspects. This post provides an example of using object oriented  paradigm for designing VELOOS application. Unlike the previous examples which  were purely programming exercises, this example is dedicated to a utilitarian  home appliance application and provides a &quot;reference design&quot; for  VELOOS applications.</p>
<p><span id="more-87"></span></p>
<h2>Example3 &ndash; Designing MIHA &ndash;  Multi Input Hall Automaton</h2>
<p></p>
<h3>Introduction</h3>
<p>There are two common approaches for light  switching in halls and staircases &ndash; off-timers and intermediate switching  schemes (please excuse me if terminology is wrong). Off timers turn light on when user pushes a button and turn off when specified time elapsed. Intermediate  switching schemes toggle lights when user toggles any switch (of two). Each  approach has its own advantages and disadvantages, however, both approaches  require special switches, which could be an undesired constraint for interior  design. See, for example, <a href="http://www.o2m8.com/modules.php?name=News&amp;file=article&amp;sid=32">Intermediate lighting switch</a>,&nbsp;<a href="http://www.tlc-direct.co.uk/Manufacturers/Contactum_Distribution/CMD_Controls_3/index.html">Stair case timer</a>,&nbsp;<a href="http://www.amidata.es/componentes-electronicos-es/circuitos-electricos/424356720-STAIRCASE-TIMER.html">Multifunction staircase timer</a></p>
<h3>Requirements (user&#8217;s needs)</h3>
<p>Implement a light-control appliance that:</p>
<ul>
<li>combines off-timer and  intermediate switchers</li>
<li>provides support for at least 3  switches</li>
<li>supports regular light switches  as well as push-buttons</li>
<li>provides settable 0.5-10 min  timer range with a simple user interface for entering value</li>
</ul>
<h3>MIHA Design Description</h3>
<p><u>Key Design Decisions:</u></p>
<ul>
<li>Implement the appliance (named  MIHA) as a VELOOS application running on a PIC microcontroller</li>
<li>Store application  configuration in EEPROM during device programming</li>
<li>Use potentiometer for  specifying timeout</li>
</ul>
<p><u>Architecture</u><br />
  MIHA consists of the following units (see  architecture diagram on Figure 1):</p>
<table border="1" cellspacing="0" cellpadding="0" style="border:solid gray .5pt;border-collapse:collapse;">
<tr>
<td width="196" valign="top" style="border:solid gray .5pt;padding:0cm 4pt 0cm 4pt;">
      Multi-input Switch Debouncer </td>
<td width="463" valign="top" style="border:solid gray .5pt;padding:0cm 4pt 0cm 4pt;">Reads and debounces switches, sends a    message on switch state changing. <br />
      Featuring triple port read with majority    logic and software implementation of RC-integration and Schmidt trigger.</td>
</tr>
<tr>
<td width="196" valign="top" style="border:solid gray .5pt;padding:0cm 4pt 0cm 4pt;">Hall Light Automaton</td>
<td width="463" valign="top" style="border:solid gray .5pt;padding:0cm 4pt 0cm 4pt;">Implements automaton logic, provides    supports for switches/push-buttons, send &#8216;alt&#8217; message to actuator and &#8216;off&#8217;    message to the delay block</td>
</tr>
<tr>
<td width="196" valign="top" style="border:solid gray .5pt;padding:0cm 4pt 0cm 4pt;">Delay Time Input</td>
<td width="463" valign="top" style="border:solid gray .5pt;padding:0cm 4pt 0cm 4pt;">Reads potentiometer value and sends the    value read to the delay block<br />
      Featuring support for multiple channels.    ADC access is arbitrated via time quantization</td>
</tr>
<tr>
<td width="196" valign="top" style="border:solid gray .5pt;padding:0cm 4pt 0cm 4pt;">Message Delay Block</td>
<td width="463" valign="top" style="border:solid gray .5pt;padding:0cm 4pt 0cm 4pt;">Provides delay for the &#8216;off&#8217; message.</td>
</tr>
<tr>
<td width="196" valign="top" style="border:solid gray .5pt;padding:0cm 4pt 0cm 4pt;">Discrete Actuator</td>
<td width="463" valign="top" style="border:solid gray .5pt;padding:0cm 4pt 0cm 4pt;">Turns on or off an output pin depending    on the message received</td>
</tr>
</table>
<table>
<tr>
<td rowspan="2">
<p><u>Mapping Architecture to Implementation.</u><br />
  Mapping from architectural units to  implementation units is straightforward &ndash; all MIHA units are directly mapped to  operating system objects, inter-unit communications are mapped to messaging. <br />
  All MIHA objects are configurable with  EEPROM data. To make design flexible, object configuration embeds acceptor  handle. The latter two decisions establish a generality which is captured as  two abstract classes:<br />
  PDO &ndash; a configurable Process Data Object<br />
  PDD &ndash; a dynamically bound PDO<br />
  (See class diagram on Figure 2)</p>
</td>
<td rowspan="2">&nbsp;</td>
<td height=57><a href="http://hutorny.in.ua/wp-content/uploads/2006/12/MIHA-Architecture.png" target=_blank rel="thumbnail"><img src="http://hutorny.in.ua/wp-content/uploads/2006/12/MIHA-Architecture.thumbnail.png" alt="MIHA Architecture" height=57 border="0" id="MIHAArchitecture"/></a><br />Figure 1.</td>
</tr>
<tr>
<td><a href="http://hutorny.in.ua/wp-content/uploads/2006/12/MIHA-ClassDiagram.png" target=_blank rel="thumbnail"><img src="http://hutorny.in.ua/wp-content/uploads/2006/12/MIHA-ClassDiagram.thumbnail.png" alt="MIHA Class Diagram" name="image89" height=80 border="0" id="image89" /></a><br />Figure 2.</td>
</tr>
</table>
<h3>Moduling</h3>
<p>Major advantage provided by VELOOS is  ability to design and implement loosely coupled objects. The following practice  can be applied to get full advantage of loose coupling: </p>
<ul>
<li>A unit should be made up of (at  least) two files: (1) .inc containing interface and (2) .asm &ndash; implementation</li>
<li>Each unit should implement one  class or a hierarchy of closely related classes.</li>
<li>A unit should not instantiate  objects of reenterable or configurable classes. Instead it should publish class  name in the interface.</li>
<li>A unit may instantiate object  of a non-reenterable class. In this case it should publish object name and  encapsulate class name.</li>
</ul>
<h3>Sharing RAM among objects</h3>
<p>Decoupling objects via messaging mechanism  provides a very explicit and straightforward watershed for scoping variables &ndash; everything  that should survive between two messages is a part of object state and should  be allocated in udata section, everything that may be discarded after handling  the message is a temporary variable and can be allocated in udata_ovr section.</p>
<h3>Using Timer for Resource Access Arbitration</h3>
<p>Class Potentiometer Parameter Input (PPI)  implements time-quantified approach for sharing ADC among several instances &ndash; time  is sliced on N quants, each instance may access hardware only if TIME mod N  equals to channel number. To simplify computing TIME mod N, N can be chosen as  power of 2. In this example N = 16.</p>
<table>
<tr>
<td rowspan="4">
<h3>Multi-input Debouncer</h3>
<p>On timer event Debouncer  polls the port three times in a row and applies majority logic to determine current  switch state. This approach eliminates sporadic spikes than may be present in a  noisy environment. For each assigned pin it maintains a counter. This counter  is incremented whenever pin level is high and decremented if low. Counter is  maintained in range 0..16, e.g. when it reaches the boundary it is not changed.  When counter reaches upper threshold (12) logical output state is changed to 1  and to 0 when it reaches lower threshold. This is a software model of an RC-integration  connected to a Schmidt trigger.<br />Few samples of  switch bouncing are shown on figures on right. The switches are regular light switches  manufactured by VIKO.</p>
<h3>Hardware Schematic</h3>
<p>MIHA schematic is shown on Figure 6. Relay, loaded on PIC12, should have actuating current up to 25 mA. Resistors R1-R4 are used for pull-up and can be roughly 1 kOhm. In an environment with strong EMI their can be reduced to avoid pickup.</p>
<h3>Package Content</h3>
<p>The package includes three projects to build this application for three different devices &ndash; PIC12F675, PIC16F690, PIC18F248. It is licensed to public under the <a href="http://www.opensource.org/licenses/osl-3.0.php">Open Software   License<br />
</a><a id=p94 href="http://hutorny.in.ua/wp-content/uploads/2006/12/miha.v.1.0.zip">Download MIHA Sources v.1.0</a></p>
</td>
<td rowspan="4">&nbsp;</td>
<td><a href="http://hutorny.in.ua/wp-content/uploads/2006/12/ON-Bouncing.png" target="_blank" rel="thumbnail"><img src="http://hutorny.in.ua/wp-content/uploads/2006/12/ON-Bouncing.thumbnail.png" alt=ON-Bouncing.png height=39 border="0" id="image91" /></a><br />Figure 3.</td>
</tr>
<tr>
<td><a href="http://hutorny.in.ua/wp-content/uploads/2006/12/OFF-Bouncing.png" target="_blank" rel="thumbnail"><img src="http://hutorny.in.ua/wp-content/uploads/2006/12/OFF-Bouncing.thumbnail.png" alt=OFF-Bouncing.png height=39 border="0" id="image92" /></a><br />Figure 4.</td>
</tr>
<tr>
<td><a href="http://hutorny.in.ua/wp-content/uploads/2006/12/Debounced.png" target="_blank" rel="thumbnail"><img src="http://hutorny.in.ua/wp-content/uploads/2006/12/Debounced.thumbnail.png" alt=Debounced.png height=47 border="0" id="image93" /></a><br />Figure 5.</td>
</tr>
<tr>
<td><a href="http://hutorny.in.ua/wp-content/uploads/2006/12/MIHA675.png" target="_blank" rel="thumbnail"><img src="http://hutorny.in.ua/wp-content/uploads/2006/12/MIHA675.thumbnail.png" alt="MIHA Hardware Schematics" height=92 border="0" id="image90" /></a><br />Figure 6.</td>
</tr>
</table>
]]></content:encoded>
			<wfw:commentRss>http://hutorny.in.ua/projects/pic/miha675-multi-input-hall-automaton/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>VELOOS Example 3</title>
		<link>http://hutorny.in.ua/projects/pic/veloos/veloos-example-3</link>
		<comments>http://hutorny.in.ua/projects/pic/veloos/veloos-example-3#comments</comments>
		<pubDate>Wed, 06 Dec 2006 21:38:00 +0000</pubDate>
		<dc:creator>Eugene</dc:creator>
				<category><![CDATA[VELOOS]]></category>

		<guid isPermaLink="false">http://hutorny.in.ua/projects/pic/veloos/veloos-example-3</guid>
		<description><![CDATA[This example for PIC12F675 implements set of &#8220;actuators&#8221; and &#8220;generators&#8221; controlled via USART. Actuators produce one 300 ms pulse when it receives command &#8216;ON&#8217; and three 100 ms pulses delimited with 100 ms spaces (pauses) on command &#8216;OFF&#8217;. Generators, when turned on, produce pulses and spaces of the specified duration (1..255). 

Actuators and Generators are [...]]]></description>
			<content:encoded><![CDATA[<p>This example for PIC12F675 implements set of &#8220;actuators&#8221; and &#8220;generators&#8221; controlled via USART. Actuators produce one 300 ms pulse when it receives command &#8216;ON&#8217; and three 100 ms pulses delimited with 100 ms spaces (pauses) on command &#8216;OFF&#8217;. Generators, when turned on, produce pulses and spaces of the specified duration (1..255). </p>
<p><span id="more-84"></span></p>
<p>Actuators and Generators are implemented as instances of Actuator and Generator classes. Yet another class in this example   protocol driver   parses the incoming via software USART commands and forwards it to a corresponding object. Command format is: <strong>command</strong>[<strong>data</strong>,[<strong>data</strong>]]; COM port settings: 2400, 8bit no parity, 1 stop bits.<br />
USART is implemented in software and uses INT0 and TMR1 interrupts for timing bits.<br />
Command language consist of 8 commands (H..O)</p>
<ul>
<li>H,I,J   control an actuator, </li>
<li>K,L   control a generator, </li>
<li>N   all actuators do OFF, susped all generators</li>
<li>O   all actuators do ON, resume all generators.</li>
</ul>
<p>H,I,J commands accepts &#8216;0&#8242; and &#8216;1&#8242; as a parameter to execute OFF or ON command  respectively. K,L commands should be supplied with pulse and pause duration</p>
<p>For example:</p>
<ul>
<li>H0   Actuator 1 do OFF</li>
<li>LUA   Turn on generator 1 with 85 ms pulse and 65 ms space</li>
</ul>
<p><a id=p86 href="http://hutorny.in.ua/wp-content/uploads/2006/12/Example3.zip">Example 3 Sources</a></p>
<p>Hardware Scematics. Connect loads to GP0,GP1,GP4,GP5 (not shown on the schematic)</p>
<p><img id="image85" alt="Example 3 Hardware Schematics" src="http://hutorny.in.ua/wp-content/uploads/2006/12/Example3.png" /></p>
<p>Simulation Results</p>
<p><img id="image95" alt="Simulation Results" src="http://hutorny.in.ua/wp-content/uploads/2006/12/SIM-Example3.png" /></p>
]]></content:encoded>
			<wfw:commentRss>http://hutorny.in.ua/projects/pic/veloos/veloos-example-3/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>VELOOS 1.0 released</title>
		<link>http://hutorny.in.ua/projects/pic/veloos/veloos-10-released</link>
		<comments>http://hutorny.in.ua/projects/pic/veloos/veloos-10-released#comments</comments>
		<pubDate>Mon, 20 Nov 2006 18:02:45 +0000</pubDate>
		<dc:creator>Eugene</dc:creator>
				<category><![CDATA[VELOOS]]></category>

		<guid isPermaLink="false">http://hutorny.in.ua/projects/pic/veloos/veloos-10-released</guid>
		<description><![CDATA[VELOOS is an object-oriented message-triggered cooperative operating system for 8-bit Microchip microcontrollers licensed to public under the Open Software License
Release 1.0 includes VELOOS kernel and two timer drivers (TMR0 and TMR2 based). It has been tested on the following devices: PIC12F675, PIC16F690, PIC18F248.
Download VELOOS v.1.0

Supporting other 14-bit core and 16-bit core devices
By design, VELOOS allocates [...]]]></description>
			<content:encoded><![CDATA[<p>VELOOS is an object-oriented message-triggered cooperative operating system for 8-bit Microchip microcontrollers licensed to public under the <a href="http://www.opensource.org/licenses/osl-3.0.php">Open Software License</a><br />
Release 1.0 includes VELOOS kernel and two timer drivers (TMR0 and TMR2 based). It has been tested on the following devices: PIC12F675, PIC16F690, PIC18F248.</p>
<p><a id=p83 href="http://hutorny.in.ua/wp-content/uploads/2006/11/veloos_v1_0.zip">Download VELOOS v.1.0</a></p>
<p><span id="more-82"></span></p>
<h3>Supporting other 14-bit core and 16-bit core devices</h3>
<p>By design, VELOOS allocates its message at the end of available banked (e.g. not shared) memory. Unfortunately, standard .inc does not include constants defining memory limits, therefore pic.inc refines &#8220;device model&#8221; and this refinement block has to be provided for each device to be used for a VELOOS application.</p>
<p>
<code><br />
&nbsp;ifdef __16F690<br />
&nbsp;&nbsp;include         "p16f690.inc"<br />
&nbsp;&nbsp;include         "pic16.inc"<br />
&nbsp;&nbsp;_pic&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;= _pic16F690<br />
&nbsp;&nbsp;_pic_maxram&nbsp;&nbsp;&nbsp;&nbsp;= 016Fh       ; with shared bank excluded<br />
&nbsp;&nbsp;_pic_maxrom&nbsp;&nbsp;&nbsp;&nbsp;= 0FFFh<br />
&nbsp;&nbsp;_pic_maxeeprom&nbsp;= 0FFh<br />
&nbsp;endif<br />
</code></p>
<p>With this refinement, VELOOS is expected to work for any 16-bit core devices (PIC18), and any 14-bit core (most of PIC14 and some of PIC12). Perhaps, it may also work on 12-bit core (PIC10 and some of PIC12). However, since there are no interrupts, timer drivers can not be used. Also, these devices have severe memory constraints, which make use of OS unreasonable.</p>
]]></content:encoded>
			<wfw:commentRss>http://hutorny.in.ua/projects/pic/veloos/veloos-10-released/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>VELOOS Example 2</title>
		<link>http://hutorny.in.ua/projects/pic/veloos/veloos-example-2</link>
		<comments>http://hutorny.in.ua/projects/pic/veloos/veloos-example-2#comments</comments>
		<pubDate>Wed, 15 Nov 2006 15:30:06 +0000</pubDate>
		<dc:creator>Eugene</dc:creator>
				<category><![CDATA[VELOOS]]></category>

		<guid isPermaLink="false">http://hutorny.in.ua/projects/pic/veloos/veloos-example-2</guid>
		<description><![CDATA[This post continues series of examples and describes how VELOOS can be used for implementing time-triggered applications.

Example2 &#8211; Heartbeat Driven PDO



Design&#160;idea:
Enhance previous example with a timer and two PDOs processing timer messages. Use EEPROM to keep instance-specific data.


Value:
Gives a simple example of implementing (1) time-triggered PDOs, (2) reenterable classes. Implements a class which may be [...]]]></description>
			<content:encoded><![CDATA[<p>This post continues series of examples and describes how VELOOS can be used for implementing time-triggered applications.</p>
<p><span id="more-78"></span></p>
<h2>Example2 &#8211; Heartbeat Driven PDO</h2>
<p></p>
<table id="Table1" style="BORDER-COLLAPSE: collapse" cellSpacing="2" cellPadding="2" border="0">
<tr>
<td vAlign="top" align="right" width="111"><b>Design&nbsp;idea:</b></td>
<td vAlign="top" width="576">Enhance previous example with a timer and two PDOs processing timer messages. Use EEPROM to keep instance-specific data.</td>
</tr>
<tr>
<td vAlign="top" align="right" width="111"><b>Value:</b></td>
<td vAlign="top" width="576">Gives a simple example of implementing (1) time-triggered PDOs, (2) reenterable classes. Implements a class which may be used for debug purposes to watch system &quot;heartbeat&quot;. </td>
</tr>
</table>
<h3>Design Description</h3>
<p>This sample application implements two PDO each triggering port pin with a certain period: first PDO is on 1 sec period, second &#8211; on 1 ms. Since behavioral pattern of these PDO are the same, they were implemented as instances of the same class.</p>
<h3>Deploying VELOOS Timer Driver</h3>
<p>Timer Driver is a non-reenterable encapsulated PDO with an interrupt handler and internal counters for millisecond and seconds. To deploy a timer driver to VELOOS application, the project should include file vtm0.asm (Timer0 based) or vtm2.asm (Timer2 based). Timer constants are calculated automatically based on <code>_osc_clock</code>. Timer driver configures hardware timer for 1 ms interrupts. When a timer interrupts occurs, Interrupt Handler sends a broadcast message. Timer PDO counts 1ms messages and on every 1000-th broadcasts a 1s message. Both 1 ms and 1 s messages include current time value.</p>
<p>In a pseudo language messages can be declared as the following (acceptor field is not shown):</p>
<table border="1" cellspacing="0" cellpadding="0" style="border-collapse:collapse;border:none;">
<tr>
<td width="358" valign="top" style="border:solid windowtext 1.0pt;padding:0cm 5.4pt 0cm 5.4pt;"><code>struct VTMR_cMsgTimer1ms {&nbsp;<br />&nbsp;    byte&nbsp;&nbsp;&nbsp; msg_id;<br />
&nbsp;    word&nbsp;&nbsp;&nbsp; millisec; }<br /></code></td>
<td width="359" valign="top" style="border:solid windowtext 1.0pt;border-left:none;padding:0cm 5.4pt 0cm 5.4pt;"><code>&nbsp;struct VTMR_cMsgTimer1s {<br />
&nbsp;&nbsp;    byte&nbsp;&nbsp;&nbsp; msg_id;<br />
&nbsp;&nbsp;    word&nbsp;&nbsp;&nbsp; seconds; }</code></td>
</tr>
</table>
<p></p>
<h3>Handling Timer Messages</h3>
<p>Timer messages are regular VELOOS messages.  To handle a timer message, PDO should first recognize the message and then, if necessary, examine time delivered with the message and take appropriate action:</p>
<p><code style="text-align:left">MyHandler&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="COLOR: green">; FSR points to message ID field</span><br />
&nbsp;&nbsp;&nbsp; movlw&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  <b><span style="COLOR: #333399">VTMR_cMsgIDTimer1ms</span></b><br />
&nbsp;&nbsp;&nbsp; xorwf&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  INDF, W&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="COLOR: green">; if message.msg_id &lt;&gt; VTMR_cMsgIDTimer1ms</span><br />
&nbsp;&nbsp;&nbsp; skpz<br />
&nbsp;&nbsp;&nbsp; return&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="COLOR: green">; return</span><br />
&nbsp;&nbsp;&nbsp; incf&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  FSR, F&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="COLOR: green">; make FSR pointing to LSB of message data</span><br />
&nbsp;&nbsp;&nbsp; movf&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  INDF, W<br />
&nbsp;&nbsp;&nbsp; andlw&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  0F0h<br />
&nbsp;&nbsp;&nbsp; xorlw&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  007h&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="COLOR: green">; on 7-th msec of every 16 msec</span><br />
&nbsp;&nbsp;&nbsp; skpnz<br />
&nbsp;&nbsp;&nbsp; return<br />
&nbsp;&nbsp;&nbsp; <span style="COLOR: green">; do something</span><br />
  </code>
</p>
<h3>Targeting Reenterability</h3>
<p>To make a class reenterable, it should not be build-time-bound to any resource. This sample class achieves reenterability by using <i>This</i> as a pointer to EEPROM data with configuration (message ID, port mask) assigned to a particular class instance. In run-time PDO reads data from EEPROM on per need basis (e.g. does not cache in in registers). Since message ID is also stored in EEPROM, message handler first reads message ID from EEPROM and then message is processed:</p>
<p><code style="text-align:left">TmrHandler<br />
&nbsp;&nbsp;&nbsp; movf&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  <b><span style="COLOR: #333399">This</span></b>, W<br />
&nbsp;&nbsp;&nbsp; call&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  &nbsp;EE_read&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="COLOR: green">;  W = EEPROM[This]; //(== msgid)</span><br />
&nbsp;&nbsp;&nbsp; xorwf&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  INDF, W<br />
&nbsp;&nbsp;&nbsp; skpz<br />
&nbsp;&nbsp;&nbsp; return<br /></code></p>
<p>With this design, class should be properly instantiated, e.g. object data should point to the configuration location in EEPROM. This can be achieved with use of a label, placed in EEPROM section:</p>
<p><code style="text-align:left">DEEPROM code<br />
On1mSecData&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="COLOR: green">; Configuration name</span><br />
&nbsp;&nbsp; de&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  <b><span style="COLOR: #333399">VTMR_cMsgIDTimer1ms</span></b>, .1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="COLOR: green">; Configuration data</span><br />
<b><span style="COLOR: #333399">VOS_Objects</span></b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="COLOR: green">; Object registry begins</span><br />
On1mSec&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="COLOR: green">; Object name (not necessary for this example)</span><br />
&nbsp;&nbsp; <b><span style="COLOR: #333399">VOS_mPersistentObject</span></b> MyTimer, On1mSecData <span style="COLOR: green">; Instance on MyTimer constructed with</span><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="COLOR: green">;object data pointing  to configuration</span></code></p>
<h3>Building the project</h3>
<p>All classes and objects for this example (except Timer) are declared, implemented and instantiated in one file: main.asm. Although this is not a recommended practice, this example, for simplicity, gives it this way. Moduling aspects will be discussed in a subsequent example.</p>
<p>A package with sources for this example can be downloaded <a href="http://hutorny.in.ua/wp-content/uploads/2006/11/VELOOS-Example2.zip">on this link</a>. It includes the following files:</p>
<table id="Table3" style="BORDER-RIGHT: medium none; BORDER-TOP: medium none; BORDER-LEFT: medium none; BORDER-BOTTOM: medium none; BORDER-COLLAPSE: collapse" cellSpacing="0" cellPadding="0" border="1">
<tr>
<td style="BORDER-RIGHT: windowtext 1pt solid; BORDER-TOP: windowtext 1pt solid; BORDER-LEFT: windowtext 1pt solid; BORDER-BOTTOM: windowtext 1pt solid" vAlign="top" width="177"><code>Example2.mcp</code></td>
<td style="BORDER-RIGHT: windowtext 1pt solid; BORDER-TOP: windowtext 1pt solid; BORDER-LEFT: medium none; BORDER-BOTTOM: windowtext 1pt solid" vAlign="top" width="540">MP LAB project file</td>
</tr>
<tr>
<td style="BORDER-RIGHT: windowtext 1pt solid; BORDER-TOP: medium none; BORDER-LEFT: windowtext 1pt solid; BORDER-BOTTOM: windowtext 1pt solid" vAlign="top" width="177"><code>main.asm</code></td>
<td style="BORDER-RIGHT: windowtext 1pt solid; BORDER-TOP: medium none; BORDER-LEFT: medium none; BORDER-BOTTOM: windowtext 1pt solid" vAlign="top" width="540">Example2 application sources</td>
</tr>
<tr>
<td style="BORDER-RIGHT: windowtext 1pt solid; BORDER-TOP: medium none; BORDER-LEFT: windowtext 1pt solid; BORDER-BOTTOM: windowtext 1pt solid" vAlign="top" width="177"><code>pic.inc</code></td>
<td style="BORDER-RIGHT: windowtext 1pt solid; BORDER-TOP: medium none; BORDER-LEFT: medium none; BORDER-BOTTOM: windowtext 1pt solid" vAlign="top" width="540">Processor-specific primitives, macros and includes</td>
</tr>
<tr>
<td style="BORDER-RIGHT: windowtext 1pt solid; BORDER-TOP: medium none; BORDER-LEFT: windowtext 1pt solid; BORDER-BOTTOM: windowtext 1pt solid" vAlign="top" width="177"><code>pic16.inc</code></td>
<td style="BORDER-RIGHT: windowtext 1pt solid; BORDER-TOP: medium none; BORDER-LEFT: medium none; BORDER-BOTTOM: windowtext 1pt solid" vAlign="top" width="540">PIC16/PIC12 specific primitives</td>
</tr>
<tr>
<td style="BORDER-RIGHT: windowtext 1pt solid; BORDER-TOP: medium none; BORDER-LEFT: windowtext 1pt solid; BORDER-BOTTOM: windowtext 1pt solid" vAlign="top" width="177"><code>vos.asm</code></td>
<td style="BORDER-RIGHT: windowtext 1pt solid; BORDER-TOP: medium none; BORDER-LEFT: medium none; BORDER-BOTTOM: windowtext 1pt solid" vAlign="top" width="540">VELOOS kernel</td>
</tr>
<tr>
<td style="BORDER-RIGHT: windowtext 1pt solid; BORDER-TOP: medium none; BORDER-LEFT: windowtext 1pt solid; BORDER-BOTTOM: windowtext 1pt solid" vAlign="top" width="177"><code>vos.inc</code></td>
<td style="BORDER-RIGHT: windowtext 1pt solid; BORDER-TOP: medium none; BORDER-LEFT: medium none; BORDER-BOTTOM: windowtext 1pt solid" vAlign="top" width="540">VELOOS public interface</td>
</tr>
<tr>
<td style="BORDER-RIGHT: windowtext 1pt solid; BORDER-TOP: medium none; BORDER-LEFT: windowtext 1pt solid; BORDER-BOTTOM: windowtext 1pt solid" vAlign="top" width="177"><code>vos_cfg.inc</code></td>
<td style="BORDER-RIGHT: windowtext 1pt solid; BORDER-TOP: medium none; BORDER-LEFT: medium none; BORDER-BOTTOM: windowtext 1pt solid" vAlign="top" width="540">VELOOS configuration file</td>
</tr>
<tr>
<td style="BORDER-RIGHT: windowtext 1pt solid; BORDER-TOP: medium none; BORDER-LEFT: windowtext 1pt solid; BORDER-BOTTOM: windowtext 1pt solid" vAlign="top" width="177"><code>vtm2.inc</code></td>
<td style="BORDER-RIGHT: windowtext 1pt solid; BORDER-TOP: medium none; BORDER-LEFT: medium none; BORDER-BOTTOM: windowtext 1pt solid" vAlign="top" width="540">Timer public interface</td>
</tr>
<tr>
<td style="BORDER-RIGHT: windowtext 1pt solid; BORDER-TOP: medium none; BORDER-LEFT: windowtext 1pt solid; BORDER-BOTTOM: windowtext 1pt solid" vAlign="top" width="177"><code>vtm2_m.inc</code></td>
<td style="BORDER-RIGHT: windowtext 1pt solid; BORDER-TOP: medium none; BORDER-LEFT: medium none; BORDER-BOTTOM: windowtext 1pt solid" vAlign="top" width="540">Timer auxiliary macros</td>
</tr>
<tr>
<td style="BORDER-RIGHT: windowtext 1pt solid; BORDER-TOP: medium none; BORDER-LEFT: windowtext 1pt solid; BORDER-BOTTOM: windowtext 1pt solid" vAlign="top" width="177"><code>vtm2.asm</code></td>
<td style="BORDER-RIGHT: windowtext 1pt solid; BORDER-TOP: medium none; BORDER-LEFT: medium none; BORDER-BOTTOM: windowtext 1pt solid" vAlign="top" width="540">Timer implementation</td>
</tr>
<tr>
<td style="BORDER-RIGHT: windowtext 1pt solid; BORDER-TOP: medium none; BORDER-LEFT: windowtext 1pt solid; BORDER-BOTTOM: windowtext 1pt solid" vAlign="top" width="177"><code>16f690.lkr</code></td>
<td style="BORDER-RIGHT: windowtext 1pt solid; BORDER-TOP: medium none; BORDER-LEFT: medium none; BORDER-BOTTOM: windowtext 1pt solid" vAlign="top" width="540">VELOOS specific linker script</td>
</tr>
</table>
<p><a href="http://hutorny.in.ua/wp-content/uploads/2006/11/VELOOS-Example2.zip">Download sources</a></p>
<table>
<tr>
<td rowspan="2">
<h3>Running the application</h3>
<p>This application was loaded to PIC16F690 on &quot;Low  Pin Count Demo Board&quot; supplied with PICkit&trade; 2. Activity of 1s driven object can be visually monitored with a led. Activities of other objects (1ms  and self-triggering) can be monitored aurally, for example  by connecting a  headset, or with a scope. Signals from RC2 and RC3 were captured with  Simplescope and their traces are shown on Figure 1 and Figure 2. As results  show, in the first run 1 ms period was actually shorter&nbsp; &#8211; 970 us instead of 1000. Therefore, for the  next run internal oscillator has been tuned with -4 value. Traces indicate that  1 ms period varies 1000-1080 ms &ndash; this is an expected effect of message  queuing.</p>
</td>
<td>&nbsp;</td>
<td width=90 align="center"><a target=_blank href="http://hutorny.in.ua/wp-content/uploads/2006/11/Example2-Timing.png" rel="thumbnail"><img src="http://hutorny.in.ua/wp-content/uploads/2006/11/Example2-Timing.thumbnail.png" alt="Timing of sampled signals" name="image80" height=37 border="0" id="image80" /></a><br />
  Figure 1</td>
</tr>
<tr>
<td>&nbsp;</td>
<td align="center"><a target=_blank href="http://hutorny.in.ua/wp-content/uploads/2006/11/Example2-Timing2.png" rel="thumbnail"><img id="image81" height=37 alt="Timing of sampled signals (adjusted)" src="http://hutorny.in.ua/wp-content/uploads/2006/11/Example2-Timing2.thumbnail.png" /></a><br />
      <span align="center">Figure 2</span></td>
</tr>
</table>
<h3>Application Source</h3>
<p><code style="text-align:left">&nbsp;<br /><span style="COLOR: green">;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; License:&nbsp;&nbsp; Licensed to public under the Open Software License</span><br /><span style="COLOR: green">;</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="http://www.opensource.org/licenses/osl-3.0.php"><span style="COLOR: green; TEXT-DECORATION: none; text-underline: none">http://www.opensource.org/licenses/osl-3.0.php</span></a><br />&nbsp;include "pic.inc"<br />&nbsp;include "vos.inc"<br />&nbsp;<br />
<span style="COLOR: green">;------------------------------------------------------------------------------</span><br />
&nbsp;__CONFIG&nbsp;_WDT_ON&nbsp;&amp;&nbsp;_INTRC_OSC_NOCLKOUT&nbsp;&amp;&nbsp;_CP_OFF&nbsp;&amp;&nbsp;_PWRTE_ON &amp;&nbsp;_MCLRE_ON&nbsp;&amp;&nbsp;_FCMEN_OFF&nbsp;&amp;&nbsp;_BOR_OFF&nbsp;&amp;&nbsp;_IESO_OFF<br />
<span style="COLOR: green">;------------------------------------------------------------------------------</span><br />
&nbsp;<br />
&nbsp;constant mask&nbsp;&nbsp;= 02h&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="COLOR: green">; mask to be used for driving port (RA1)</span><br />
&nbsp;constant msgid = 040h&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="COLOR: green">; message ID</span><br />
&nbsp;constant mask1ms&nbsp;= 04h&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="COLOR: green">; mask to be used for driving port on 1 msec event (RC2)</span><br />
&nbsp;constant mask1s&nbsp;&nbsp;= 08h&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="COLOR: green">; mask to be used for driving led  (RC3) &nbsp;</span><br />
  <b><span style="COLOR:#333399">VOS_Classes</span></b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="COLOR: green">; Class definitions begin</span><br />
  MyClass <b><span style="COLOR: #333399">VOS_mClass</span></b> MyHandler,&nbsp;MyInit&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="COLOR: green">; MyClass implementes MyHandler and MyInit methods</span><br />
  MyTimer <b><span style="COLOR: #333399">VOS_mClass</span></b> TmrHandler, TmrInit&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="COLOR: green">; MyTimer implementes TmrHandler, TmrInit</span><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="COLOR: green">; Class definitions end with beginning of the next code section</span><br />
  <b><span style="COLOR:#333399">VOS_Objects</span></b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="COLOR: green">; Object registry begins</span><br />
MyObject<br />
&nbsp; <b><span style="COLOR:#333399">VOS_mPersistentObject</span></b>&nbsp;MyClass,&nbsp;mask&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;<span style="COLOR: green">; Instance of MyClass constructed with object data == mask</span><br />
On1mSec<br /> <br />
&nbsp; <b><span style="COLOR:#333399">VOS_mPersistentObject</span></b> MyTimer,On1mSecData<span style="COLOR: green">; Instance on MyTimer constructed with object data pointing</span><br /> <br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="COLOR: green">; to EERPOM location</span><br />
On1Sec<br />
&nbsp;  <b><span style="COLOR:#333399">VOS_mPersistentObject</span></b> MyTimer,On1SecData  <span style="COLOR: green">; Another instance on MyTimer</span><br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="COLOR: green">; Object registry ends with beginning of the code next section</span><br />
<span style="COLOR: green">;------------------------------------------------------------------------------</span><br />
  <br />
  DEEPROM code<br />
On1mSecData     <br />
&nbsp; de      <b><span style="COLOR:#333399">VTMR_cMsgIDTimer1ms</span></b>, mask1ms<br />
On1SecData<br />
&nbsp; de      <b><span style="COLOR:#333399">VTMR_cMsgIDTimer1s</span></b>, mask1s<br />
  <span style="COLOR: green">;------------------------------------------------------------------------------</span><br />
  &nbsp;&nbsp;&nbsp; code  <br />
MyInit&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="COLOR: green">; This was loaded with object data</span><br />
&nbsp;&nbsp;&nbsp; comf&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<b><span style="COLOR:#333399">This</span></b>,&nbsp;W&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;<span style="COLOR: green">; W := ~mask</span><br />
  <br />
  &nbsp;&nbsp;&nbsp; banksel&nbsp;&nbsp;&nbsp; TRISA<br />&nbsp;&nbsp;&nbsp; movwf&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;TRISA&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;<span style="COLOR: green">; Prepare port for output</span><br />&nbsp;&nbsp;&nbsp; <b><span style="COLOR:#333399">VOS_mPostMessage</span></b>&nbsp;MyObject,&nbsp;msgid&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="COLOR: green">; post message to itself</span><br />
&nbsp;&nbsp;&nbsp; return<br />
<span style="COLOR: green">;------------------------------------------------------------------------------</span><br />&nbsp;<br />
MyHandler&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="COLOR: green">; FSR points to message ID field, This is loaded with object data</span><br />&nbsp;&nbsp;&nbsp; movlw&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; msgid<br />
&nbsp;&nbsp;&nbsp; xorwf&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; INDF,&nbsp;W&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;<span style="COLOR: green">; if message.msg_id &lt;&gt; msgid</span><br />
&nbsp;&nbsp;&nbsp; skpz<br />
&nbsp;&nbsp;&nbsp; return&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;<span style="COLOR: green">; return</span><br />
&nbsp;&nbsp;&nbsp; movf&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <b><span style="COLOR: #333399">This</span></b>,&nbsp;W<br />&nbsp;&nbsp;&nbsp; banksel&nbsp;&nbsp;&nbsp;&nbsp; PORTA<br />
&nbsp;&nbsp;&nbsp; xorwf&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; PORTA,&nbsp;F&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;<span style="COLOR: green">; Toggle port</span><br />
&nbsp;&nbsp;&nbsp; <b><span style="COLOR: #333399">VOS_mPostMessage </span></b>MyObject,&nbsp;msgid&nbsp;&nbsp; &nbsp; &nbsp; <span style="COLOR: green">; post message to itself</span><br />
&nbsp;&nbsp;&nbsp; return<br /><span style="COLOR: green">;------------------------------------------------------------------------------</span></p>
<p>EE_read<br />
&nbsp;&nbsp;&nbsp; banksel&nbsp;&nbsp;&nbsp;&nbsp;  EEADR<br />
&nbsp;&nbsp;&nbsp; movwf&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  EEADR&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color:green; ">; EEADDR = This</span><br />
&nbsp;&nbsp;&nbsp; banksel&nbsp;&nbsp;&nbsp;&nbsp;  EECON1<br />
&nbsp;&nbsp;&nbsp; bsf&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  EECON1,&nbsp;RD&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color:green; ">; EE Read</span><br />
&nbsp;&nbsp;&nbsp; banksel&nbsp;&nbsp;&nbsp;&nbsp;  EEDATA<br />
&nbsp;&nbsp;&nbsp; movfw&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  EEDATA <br />
&nbsp;&nbsp;&nbsp; return<br />
<span style="COLOR: green">;------------------------------------------------------------------------------</span><br />
&nbsp;<br />
TmrHandler<br />
&nbsp;&nbsp;&nbsp; movf&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  <b><span style="COLOR: #333399">This</span></b>, W<br />
&nbsp;&nbsp;&nbsp; call&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  EE_read&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color:green; ">; W = EEPROM[This] == msgid</span><br />
&nbsp;&nbsp;&nbsp; xorwf&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  INDF, W<br />
&nbsp;&nbsp;&nbsp; skpz<br />
&nbsp;&nbsp;&nbsp; return<br />
&nbsp;&nbsp;&nbsp; incf&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  <b><span style="COLOR: #333399">This</span></b>, W<br />
&nbsp;&nbsp;&nbsp; call&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  EE_read&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color:green; ">; W = EEPROM[This+1] == mask</span><br />
&nbsp;&nbsp;&nbsp; banksel&nbsp;&nbsp;&nbsp;&nbsp;  PORTC<br />
&nbsp;&nbsp;&nbsp; xorwf&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  PORTC, F&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color:green; ">; Toggle   PORT</span><br />
&nbsp;&nbsp;&nbsp; return&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br />
&nbsp;<br />
<span style="COLOR: green">;------------------------------------------------------------------------------</span></p>
<p>TmrInit<br />
&nbsp;&nbsp;&nbsp; incf&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  <b><span style="COLOR: #333399">This</span></b>, W<br />
&nbsp;&nbsp;&nbsp; call&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  EE_read&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:green; ">; W =  EEPROM[This+1] == mask</span><br />
&nbsp;&nbsp;&nbsp; xorlw&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  0FFh&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color:green; ">; W = ~mask</span><br />
&nbsp;&nbsp;&nbsp; banksel&nbsp;&nbsp;&nbsp;&nbsp;  TRISC<br />
&nbsp;&nbsp;&nbsp; andwf&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  TRISC, F&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color:green; ">; Prepare port for output according to mask</span><br />
&nbsp;&nbsp;&nbsp; return<br />
<span style="COLOR: green">;------------------------------------------------------------------------------</span><br />
&nbsp;<br />
<b><span style="COLOR: #333399">VOS_BootHandlers</span></b> code&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="COLOR: green">; starts a section for the application boot handler</span><br />
&nbsp;&nbsp;&nbsp; banksel&nbsp;&nbsp;&nbsp;&nbsp; ANSEL<br />
&nbsp;&nbsp;&nbsp; clrf&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ANSEL&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;<span style="COLOR: green">; Turn all pints to digital</span><br />
&nbsp;&nbsp;&nbsp; clrf&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ANSELH<br />
&nbsp;&nbsp;&nbsp; banksel&nbsp;&nbsp;&nbsp;&nbsp; OSCCON&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;<span style="COLOR: green">; Set Fosc = 8Mhz</span><br />
&nbsp;&nbsp;&nbsp; movlw&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (.7 &lt;&lt; IRCF0)<br />
&nbsp;&nbsp;&nbsp; movwf&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; OSCCON<br />
&nbsp;&nbsp;&nbsp; banksel     &nbsp;&nbsp;&nbsp; OSCTUNE     <br />
&nbsp;&nbsp;&nbsp; movlw&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; -.4<br />
&nbsp;&nbsp;&nbsp; movwf&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; OSCTUNE <br />
&nbsp;&nbsp;&nbsp; <span style="COLOR: green">; !!! NO RETURN ALLOWED !!!</span><br />
<span style="COLOR: green">;------------------------------------------------------------------------------</span><br />
&nbsp;<br />
&nbsp;end<br />
</code></p>
]]></content:encoded>
			<wfw:commentRss>http://hutorny.in.ua/projects/pic/veloos/veloos-example-2/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
