Bicycle speedometer (write not working continue)


Closed Thread
Results 1 to 6 of 6
  1. #1
    servo260's Avatar
    servo260 Guest

    Default Bicycle speedometer (write not working continue)

    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

  2. #2
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    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
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  3. #3
    servo260's Avatar
    servo260 Guest


    Did you find this post helpful? Yes | No

    Default

    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

  4. #4
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    let's review a part of setup1 routine

    Code:
    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
    Code:
    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.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  5. #5
    servo260's Avatar
    servo260 Guest


    Did you find this post helpful? Yes | No

    Default

    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.

  6. #6
    servo260's Avatar
    servo260 Guest


    Did you find this post helpful? Yes | No

    Default

    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?

Similar Threads

  1. READ WRITE not working consistantly on 12f675
    By sccoupe in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 19th September 2009, 16:15
  2. WRITE: One more PBP 2.60 Surprise ...
    By Acetronics2 in forum mel PIC BASIC Pro
    Replies: 22
    Last Post: - 26th August 2009, 09:10
  3. Need the code to write to a memory
    By Hamlet in forum General
    Replies: 0
    Last Post: - 20th August 2007, 00:22
  4. Changing declared variables names on the fly
    By jessey in forum mel PIC BASIC Pro
    Replies: 15
    Last Post: - 16th December 2006, 06:34
  5. Storing Strings using the Write command
    By BobP in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 1st November 2005, 11:31

Members who have read this thread : 2

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts