Log in

View Full Version : semaphore pic12f629



Leonardo
- 3rd November 2008, 00:18
Hello,
Someone can guide me to do a semaphore using a pic12f629 with which one can vary the speed of lighting of the LEDs.

Thanks for any suggestions

mister_e
- 3rd November 2008, 00:35
By Semaphore you mean?

Leonardo
- 3rd November 2008, 01:00
By Semaphore you mean?


I refer to traffic light

Thanks

mackrackit
- 3rd November 2008, 01:19
What do you want to control the speed with? A pot or have a set of pre determined speeds selected by button pushes or some other manner?

Leonardo
- 3rd November 2008, 01:29
What do you want to control the speed with? A pot or have a set of pre determined speeds selected by button pushes or some other manner?

Hello,

Determined speeds selected by button pushes.

Thanks

mackrackit
- 3rd November 2008, 02:10
First we need to work on the schematic. The way it is drawn the red and green leds will never light up. Yellow is OK.

You will also want it rigged so if a green is on the corresponding red at the other fixture will be off.

Take a look here and see if you want to use a configuration something like the drawing with three pins (with a little tweaking)
http://www.mackrackit.com/mac/www/dave/LED/LEDs.html

Leonardo
- 3rd November 2008, 02:39
First we need to work on the schematic. The way it is drawn the red and green leds will never light up. Yellow is OK.

You will also want it rigged so if a green is on the corresponding red at the other fixture will be off.

Take a look here and see if you want to use a configuration something like the drawing with three pins (with a little tweaking)
http://www.mackrackit.com/mac/www/dave/LED/LEDs.html

Hello,

In this case would be activated sequentially outs GP4 and GP5 agree to the amendment that I made to the circuit.

mackrackit
- 3rd November 2008, 04:17
That is doable. If GP4 is LOW, making GP0 or GP1 or GP2 High will make the connected LED light. The same for GP5.

Being I do not know the sequence you want them to light here is an idea.

Your code will have the "blinking" sequence with multiple pauses. The value of the pauses will be held in a variable. A button will connect to GP3 as an interrupt. Every time the button is pushed the variable will increase by the amount you want. Once the highest value is reached the variable will reset to the lowest.



"VARIABLES
X VAR WORD:Y VAR WORD:Z VAR WORD

ON INTERRUPT GOTO MYINT
INTCON=%10001000
IOC = %00001000
'##############
'YOUR SEQUENCE
'##############
DISABLE
MYINT:
IF GPIO.3 = 1 THEN
X = X * 10
Y = Y ???
Z = Z ???
pause 100
IF X => ? THEN X = ??
IF Y => ? THEN Y = ??
IF Z => ? THEN Z = ??
INTCON.1 = 0
RESUME
ENABLE


Maybe something like that will work for you.

Leonardo
- 3rd November 2008, 15:27
That is doable. If GP4 is LOW, making GP0 or GP1 or GP2 High will make the connected LED light. The same for GP5.

Being I do not know the sequence you want them to light here is an idea.

Your code will have the "blinking" sequence with multiple pauses. The value of the pauses will be held in a variable. A button will connect to GP3 as an interrupt. Every time the button is pushed the variable will increase by the amount you want. Once the highest value is reached the variable will reset to the lowest.



"VARIABLES
X VAR WORD:Y VAR WORD:Z VAR WORD

ON INTERRUPT GOTO MYINT
INTCON=%10001000
IOC = %00001000
'##############
'YOUR SEQUENCE
'##############
DISABLE
MYINT:
IF GPIO.3 = 1 THEN
X = X * 10
Y = Y ???
Z = Z ???
pause 100
IF X => ? THEN X = ??
IF Y => ? THEN Y = ??
IF Z => ? THEN Z = ??
INTCON.1 = 0
RESUME
ENABLE


Maybe something like that will work for you.

Hello,

This is a sequence that desire for the lights.

aratti
- 3rd November 2008, 16:46
You can accomplish the result with only 3 output ports. Connect Red led A and Green led B from port one to ground; Green led A and Red led B from port one to + 5V (pay attention to the polarity). Yellow led A to port 2 and Yellow led B to port 3. When Port one is High the green/red leds (correctly polarized will lit) when port one will turn low you will switch on the second set of green/red leds.
With port 2 and 3 you modulate the yellows.

Darrel Taylor
- 4th November 2008, 01:10
This is a sequence that desire for the lights.
Are you sure about that sequence?

Don't they normally go Green-Yellow-Red?

Leonardo
- 4th November 2008, 01:19
Are you sure about that sequence?

Don't they normally go Green-Yellow-Red?

Darrel is the sequence .gif

Darrel Taylor
- 4th November 2008, 01:22
Darrel is the sequence .gif

