Sunday, February 3, 2008

[oopic] Re: events again

--- In oopic@yahoogroups.com, "dldlhfd" <dldlhfd@...> wrote:
>
> About a month or so ago you tried to help me with event
> programming. I eventually gave up and used To Do Loops figuring I
was
> just too dumb to figure it out.
> I have another situation that requires Event programming. I
took
> the code below from the manual. I changed it so I could see leds in
> different parts of the program but I did not change the event part.
> I would expect the code below to delay 5 seconds turn on the
> green led, go to the event subroutine, turn on the red led wait 1
> second and turn it off. From there blink the red led every 1 second.
> What happens is there is a delay of 5 seconds the green led
comes
> on and goes out after a second or so then delays 5 seconds and
comes
> back on. Like it is rebooting. This time I have nothing connected
to
> the board.
> I tried the virtual circuit in chapter 7. That works as
expected.
> Could I get you to run this code and see if it works correctly
> please? another question that might be related. Pin 21 is supposed
to
> be 5 volt pwr I get 6.49 volts. Is that correct?
>
> c 1.1 + board v 6.1.1 compiler
>
> Dim BLINK As New oEvent
> Dim WIRE As New oWire
> Dim led7 As New oLED
> Dim led5 As New oLED
>
> Sub Main()
> ooPIC.Delay = 5000
> led5.IOLine = 5
> led5.TurnOn
> led7.IOLine = 7
> WIRE.Input.Link(ooPIC.Hz1)
> WIRE.Output.Link(BLINK.Operate)
> WIRE.Operate = cvTrue
> End Sub
>
> Sub BLINK_Code()
> led7.TurnOn
> ooPIC.Delay =1000
> led7.TurnOff
> End Sub
>

You need to STOP and find out what is causing the above normal
voltages. Are you talking about some PIN 21 or IOLine 21? What
board do you have? Always put that info in your postings. Just the
chip version and compiler version is not sufficient.

You should never see a voltage above 5V on any IOLine.


Change the ooPIC.Delay = 1000 in Sub BLINK_Code() to ooPIC.Delay =
500 and the code will work.

You are calling the event every second and delaying one second in the
event code. Something is likely to get jammed up.

I see that not only doesn't V6 bother to document ooPIC.Delay but
that the units have been changed from 1/100 second to 1/1000 second.
At first I thought you were delaying 50 seconds at startup!

As a practical matter, your code has an issue You are spending more
than 50% of the processor time waiting on a delay. Maybe some
virtual circuits will still be running but mainline code will not.

You can use Hz60 and a counter to get a similar effect:

Dim BLINK As New oEvent
Dim WIRE As New oWire
Dim led7 As New oLED
Dim led5 As New oLED
Dim counter As New oByte

Sub Main()
counter = 0
ooPIC.Delay = 5000
led5.IOLine = 5
led5.TurnOn
led7.IOLine = 7
WIRE.Input.Link(ooPIC.Hz60)
WIRE.Output.Link(BLINK.Operate)
WIRE.Operate = cvTrue
End Sub

Sub BLINK_Code()
counter = counter + 1
If counter = 30 Then
led7.TurnOn
ElseIf counter = 59
counter = 0
led7.TurnOff
End If

End Sub

This has the advantage of no delays but the disadvantage of executing
the event code 60 times per second. I don't seem to get 1 flash per
second, I'll look in to that some day. It's as though Hz60 is really
Hz30!

Richard



Yahoo! Groups Links

<*> To visit your group on the web, go to:

http://groups.yahoo.com/group/oopic/

<*> Your email settings:
Individual Email | Traditional

<*> To change settings online go to:

http://groups.yahoo.com/group/oopic/join

(Yahoo! ID required)

<*> To change settings via email:
mailto:oopic-digest@yahoogroups.com
mailto:oopic-fullfeatured@yahoogroups.com

<*> To unsubscribe from this group, send an email to:
oopic-unsubscribe@yahoogroups.com

<*> Your use of Yahoo! Groups is subject to:

http://docs.yahoo.com/info/terms/

No comments:

Post a Comment