Hola Picuino,
Yo no estoy tratando de generar grafcet puro el cual esta basado en la norma IEC 608048, sino que trato de implementar programación SCF como la que utilizan los PLC basado en la norma IEC 61131-3, son parecidos pero no igual :D :D.
Si quieres te ayudo a implementar el programa del grafcet que has puesto en el primer post (que habría que corregir también).
De todas formas ese grafcet no hace nada, sería mejor hacer un grafcet para encender un led al pulsar un botón y apagar el led al volver a pulsar el botón. Todo hecho con Grafcet y estados, sin detectar flancos.
Un saludo.
Sin detectar flancos :-/ !!! es un reto muy bueno. Si puedes mostrarnos como lo haces y lo posteas. Seria muy interesante de ver ((:-)).
Sería algo similar a este diagrama, puse entre paréntesis la detección de flancos porque en realidad no se como hacerlo sin detección de flancos.
(http://i55.photobucket.com/albums/g143/joserafa83/detector_flancos.jpg)
Esta es la simulación en Proteus, de mi placa de desarrollo para PIC12F675 :D
(http://i55.photobucket.com/albums/g143/joserafa83/Ejercicio01_02.gif)
Y este seria el código en PSI Basic
Dim m0 As Byte
Dim last_button_state As Bit
Dim button_state As Bit
Dim flag_debounce As Bit
Dim rising_flag As Bit
Symbol key1 = GPIO.2
Symbol key2 = GPIO.5
Symbol led1 = GPIO.0
Symbol led2 = GPIO.1
Symbol adc_vr1 = GPIO.4
inicio:
m0 = 0
CMCON = 7
ANSEL = 0
TRISIO = %11111100
last_button_state = 0
button_state = 0
flag_debounce = 0
rising_flag = 0
m0 = 1
If m0 = 1 Then
Goto led_off
Else
Goto inicio
Endif
led_off:
led1 = 0
Gosub rising_edge
'si existe un flanco positivo m0=2
If rising_flag = 1 Then
rising_flag = 0
m0 = 2
Endif
If m0 = 2 Then
Goto led_on
Else
Goto led_off
Endif
led_on:
led1 = 1
Gosub rising_edge
'si existe un flanco positivo m0=1
If rising_flag = 1 Then
rising_flag = 0
m0 = 1
Endif
If m0 = 1 Then
Goto led_off
Else
Goto led_on
Endif
End
'RUTINA PARA DETECTAR FLANCO POSITIVO
'SE INCLUYE RETARDO 20ms PARA ELIMINAR REBOTE
rising_edge:
button_state = key1
If last_button_state <> button_state Then
WaitMs 20 'RETARDO PARA ELIMNAR REBOTE
button_state = key1
If last_button_state <> button_state Then
flag_debounce = 1
Endif
If flag_debounce = 1 Then
If button_state = 1 Then
flag_debounce = 0
last_button_state = button_state
rising_flag = 1
Endif
Endif
Endif
last_button_state = button_state
Return
Aquí les traigo otro ejercicio :-/, con el mismo pulsador vamos a encender y apagar los LED1 Y LED2 secuencialmente.
El diagrama SFC de control sería el siguiente:
(http://i55.photobucket.com/albums/g143/joserafa83/ejercicio1_3.jpg)
La simulación en Proteus seria la siguiente:
(http://i55.photobucket.com/albums/g143/joserafa83/Ejercicio01_03.gif)
EL código en PSI Basic:
Dim m0 As Byte
Dim last_button_state As Bit
Dim button_state As Bit
Dim flag_debounce As Bit
Dim rising_flag As Bit
Symbol key1 = GPIO.2
Symbol key2 = GPIO.5
Symbol led1 = GPIO.0
Symbol led2 = GPIO.1
Symbol adc_vr1 = GPIO.4
inicio:
m0 = 0
CMCON = 7
ANSEL = 0
TRISIO = %11111100
last_button_state = 0
button_state = 0
flag_debounce = 0
rising_flag = 0
m0 = 1
If m0 = 1 Then
Goto led1_2_off
Else
Goto inicio
Endif
led1_2_off:
led1 = 0
led2 = 0
Gosub rising_edge
If rising_flag = 1 Then
rising_flag = 0
m0 = 2
Endif
If m0 = 2 Then
Goto led1_on
Else
Goto led1_2_off
Endif
led1_on:
led1 = 1
Gosub rising_edge
If rising_flag = 1 Then
rising_flag = 0
m0 = 3
Endif
If m0 = 3 Then
Goto led1_off
Else
Goto led1_on
Endif
led1_off:
led1 = 0
Gosub rising_edge
If rising_flag = 1 Then
rising_flag = 0
m0 = 4
Endif
If m0 = 4 Then
Goto led2_on
Else
Goto led1_off
Endif
led2_on:
led2 = 1
Gosub rising_edge
If rising_flag = 1 Then
rising_flag = 0
m0 = 5
Endif
If m0 = 5 Then
Goto led2_off
Else
Goto led2_on
Endif
led2_off:
led2 = 0
Gosub rising_edge
If rising_flag = 1 Then
rising_flag = 0
m0 = 2
Endif
If m0 = 2 Then
Goto led1_on
Else
Goto led2_off
Endif
End
'RUTINA PARA DETECTAR FLANCO POSITIVO
'SE INCLUYE RETARDO 20ms PARA ELIMINAR REBOTE
rising_edge:
button_state = key1
If last_button_state <> button_state Then
WaitMs 20 'RETARDO PARA ELIMNAR REBOTE
button_state = key1
If last_button_state <> button_state Then
flag_debounce = 1
Endif
If flag_debounce = 1 Then
If button_state = 1 Then
flag_debounce = 0
last_button_state = button_state
rising_flag = 1
Endif
Endif
Endif
last_button_state = button_state
Return