PDA

View Full Version : Bicycle speedometer (write not working continue)



servo260
- 30th December 2004, 22:40
Whell, I started e anew post because the last one was too large.

Ok, I finally got a program that seems to works fine and with a 4mhz osc.
The timer is set to 63ms, and it count it fourth times, so I get 250ms.
Here is the code, It has basic interrupts, but I'm trying to implement them in assembler. What do you think?

define osc 4

TRISA = %00000000
TRISB = %00000001

intcon = 0


clear

num var byte
x var word
pulsos var byte
cuenta var byte
velocidad var word


timer con 9


goto start

on interrupt goto tiempo

start:
OPTION_REG = %10000111
INTCON = %10100000
goto main

main:

if intcon.1 = 1 then
pulsos = pulsos + 1 ; count number of pulses on rb0
intcon.1 = 0
endif

if cuenta = 4 then
cuenta = 0
velocidad = pulsos * 4 * 100 ; meters/hour calc and km/h conversion rutine
velocidad = velocidad / 25
velocidad = velocidad * 36
velocidad = velocidad / 10
x = velocidad
pulsos = 0
endif

num = x dig 0 ; multiplexed display rutine using a 4511
porta = num
high portb.4
pause 3
low portb.4
num = x dig 1
porta = num
high portb.5
pause 3
low portb.5
num = x dig 2
porta = num
high portb.6
pause 3
low portb.6

goto main

disable
tiempo:

cuenta = cuenta + 1 ; counts number of times the timer
; interrupt activates
TMR0 = timer
INTCON.2 = 0

resume
enable

mister_e
- 31st December 2004, 17:50
Well, if everything is working in Basic, why choosing any kind of assembler interrupt. In case your Write statement still not working you can use the EEIE, EEIF, WRERR interrupt/flag (INTCON.6, EECON1 register) , to validate that your EEPROM write is done with F84A

servo260
- 31st December 2004, 19:07
Hi, I added the config rutine and the write statement. But It isn't working. I write a validtion rutine to chek if the WRITE was ok, but I get It's not.
In the 16f84a datasheet says that the error could be caused for a WDT reset or a MCLR reset.
I dissable the WDT, both on pbp and in the fuses, so the only one left is the MCLR reset.
How can I avoid that, considering that everything else is working fine?
I have a 4.7K resistor to MCLR and +5V.


define osc 4

Define NO_CLRWDT 1

TRISA = %00000000
TRISB = %00000111

intcon = 0


clear

num var byte
x var word
pulsos var byte
cuenta var byte
velocidad var word
circunferencia var byte
demora var byte

t1 var portb.4
t2 var portb.5
t3 var portb.6

timer con 9

data @0, 4


goto start

on interrupt goto tiempo

start:
OPTION_REG = %10000111
INTCON = %10100000
read 0, circunferencia
goto main

main:

if portb.2 = 0 then gosub setup

if intcon.1 = 1 then
pulsos = pulsos + 1
intcon.1 = 0 ; pongo a 0 el flag de la interrupcion en Rb0
endif

if cuenta = 4 then
cuenta = 0
velocidad = pulsos * circunferencia * 100
velocidad = velocidad / 25
velocidad = velocidad * 36
velocidad = velocidad / 40
x = velocidad
pulsos = 0
endif

gosub display

goto main


display:
num = x dig 0 ; unidad de X y lo manda a num
porta = num
high t1
pause 3
low t1
num = x dig 1 ; decena de X y lo manda a num
porta = num
high t2
pause 3
low t2
num = x dig 2 ; centena de X y lo manda a num
porta = num
high t3
pause 3
low t3
return



disable
setup: ; config setup

x = circunferencia
for demora = 1 to 50
gosub display
next

setup1:
x = circunferencia
for demora = 1 to 20
gosub display
next
if portb.2 = 0 then gosub config
if portb.3 = 0 then
intcon.7 = 0
write 0,circunferencia
intcon.7 = 1
if eecon1.3 = 0 then ; if write ok shows 888
x = 888
for demora = 1 to 30
gosub display
next
endif
if eecon1.3 = 1 then ; if write not ok shows 111
x = 111
for demora = 1 to 30
gosub display
next
endif
return ; si se apreta el segundo boton vuelve a main
enable
endif
goto setup1

config:

circunferencia = circunferencia + 1
if circunferencia = 216 then circunferencia = 0

return

disable
tiempo:

cuenta = cuenta + 1

TMR0 = timer
INTCON.2 = 0

resume
enable

mister_e
- 31st December 2004, 19:45
let's review a part of setup1 routine



setup1:
if eecon1.3 = 0 then ; if write ok shows 888
x = 888
for demora = 1 to 30
gosub display
next
endif

if eecon1.3 = 1 then ; if write not ok shows 111
x = 111
for demora = 1 to 30
gosub display
next
endif
return ; si se apreta el segundo boton vuelve a main
enable
endif
goto setup1

i'll prefer using something like that



While EECON1.3 == 0 'while eeprom write is not finish
x=111
gosub display
wend

that way you'll monitor WRERR as long the write is not finish. OR, you can also include the WRERR test in your interrupt routine too if you enable EEIE bit in INTCON.

if nothing is working, let me know, i'll give a try in real world with this issue.

servo260
- 31st December 2004, 22:35
Hi,

I tried it but I never get to see the 111, instead it continue showing the configured number for about 20seconds and then return to the main program.

servo260
- 4th January 2005, 04:14
I was doing some test and the write command works when there isn't an interrupt of any kind, basic or assembler.
I really don't understand why. Am I configuring something wrong?