Yes, but it looks like it's backwards.

<img src="http://www.picbasic.co.uk/forum/attachment.php?attachmentid=2968" />

Leonardo
- 4th November 2008, 01:25
Yes, but it looks like it's backwards.

<img src="http://www.picbasic.co.uk/forum/attachment.php?attachmentid=2968" />

Darrel sequence can be changed later by now we can start the code to get an idea of the operation, which you suggest?.

Thanks

Darrel Taylor
- 4th November 2008, 01:56
Well, ok.

But I accept no responsibility for the resulting accidents. :eek:

@ device INTOSCIO, WDT_OFF, PWRT_OFF, MCLR_OFF, PROTECT_OFF, CPD_OFF
DEFINE OSCCAL_1K 1

Green CON 5000 ; mS to show Green Light
Yellow CON 1000 ; mS to show Yellow Light
Tcalibrate CON 480 ; Adjust for loop timing accuracy
;---------------------
Sequence VAR BYTE ; cycles through the 4 states
TimeCount VAR WORD ; Counts down sequence time

CMCON = 7 ; Disable comparator
GPIO = %110000 ; Start with all LED's off
TRISIO = %001000 ; Set LED ports to output

;---------------------------------------------------------------------------
Main:
FOR Sequence = 0 to 3
LOOKUP2 Sequence,[ Green, Yellow, Green, Yellow], TimeCount
REPEAT ; Multiplex
LOOKUP Sequence,[%100001,%100011,%100100,%100100],GPIO ; Tr. Light #1
PauseUS Tcalibrate
LOOKUP Sequence,[%010100,%010100,%010001,%010011],GPIO ; Tr. Light #2
PauseUS Tcalibrate
TimeCount = TimeCount - 1
UNTIL TimeCount = 0
NEXT Sequence
GOTO Main

Bruce
- 4th November 2008, 07:46
Pleeeeeeease don't install these traffic lights in Colorado.

My wife thinks;

Green = go
Yellow = go really fast
Red = stop if you can

Would really screw up the natural order of things..;o}

Leonardo
- 4th November 2008, 12:26
Well, ok.

But I accept no responsibility for the resulting accidents. :eek:

@ device INTOSCIO, WDT_OFF, PWRT_OFF, MCLR_OFF, PROTECT_OFF, CPD_OFF
DEFINE OSCCAL_1K 1

Green CON 5000 ; mS to show Green Light
Yellow CON 1000 ; mS to show Yellow Light
Tcalibrate CON 480 ; Adjust for loop timing accuracy
;---------------------
Sequence VAR BYTE ; cycles through the 4 states
TimeCount VAR WORD ; Counts down sequence time

CMCON = 7 ; Disable comparator
GPIO = %110000 ; Start with all LED's off
TRISIO = %001000 ; Set LED ports to output

;---------------------------------------------------------------------------
Main:
FOR Sequence = 0 to 3
LOOKUP2 Sequence,[ Green, Yellow, Green, Yellow], TimeCount
REPEAT ; Multiplex
LOOKUP Sequence,[%100001,%100011,%100100,%100100],GPIO ; Tr. Light #1
PauseUS Tcalibrate
LOOKUP Sequence,[%010100,%010100,%010001,%010011],GPIO ; Tr. Light #2
PauseUS Tcalibrate
TimeCount = TimeCount - 1
UNTIL TimeCount = 0
NEXT Sequence
GOTO Main


Darrel,

You notice how it works.

Thank you

Leonardo
- 4th November 2008, 12:28
Pleeeeeeease don't install these traffic lights in Colorado.

My wife thinks;

Green = go
Yellow = go really fast
Red = stop if you can

Would really screw up the natural order of things..;o}

Bruce,

It is just an example of operation.

Thank you

Leonardo
- 5th November 2008, 00:16
Well, ok.

But I accept no responsibility for the resulting accidents. :eek:

@ device INTOSCIO, WDT_OFF, PWRT_OFF, MCLR_OFF, PROTECT_OFF, CPD_OFF
DEFINE OSCCAL_1K 1

Green CON 5000 ; mS to show Green Light
Yellow CON 1000 ; mS to show Yellow Light
Tcalibrate CON 480 ; Adjust for loop timing accuracy
;---------------------
Sequence VAR BYTE ; cycles through the 4 states
TimeCount VAR WORD ; Counts down sequence time

CMCON = 7 ; Disable comparator
GPIO = %110000 ; Start with all LED's off
TRISIO = %001000 ; Set LED ports to output

