Pic based Wind Speed meter


Closed Thread
Results 1 to 32 of 32

Hybrid View

  1. #1
    Join Date
    Feb 2005
    Location
    Holmfirth England
    Posts
    116


    Did you find this post helpful? Yes | No

    Default Re: Pic based Wind Speed meter

    You could use the internal timer of the PIC to measure the time between pulses. I have done something similar to measure the frequency of an AC supply.

    Code:
    define OSC 40
    INCLUDE "DT_INTS-18.bas"     ' Base Interrupt System
    INCLUDE "ReEnterPBP-18.bas"     ' Include if using PBP interrupts
    
    'set up timer 
    T0CON = %00000001 '1/4 prescale fosc/4 not running (40MHz)
    TMR0H = 0  ;Clear registers
    TMR0L = 0
    
    ASM
    INT_LIST  macro    ;  IntSource,  Label,   Type, ResetFlag?
            INT_Handler    INT0_INT,  _ZERO,   PBP,  yes
        endm
        INT_CREATE               ; Creates the interrupt processor
    ENDASM
    
    @   INT_ENABLE   INT0_INT     ; enable external (INT) interrupts
    
    goto start
    
    ZERO: 'we have just detected zero cross signal.
    'first job is to sort out the timer
    @ bcf T0CON,TMR0ON ; Switch off timer
    period.lowbyte = TMR0L  'Record Result
    period.highbyte = TMR0H
    @ clrf TMR0H  ; Reset registers to zero
    @ clrf TMR0L
    @ bsf T0CON,TMR0ON  ;Start timer
    period = (period / 5) * 2  'Gives period value in microseconds
    @ INT_RETURN
    
    start:
    'wait for interrupt to happen
    goto start
    
    END
    You dont need to use interrupts either just a loop waiting for your input signal. In fact not using interrupts might be better. You could sort out your calculations and displaying the result without worrying about being interrupted.

    You would need to set up the timer to give a useable range. I use the "PIC Timer Calculator" to do this, it makes things much easier.
    You may need more than one pulse per revolution to give results at low wind speeds.

    You may need to use the timer interrupt to flag if the timer has overflowed (got to 65535 & started counting again from zero) otherwise in very low winds you may not get a pulse before overflow, & the results would be wrong. If you get a timer overflow interrupt then you can say that the wind speed is zero.

    http://pic-timer-calculator.software.informer.com/
    http://darreltaylor.com/DT_INTS-18/home.html

    Ofcourse this is all more complicated than using pulsein. But It is sometimes good to play around with more complex answers. It is the only way to learn new things. One month ago I knew nothing about using timers or Interrupts. Now it is second nature, and I wonder how I managed to get by without them.

    Regards
    Bob.

  2. #2
    Join Date
    Mar 2010
    Posts
    52


    Did you find this post helpful? Yes | No

    Default Re: Pic based Wind Speed meter

    Hi Bob,

    I totally agree, I have been playing with the manual AD routines and find it much more stable than the ADCIN function ,:-), the only question is which 18F to use, currently i have a 16F876A with a LCD connected and would like to connect some temp sensors and perhaps another pressure sensor, so im not 100% sure which 18F chip would be better suited. Any advice?

    Kind Regards
    Rob

  3. #3
    Join Date
    Feb 2005
    Location
    Holmfirth England
    Posts
    116


    Did you find this post helpful? Yes | No

    Default Re: Pic based Wind Speed meter

    Hi Rob,

    That was written for a 18F1220 18 pin device. I also use 18F2420 28 pin, and 18F4550 40 pin. It depends which of the internal peripherals you want to use. Microchip have a chip selector tool on their site. You tell it what you need, and it will sugest which chips are suitable. Though it did not work last time I tried, but that was probably due to our totally slow, & unreliable internet at work.

    I love how you can get clock speeds of 40 or 48MHZ using 10 or 20MHZ resonator, and using the HS PLL Enabled option. You can pretty much ignore how long calculations etc. take. It's so fast that it usualy makes no difference to your results.

    The only things that get in the way are LCD, EEPROM, or serial comms, etc that always take a long time.

    Regards
    Bob.

  4. #4
    Join Date
    Mar 2010
    Posts
    52


    Did you find this post helpful? Yes | No

    Default Re: Pic based Wind Speed meter

    Hi All,

    Been a slow coding month, although I have been thinking and reading on how to do it, think i have settled on a disk option using a Phototransistor and counting the triggers every 1.5s using something like:

    Count PORTB.2,1500,RPM

    Depending on the number of gaps in the disk i can then do the maths to calculate the RPM and then tweak it / calibrate it to give me a rough wind speed, :-).

    Going to start working on the mechanical parts of it this week and will post pictures and code once its done, :-)

  5. #5
    Join Date
    Mar 2010
    Posts
    52


    Did you find this post helpful? Yes | No

    Default Re: Pic based Wind Speed meter

    Hi All,

    Well, the count didn’t work as expected, seems the count function will only work for >100-150 rpm measurements, :-(. Even an event measured in 1 second, multiplied out the LCD reads it as 60rpm, ;-(

    So far my code is as follows:

    Code:
    INCLUDE "DT_INTS-14.bas"     ' Base Interrupt System
    INCLUDE "ReEnterPBP.bas"     ' Include if using PBP interrupts
    INCLUDE "Elapsed_INT.bas"    ' Elapsed Timer Routines
    DEFINE OSC 4 '4 MHz Osc
    DEFINE LCD_COMMANDUS 2000
    DEFINE ADC_BITS 10
    DEFINE ADC_CLOCK 3
    DEFINE ADC_SAMPLEUS 10
    T1CON = %00000000 '1:1 Prescaler
    TMR1H = 0  ;Clear registers
    TMR1L = 0
    
    TRISB = %00000001 'Set PortB.0 as input for Hall sensor
    ADCON0 = %11100001
    ADCON1 = %10000000  'Right Justify, VDD as vref
    Hall var word 'VAR for hall sensor
    Period var word
    P1 var word
    W2 var word  
    
    ASM
    INT_LIST  macro    ; IntSource,        Label,  Type, ResetFlag?
            INT_Handler    INT_INT,  _HallCount,   PBP,  yes
       ;     INT_Handler   TMR0_INT,  _TimePeriod,   PBP,  yes
            INT_Handler   TMR1_INT,  _ClockCount,   PBP,  yes
        endm
        INT_CREATE               ; Creates the interrupt processor
    ENDASM
    OPTION_REG = OPTION_REG & $80 | 1  ; Set TMR0 Prescaler to 256, leave RBPU alone
    @    INT_ENABLE   INT_INT     ; enable external (INT) interrupts
    '@    INT_ENABLE  TMR0_INT     ; enable Timer 0 interrupts
    @    INT_ENABLE  TMR1_INT     ; Enable Timer 1 Interrupts  
    wsave   VAR BYTE    $20     SYSTEM      ' location for W if in bank0
    'wsave   VAR BYTE    $70     SYSTEM      ' alternate save location for W 
    GOSUB ResetTime              ' Reset Time to  0d-00:00:00.00
    GOSUB StartTimer             ' Start the Elapsed Timer
    Main:
        IF SecondsChanged = 1 THEN  
           SecondsChanged = 0
           LCDOUT $FE,$C0, DEC Days,"d-",DEC2 Hours,":",DEC2 Minutes,":",DEC2 Seconds
        ENDIF
        LCDOut $FE, $80, "Period = ", DEC P1 DIG 3, DEC P1 DIG 2, dec P1 dig 3
    GOTO Main
    '---[INT - interrupt]---------------------------------------------------    
    HallCount:  
             @ bcf T1CON,TMR1ON ; Switch off timer
            period.lowbyte = TMR1L  'Record Result
            period.highbyte = TMR1H
    @ clrf TMR1H  ; Reset registers to zero
    @ clrf TMR1L
    @ bsf T1CON,TMR1ON  ;Start timer
    period = (period / 5) * 2  'Gives period value in microseconds
    p1 = period
    @ INT_RETURN
    I have left in the timer interupt running as it shows that the pic is running for now.

    The output to the LCD now changes depending on the speed of the rotations, however I'm not sure if my prescaler is setup right (4mhz osc) and if the calc to get the microseconds is correct for my osc (thanks BobEdge).

  6. #6
    Join Date
    Mar 2010
    Posts
    52


    Did you find this post helpful? Yes | No

    Default Re: Pic based Wind Speed meter

    One correction to the code, the hall sensor is on RB0 not in PortB.0.

    RB0 is pulled high and the hall sensor pulls it low when the magnet passes (would like to still change this around but assume it wont make a difference except to power consumption).

  7. #7
    Join Date
    Mar 2010
    Posts
    52


    Did you find this post helpful? Yes | No

    Default Re: Pic based Wind Speed meter

    Still stumped with the maths to try get the numbers is giving me into a usable number, anyone that can advise?

    ALso, does anyone have any examples of where / how to capture the TMR overflow?

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