COUNT is not counting again


Closed Thread
Results 1 to 34 of 34

Hybrid View

  1. #1
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    The first error indicates you have not commented out the __config line if the 16F690.INC
    file that's used with the MPASM assembler. Make sure you do before compiling if you insert
    the MPASM @ __config directive in your code.

    The remaining errors indicate it's not finding the Microchip P16F690.INC file, which defines
    register locations/names.

    Make sure your path statement includes information on where you have MPLAB installed, or
    modify the 16F690.INC file to point directly to it.

    INCLUDE "C:\Program Files\Microchip\MPASM Suite\P16F690.INC"
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  2. #2
    Join Date
    Mar 2009
    Location
    Colorado
    Posts
    378


    Did you find this post helpful? Yes | No

    Unhappy Path was the problem...now I have a new problem

    Quote Originally Posted by Bruce View Post
    "Make sure your path statement includes information on where you have MPLAB installed, or modify the 16F690.INC file to point directly to it."
    I guess when I upgraded to PB Pro and installed it, MPLAB must have ended up in a different place. Thanks for catching this...I could have spent a long time looking and not thinking of this.
    Now I have a different problem. Although I was going to try to do the counting with a NonInterrupt version of using the TMR0 overflow counter as you described above, I discovered as I progressed on my app design that I really need to do the counting with an interrupt and also another interrupt for checking on an external switch closure. I therefore am trying to use the below code where I have the interrupt handler doing two IF..THEN checks of the flag bits to handle either the TMR0 overflow while using RA2 input to TMR0 as switch for counting, or the RABIE on-change-interrupt for the RA3 input from a switch closure to ground. The TMR0 interrupt works in this code, however, the RABIE on-change-interrupt does not. I can't figure out why. Can you see whay the RABIE isn't working??
    Code:
    ' -----[ Device Declaration ]----------------------------------------------
    '
    @ __config _INTRC_OSC_NOCLKOUT & _WDT_OFF & _MCLRE_OFF & _CP_OFF
     
    ' -----[ Variables & Aliases Intitialization ]-----------------------------
    '
    led1  VAR PORTC.0   ' Set RC0 as LED indicator of valve open..water flowing
    led2  VAR PORTC.1   ' Set RC1 as LED indicator of low battery
    valve VAR PORTC.3   ' Set RC3 as valve solenoid open/close command
    low_bat VAR PortA.0 ' Set RA0 as battery low power monitor
    meter VAR PORTA.2   ' Set RA2 as input for Hall Sensor meter pulse Interrupt
    flush VAR PORTA.3   ' Set RA3 as input for sensing flush switch closure Int
    bat_mon VAR Byte    ' bat_mon value when Vtrh multiplied by low_bat
    
    
    ' -----[ Constants Initialization ]----------------------------------------
    '
     k             CON 10   ' Calibration factor for flow meter...# pulses per gal
     i             VAR Byte ' Index used in Gallon counter loop
     Vthr          CON 4    ' Low Battery Monitor threshold
     
    ' -----[ Initialization ]--------------------------------------------------
    '
    'EEPROM PRESETS
    'DATA @0,0
    
    'OSC DEFINE
    'DEFINE OSC 4
    
    ' Setup Timer0 as an 8-bit counter with the clock input on RA2.
    ' 1:1 TMR0 prescaler
    ' TMR0 counts on high-to-low transitions
      OPTION_REG = %00111000
      
    'Register Settings
    Init:
    TRISA = %11111111   ' Set all PORTA pins to inputs...RA0, RA2 & RA3 are used
    TRISB = %00000000   ' Set all PORTB and PORTC pins to outputs
    TRISC = %00000000
    PORTC = %00000000	' Pre-set PORTC pins low, turning LEDs off
    TMR0 = 256-K        ' Preload TMR0 to overflow after k counts
    
    'A/D & Comparators disabled
      ADCON0 = %01110000  ' Set PORTA to digital I/O & FRC (clock derived from a 
      ADCON1 = %00000000  ' dedicated internal oscillator)
      ANSEL=0           ' Set PortA to digital I/O
      ANSELH=0          ' Analog module disabled
      CM1CON0=0
      CM2CON0=0
    TRISC.3 = 0       ' Set RC3 as output port for valve latching solenoid control
    Low Valve         ' Initialize RC3 (valve) at Low value
    TRISA.2 = 1       ' Set RA2 as input port for clock to TMR0
    TRISA.3 = 1       ' Set RA3 as input port for sensing METER switch closure
    High meter        ' Initialize RA2 (meter) at High value for METER pulse inputs
                      ' RA2 = TMR0 clock input for simulated meter pulse inputs
    High flush        ' Initialize RA3 (flush) at High value for flush interrupt  
      
    'Interrupts Settings
    FLUSH_INT_FLAG VAR INTCON.0  ' RA3 (FLUSH) On-change-interrupt flag bit
    TMRO_INT_FLAG VAR INTCON.2   ' Timer0 overflow flag bit 
    INTCON = %10101000           ' Enable global, TMR0 & RABIE (RA3 on-change-INT)
    IOCA = %00000000             ' Enable RA3 as on-change-INT
    
    ' -----[ Main Code ]-------------------------------------------------------
    'Set INT Handler
    ON INTERRUPT GOTO Int_handler   
    
    'Start...normal code here
    MAIN:
        PORTC = %00000000   ' Turn all LEDs off
        PAUSE 1
        'SLEEP = 65,535     ' Put MC in Sleep state at power up 
        ' Microcontroller is in Sleep State waiting for external FLUSH Interrupt
      GOTO Main        ' Loop to Main to wait for next Flush interrupt
    
      DISABLE 
    Int_handler:
      IF FLUSH_INT_FLAG = 1 Then  ' Interrupt was from RA3 on change    
        DEFINE WRITE_INT 1
        write  9, flush     ' Write RA3 (FLUSH) value during testing
        PULSOUT valve,1000  ' Generate required 10 msec pulse to RC3 to open valve
        High led1           ' Light indicator that valve is open & water flowing
        Low low_bat         ' Simulate battery monitor input is low  
        'Put code here to Wakeup the Microcontroller
        
        ' Put code here to start a timer to run for 50 secs as a fail safe 
        ' to prevent overflow of toilet tank in case of sensor failure.
            'Goto Shutvalve
        High flush             ' Clear the interrupt
        FLUSH_INT_FLAG = 0     ' Clear interrupt flag
      Endif
      IF TMRO_INT_FLAG = 1 then  ' Interrupt was a TMR0 overflow..volume reached
        PULSOUT valve,6000  ' Generate required 20 msec pulse to RC3..close valve  
        WRITE 5, TMR0      ' Write TMR0 value..remove comment for test only
        bat_mon = low_bat * Vthr
        Write 7, bat_mon    ' Remove comment for test only  
        If bat_mon < Vthr Then
            'Light the low battery monitor light
            HIGH led2
        ENDIF
        TMR0 = 256-k              ' Reload TMR0 to overflow after k counts
        TMRO_INT_FLAG = 0         ' Clear overflow flag
      ENDIF
      LOW led1
      Low led2
      RESUME
      ENABLE   
    
        ' If the user program ends by getting to the last statement of the program
        ' at an END instruction, the MCU will SLEEP and await a wakeup.
    END

  3. #3
    Join Date
    Mar 2009
    Location
    Colorado
    Posts
    378


    Did you find this post helpful? Yes | No

    Question Fixed part of the problem

    I discovered one of DT's posts that explained part of my problem was that I wasn't properly clearing the mismatch. When I did that the On-interrupt for RA3 worked. However, I noticed in the same DT post his statement "Keep in mind that you will get an interrupt on both the Press and Release of the button. You will eventually need to change the interrupt handler to determine which Edge occurred." I am using a momentary switch button that grounds RA3 for this On-interrupt and now I see happening what he was warning about...I get an intterupt on press AND release. However, I don't quite grasp how to modify my interrupt handler "to determine which Edge occurred." Obviously I want the interrupt to respond only to the press and not the release. Is there a way to filter out the release action to prevent the 2nd interrupt?

  4. #4
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by jellis00 View Post
    I discovered one of DT's posts that explained part of my problem was that I wasn't properly clearing the mismatch. When I did that the On-interrupt for RA3 worked. However, I noticed in the same DT post his statement "Keep in mind that you will get an interrupt on both the Press and Release of the button. You will eventually need to change the interrupt handler to determine which Edge occurred." I am using a momentary switch button that grounds RA3 for this On-interrupt and now I see happening what he was warning about...I get an intterupt on press AND release. However, I don't quite grasp how to modify my interrupt handler "to determine which Edge occurred." Obviously I want the interrupt to respond only to the press and not the release. Is there a way to filter out the release action to prevent the 2nd interrupt?
    Page 37 of the data sheet, Option Reg allows you to control rising or falling edge on RA2, you might have to move your ports around a bit . . .
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

  5. #5
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    If your switch grounds the input pin to generate the interrupt, and it returns high when the
    switch is released, just wait for the pin to return high before exiting the interrupt.
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  6. #6
    Join Date
    Mar 2009
    Location
    Colorado
    Posts
    378


    Did you find this post helpful? Yes | No

    Default Your suggestion solved problem

    By following your suggestion for basically debouncing it works. Thanks for advice!

Similar Threads

  1. Can't get COUNT to count
    By jellis00 in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 24th March 2009, 00:14
  2. Remain counting while sending out a pulse
    By ultiblade in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 10th January 2007, 16:51
  3. hardware counting while software runs
    By Archangel in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 2nd October 2006, 04:26
  4. continious counting process (capture)
    By asynch in forum General
    Replies: 1
    Last Post: - 17th February 2006, 08:42
  5. Count command
    By hawk72501 in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 6th September 2005, 20:04

Members who have read this thread : 0

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