;---------------------------------------------------------------------------
Main:
FOR Sequence = 0 to 3
LOOKUP2 Sequence,[ Green, Yellow, Green, Yellow], TimeCount
REPEAT ; Multiplex
LOOKUP Sequence,[%100001,%100011,%100100,%100100],GPIO ; Tr. Light #1
PauseUS Tcalibrate
LOOKUP Sequence,[%010100,%010100,%010001,%010011],GPIO ; Tr. Light #2
PauseUS Tcalibrate
TimeCount = TimeCount - 1
UNTIL TimeCount = 0
NEXT Sequence
GOTO Main


Hello friends,

Upss was wrong with the sequence of lights here correct.

http://img367.imageshack.us/img367/255/trafficlightokyk2.gif (http://imageshack.us)

Leonardo
- 5th November 2008, 01:26
Well, ok.

But I accept no responsibility for the resulting accidents. :eek:

@ device INTOSCIO, WDT_OFF, PWRT_OFF, MCLR_OFF, PROTECT_OFF, CPD_OFF
DEFINE OSCCAL_1K 1

Green CON 5000 ; mS to show Green Light
Yellow CON 1000 ; mS to show Yellow Light
Tcalibrate CON 480 ; Adjust for loop timing accuracy
;---------------------
Sequence VAR BYTE ; cycles through the 4 states
TimeCount VAR WORD ; Counts down sequence time

CMCON = 7 ; Disable comparator
GPIO = %110000 ; Start with all LED's off
TRISIO = %001000 ; Set LED ports to output

;---------------------------------------------------------------------------
Main:
FOR Sequence = 0 to 3
LOOKUP2 Sequence,[ Green, Yellow, Green, Yellow], TimeCount
REPEAT ; Multiplex
LOOKUP Sequence,[%100001,%100011,%100100,%100100],GPIO ; Tr. Light #1
PauseUS Tcalibrate
LOOKUP Sequence,[%010100,%010100,%010001,%010011],GPIO ; Tr. Light #2
PauseUS Tcalibrate
TimeCount = TimeCount - 1
UNTIL TimeCount = 0
NEXT Sequence
GOTO Main


Hummm,

The code works very well but I want to change the sequence of image.

How can I change the code with this sequence.

http://img367.imageshack.us/img367/255/trafficlightokyk2.gif (http://imageshack.us)

Darrel Taylor
- 5th November 2008, 07:18
Just change the numbers in the LookUp's.

LOOKUP Sequence,[%100001,%100011,%100100,%100100],GPIO ; Tr. Light #1


%100001
|| |||
|| ||Red
|| |Yellow
|| Green
|0=Tr.Light #1
0=Tr.Light #2

Leonardo
- 5th November 2008, 11:14
Just change the numbers in the LookUp's.

LOOKUP Sequence,[%100001,%100011,%100100,%100100],GPIO ; Tr. Light #1


%100001
|| |||
|| ||Red
|| |Yellow
|| Green
|0=Tr.Light #1
0=Tr.Light #2

Darrel excellent works ok, I will add other features and when they finish the code public.

Thank you very much

Leonardo
- 5th November 2008, 22:45
Ready already got!.

Darrel Taylor
- 6th November 2008, 14:41
I didn't see that you edited your post.
Oh well, I needed the Flash practice anyway.

<OBJECT CLASSID="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" CODEBASE="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0" WIDTH="600" HEIGHT="400" ><PARAM NAME="MOVIE" VALUE="http://www.pbpgroup.com/files/TrafficLight.swf"><PARAM NAME="PLAY" VALUE="true"><PARAM NAME="LOOP" VALUE="true"><PARAM NAME="QUALITY" VALUE="high"><EMBED SRC="http://www.pbpgroup.com/files/TrafficLight.swf" WIDTH="600" HEIGHT="400" PLAY="true" LOOP="true" WMODE="opaque" QUALITY="high" TYPE="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/go/getflashplayer"></EMBED></OBJECT>

Leonardo
- 6th November 2008, 14:54
I didn't see that you edited your post.
Oh well, I needed the Flash practice anyway.


Hey Darrel,

Very good explanation is very didactic congratulations.

Darrel Taylor
- 7th November 2008, 07:24
"didactic"
That was a new word for me.

I found several "definitions" for it. But I think this one fits exactly what I want to accomplish ... some day.


a: designed or intended to teach
b: intended to convey instruction and information as well as pleasure and entertainment :)
http://www.merriam-webster.com/dictionary/didactic

Thanks!

Leonardo
- 7th November 2008, 13:55
"didactic"
That was a new word for me.

I found several "definitions" for it. But I think this one fits exactly what I want to accomplish ... some day.


a: designed or intended to teach
b: intended to convey instruction and information as well as pleasure and entertainment :)
http://www.merriam-webster.com/dictionary/didactic

Thanks!

Darrel,

In my Spanish language is something that explains in simple and direct the operation of something like this project.

Again thanks for the help.