count problem


Closed Thread
Results 1 to 6 of 6

Thread: count problem

Hybrid View

  1. #1
    servo260's Avatar
    servo260 Guest

    Default count problem

    Hi, i'm using the COUNT command along with an asm interrupt wich shows in a display de variable used by count.
    without the interrupt the commad works fine, but now I'm getting all kind numbers.
    Is there any special variable used by count that I need to save before the interrupt for it to work ok?

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


    Did you find this post helpful? Yes | No

    Default

    IMO, disable interrupt before counting will solve the problem, but there's certainely other way ...See section 9.3 of the PBP manual. It must point you in the right direction.

    BTW wich PIC are you using ? you can look in the according PBPPICXXX.LIB to see what value are use in COUNT. Try R1 and W.

    regards
    Steve

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

  3. #3
    Join Date
    Jul 2003
    Location
    Sweden
    Posts
    237


    Did you find this post helpful? Yes | No

    Post

    It's always a good idea to post your code. It's difficult to help otherwise ........

    Count uses FSR and RM1. FSR needs to be saved and restored in your ASM blocks. RM1 is a PBP variable and needs to be saved and restored the same way as R0,1,2 and 3.
    Code:
    fsave var byte bank0 system
    rm1 var word bank0
    
    asm
    display
             movwf wsave ; display rutine
             swapf STATUS, W
             clrf STATUS
             movwf ssave
             movf PCLATH, W
             movwf psave
             movf FSR,w
             movwf fsave
    endasm
    r0save = R0
    r1save = R1
    r2save = R2
    r3save = R3
    rm1save = RM1
    
    'blah blah ......
    
    R0 = r0save
    R1 = r1save
    R2 = r2save
    R3 = r3save
    RM1 = rm1save
    asm
             bcf INTCON, 1
             movf fsave,w
             movwf FSR
             movf psave, W
             movwf PCLATH
             swapf ssave, W
             movwf STATUS
             swapf wsave, F
             swapf wsave, W
             retfie
    endasm
    It's always a good idea to tell wich PIC and compiler you're using.

    /Ingvar

  4. #4
    servo260's Avatar
    servo260 Guest


    Did you find this post helpful? Yes | No

    Default

    Hi, here is the code I i'm using to test count and asm interruprs with a 16f84a, some var are in sapanish, I hope it's no a problem to understand it, I can't find what is wrong with it.

    define osc 20


    clear

    pulsos var byte

    x var word ; display value

    num var byte


    velocidad var byte

    wsave var byte $20 system
    ssave var byte bank0 system
    psave var byte bank0 system
    r0save VAR WORD bank0
    r1save VAR WORD bank0
    r2save VAR WORD bank0
    r3save VAR WORD bank0
    fsave var byte bank0 system
    rm1save var word bank0



    TRISA = %11111111

    TRISB = %00000000


    goto start


    define INTHAND display



    start:

    option_reg = %00000011


    intcon = %10100000

    main:



    count porta.2,1000,pulsos



    x = pulsos


    goto main






    asm
    display
    ENDASM

    r0save = R0
    r1save = R1
    r2save = R2
    r3save = R3
    fsave = fsr
    rm1save = RM1

    ASM
    movwf wsave
    swapf STATUS, W
    clrf STATUS
    movwf ssave
    movf PCLATH, W
    movwf psave

    endasm



    num = x dig 0

    portb = num

    high portb.4

    pause 7

    low portb.4

    num = x dig 1

    portb = num

    high portb.5

    pause 7

    low portb.5

    num = x dig 2

    portb = num

    high portb.6

    pause 7

    low portb.6

    TMR0 = 60

    INTCON.2 = 0

    asm

    movf psave, W

    movf psave, W
    movwf PCLATH
    swapf ssave, W
    movwf STATUS
    swapf wsave, F
    swapf wsave, W
    endasm

    fsr = fsave
    R0 = r0save
    R1 = r1save
    R2 = r2save
    R3 = r3save
    RM1 = rm1save

    asm
    retfie
    endasm

  5. #5
    Join Date
    Jul 2003
    Location
    Sweden
    Posts
    237


    Did you find this post helpful? Yes | No

    Unhappy

    Hi,

    First of all ...... you didn't follow my instructions, the saving and restoring of PBPvariables and registers are shuffled. Not that it matters much, it will not work anyway. Now when i see your code, i understand what you're trying to do. It will not work for several reasons .... the most obvious one beeing that your interruptroutine will take much longer time than the timer needs to rollover. This means that your pic will be busy handling the display almost all the time. That leaves virtually no time to count pulses. It can be done if you write a true assemblerinterrupt and slow the display. I would have helped you but i'm going away for the hollidays. Perhaps someone else could help, there must be somone more than me that have done this in the past.

    /Ingvar

  6. #6
    servo260's Avatar
    servo260 Guest


    Did you find this post helpful? Yes | No

    Default

    Hi, I did follow your instructions and everithing is working fine now, thanks a lot.
    Some how I post and older code, I didn't notice, sorry.
    And thanks again because I'm new with pics and this help me a lot.

Similar Threads

  1. COUNT is not counting again
    By jellis00 in forum mel PIC BASIC Pro
    Replies: 33
    Last Post: - 19th June 2009, 04:52
  2. Indexer not indexing...a basic PBP problem??
    By jellis00 in forum General
    Replies: 8
    Last Post: - 24th March 2009, 16:53
  3. Problem with ASM IRQ using FSR0 on PIC18F252
    By mytekcontrols in forum mel PIC BASIC Pro
    Replies: 10
    Last Post: - 11th March 2008, 20:48
  4. USART Problem , but don't know where, in pc? or in PIC?
    By precision in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 15th July 2007, 08:12
  5. 7 segment digit problem (using Mister E's code)
    By jmgelba in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 9th September 2005, 20:25

Members who have read this thread : 1

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