as the title suggests, I have implemented an odometer with hall sensor switches and neodymium magnets.
everything ok with this code in GCBasic:
CHIP 16F877A,4
CONFIG OSC=XT,WDT_OFF,PWRTE_ON,CP_OFF,DEBUG_OFF,WRT_OFF,CPD_OFF,LVP_OFF,BODEN_ON
On Interrupt ExtInt0 Call Interrupt_RB0
On Interrupt PORTBChange Call Interrupt_PORTB
DIM Flag_apagado,Tick AS INTEGER
SUB Interrupt_PORTB()
IF PORTB.4=1 THEN SET PORTD.0 ON
IF PORTB.4=0 THEN SET PORTD.0 OFF
IF PORTB.5=1 THEN SET PORTD.3 ON
IF PORTB.5=0 THEN SET PORTD.3 OFF
END SUB
SUB Interrupt_RB0()#NR
IntOFF
DO
LOOP UNTIL PORTB.0=1
WAIT 200 ms
IF Flag_apagado=0 THEN
Flag_apagado=1
ELSE
Flag_apagado=0
END IF
IntON
END SUB
SUB Stop()#NR
HPWM 1,20,127
HPWM 2,20,127
END SUB
SUB Adelante_normal()#NR
HPWM 1,20,82
HPWM 2,20,173
END SUB
Ciclo:
TRISA=b'00000'
TRISB=b'00110001'
TRISC=b'00000000'
TRISD=b'00000000'
TRISE=b'00000000'
PORTA=b'000000'
PORTB=b'00000000'
PORTC=b'00000000'
PORTD=b'00000000'
PORTE=b'00000000'
INTCON=b'00000000'
CVRCON=b'00000000'
CCP1CON=b'00001100'
CCP2CON=b'00001100'
ADCON0=b'00000000'
ADCON1=b'10000110'
Flag_apagado=0
Inicio:
INTCON=b'11010000'
OPTION_REG=b'11000000'
SET PORTC.0 OFF
SET PORTD.0 OFF
SET PORTD.3 OFF
IF Flag_apagado=0 THEN GOTO Inicio
SET PORTC.0 ON
INTCON=b'11011000'
Adelante_normal()
DO
LOOP UNTIL Flag_apagado=0
Stop()
GOTO Inicio
the LEDs light up to the passage of magnet as programma.
but if i add a variable to a count,the same contains incorrect values(for example,if the program stopped with the button on PORTB.0 this stops,but the variable to a value much higher than that of the passage of magnet.example 2 round = 8 state change in the variable has a value greater than 100 stored)
PS:sorry for my english
Last edit: alejandro1957 2013-07-19
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
OK. So, the code you provided compiles, and loads into a my simulator.
I will help but I still more clarity. I am not sure I understand you circuit and the core issue.
Is PortB.4 normally high ? PortB.5 also normally high?
In your diagram Output_A and Output_B are shown as outputs. Did you mean inputs?
What is connect Port C.1 and Port C.2?
This could be as simple as a adding a debounce to your code. You can try adding a debounce check.
A recommendation: You should not use #NR in your subs as this is no longer recommended.
Last edit: Anobium 2013-07-20
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
' set up of ports and global variables
' Define the switch port
#define SwitchIn1 PORTD.2
Dir SwitchIn1 In
#define check_switch RD2
#define state_switch OFF
' Debounce button, Debounce switch
Function input_switch ( )
dim ButtonCount as byte
input_switch = false
If check_switch = state_switch Then
ButtonCount = 0
Do While check_switch = state_switch and ButtonCount < 4
wait 5 ms
ButtonCount += 1
Loop
end if
If ButtonCount > 3 then
input_switch = true
ButtonCount = 0
end if
End Function
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
With this code executes the programa and flashes the LED at the end of the count (Pulse = 8), however, a sensor at a time.
if I connect both of you bust
SUB Interrupt_PORTB()
IF INTCON.RBIF=1 THEN
PORTB_New=PORTB_Old#0xC0
IF PORTB_New=0xD0|PORTB_New=0xE0 THEN Impulso+=1
IF PORTB_New=0xF0 THEN Impulso+=1
PORTB_Old=PORTB
INTCON.RBIF=0
END IF
END SUB
CICLO:
TRISA=b'00000'
TRISB=b'00110001'
TRISC=b'00000000'
TRISD=b'00000000'
TRISE=b'00000000'
PORTA=b'000000'
PORTB=b'00000000'
PORTC=b'00000000'
PORTD=b'00000000'
PORTE=b'00000000'
INTCON=b'11001000'
CVRCON=b'00000000'
CCP1CON=b'00000000'
CCP2CON=b'00000000'
ADCON0=b'00000000'
ADCON1=b'10000110'
INICIO:
SET PORTD.0 OFF
SET PORTD.3 OFF
Impulso=0
WAIT 250 ms
DO
LOOP UNTIL Impulso=8
FOR LED=1 TO 8
SET PORTD.0 ON
SET PORTD.3 ON
WAIT 100 ms
SET PORTD.0 OFF
SET PORTD.3 OFF
WAIT 100 ms
NEXT LED
GOTO INICIO
1st hypothesis
I can not handle the interrupt Portb.4/5(I tried with PORTB.6/7 with the same result)
2nd option
problemmi with 74LS14
ideas?
is a better 74HC14?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
as the title suggests, I have implemented an odometer with hall sensor switches and neodymium magnets.
everything ok with this code in GCBasic:
CHIP 16F877A,4
CONFIG OSC=XT,WDT_OFF,PWRTE_ON,CP_OFF,DEBUG_OFF,WRT_OFF,CPD_OFF,LVP_OFF,BODEN_ON
On Interrupt ExtInt0 Call Interrupt_RB0
On Interrupt PORTBChange Call Interrupt_PORTB
DIM Flag_apagado,Tick AS INTEGER
SUB Interrupt_PORTB()
IF PORTB.4=1 THEN SET PORTD.0 ON
IF PORTB.4=0 THEN SET PORTD.0 OFF
IF PORTB.5=1 THEN SET PORTD.3 ON
IF PORTB.5=0 THEN SET PORTD.3 OFF
END SUB
SUB Interrupt_RB0()#NR
IntOFF
DO
LOOP UNTIL PORTB.0=1
WAIT 200 ms
IF Flag_apagado=0 THEN
Flag_apagado=1
ELSE
Flag_apagado=0
END IF
IntON
END SUB
SUB Stop()#NR
HPWM 1,20,127
HPWM 2,20,127
END SUB
SUB Adelante_normal()#NR
HPWM 1,20,82
HPWM 2,20,173
END SUB
Ciclo:
TRISA=b'00000'
TRISB=b'00110001'
TRISC=b'00000000'
TRISD=b'00000000'
TRISE=b'00000000'
PORTA=b'000000'
PORTB=b'00000000'
PORTC=b'00000000'
PORTD=b'00000000'
PORTE=b'00000000'
INTCON=b'00000000'
CVRCON=b'00000000'
CCP1CON=b'00001100'
CCP2CON=b'00001100'
ADCON0=b'00000000'
ADCON1=b'10000110'
Flag_apagado=0
Inicio:
INTCON=b'11010000'
OPTION_REG=b'11000000'
SET PORTC.0 OFF
SET PORTD.0 OFF
SET PORTD.3 OFF
IF Flag_apagado=0 THEN GOTO Inicio
SET PORTC.0 ON
INTCON=b'11011000'
Adelante_normal()
DO
LOOP UNTIL Flag_apagado=0
Stop()
GOTO Inicio
the LEDs light up to the passage of magnet as programma.
but if i add a variable to a count,the same contains incorrect values(for example,if the program stopped with the button on PORTB.0 this stops,but the variable to a value much higher than that of the passage of magnet.example 2 round = 8 state change in the variable has a value greater than 100 stored)
PS:sorry for my english
Last edit: alejandro1957 2013-07-19
Hi, welcome to the forum.
Please post a simple circuit diagram and can you clarify the issue? I can help but I cannot understand the issue.
:-)
this is the circuit (very simple). a hall sensor with digital outputs connected to a 74LS14.
the outputs of the inverter triggered in the Portb.4 / 5
OK. So, the code you provided compiles, and loads into a my simulator.
I will help but I still more clarity. I am not sure I understand you circuit and the core issue.
Is PortB.4 normally high ? PortB.5 also normally high?
In your diagram Output_A and Output_B are shown as outputs. Did you mean inputs?
What is connect Port C.1 and Port C.2?
This could be as simple as a adding a debounce to your code. You can try adding a debounce check.
A recommendation: You should not use #NR in your subs as this is no longer recommended.
Last edit: Anobium 2013-07-20
TRISB=b'00110001
PORTB.0/4/5 are low
PORTC.0 is enable L293B
PORTD.0 and PORTD.3 are the doors that lights and turn off the LEDs to change state on the PORTB.4/5
In your diagram Output_A and Output_B are shown as outputs. Did you mean inputs?
are the outputs of the inverter which sent the TTL signal to the pic
This could be as simple as a adding a debounce to your code. You can try adding a debounce check.
how can you implement?
Have a look at http://www.mikroe.com/download/eng/documents/compilers/mikroc/pro/avr/help/button_library.htm
and, my code for my current project.
' set up of ports and global variables
' Define the switch port
#define SwitchIn1 PORTD.2
Dir SwitchIn1 In
#define check_switch RD2
#define state_switch OFF
' Debounce button, Debounce switch
Function input_switch ( )
dim ButtonCount as byte
input_switch = false
If check_switch = state_switch Then
ButtonCount = 0
Do While check_switch = state_switch and ButtonCount < 4
wait 5 ms
ButtonCount += 1
Loop
end if
If ButtonCount > 3 then
input_switch = true
ButtonCount = 0
end if
End Function
With this code executes the programa and flashes the LED at the end of the count (Pulse = 8), however, a sensor at a time.
if I connect both of you bust
CHIP 16F877A,4
CONFIG OSC=XT,WDT_OFF,PWRTE_ON,CP_OFF,DEBUG_OFF,WRT_OFF,CPD_OFF,LVP_OFF,BODEN_ON
On Interrupt PORTBChange Call Interrupt_PORTB
SUB Interrupt_PORTB()
IF INTCON.RBIF=1 THEN
PORTB_New=PORTB_Old#0xC0
IF PORTB_New=0xD0|PORTB_New=0xE0 THEN Impulso+=1
IF PORTB_New=0xF0 THEN Impulso+=1
PORTB_Old=PORTB
INTCON.RBIF=0
END IF
END SUB
CICLO:
TRISA=b'00000'
TRISB=b'00110001'
TRISC=b'00000000'
TRISD=b'00000000'
TRISE=b'00000000'
PORTA=b'000000'
PORTB=b'00000000'
PORTC=b'00000000'
PORTD=b'00000000'
PORTE=b'00000000'
INTCON=b'11001000'
CVRCON=b'00000000'
CCP1CON=b'00000000'
CCP2CON=b'00000000'
ADCON0=b'00000000'
ADCON1=b'10000110'
INICIO:
SET PORTD.0 OFF
SET PORTD.3 OFF
Impulso=0
WAIT 250 ms
DO
LOOP UNTIL Impulso=8
FOR LED=1 TO 8
SET PORTD.0 ON
SET PORTD.3 ON
WAIT 100 ms
SET PORTD.0 OFF
SET PORTD.3 OFF
WAIT 100 ms
NEXT LED
GOTO INICIO
1st hypothesis
I can not handle the interrupt Portb.4/5(I tried with PORTB.6/7 with the same result)
2nd option
problemmi with 74LS14
ideas?
is a better 74HC14?
OK. I have been away for a day or two. Sorry.
I am trying to get my head around what you are trying to achieve.
How urgent is this? As I go on vacation tomorrow and I would like to help.
we talk about it after the holidays.