Pic based Wind Speed meter


Closed Thread
Results 1 to 32 of 32

Hybrid View

  1. #1
    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

  2. #2
    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.

  3. #3
    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, :-)

  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,

    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).

  5. #5
    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).

  6. #6
    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?

  7. #7
    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 Bobbo,

    Did you download the PIC timer calculator linked above?
    Using this we can see what is happening much more easily.

    Lets take a look, you have a 4MHz osc, and the timer uses fosc / 4, and your using tmr0 in 16 bit mode.

    So a prescaler of 1:2 gives us a timer clock frequency of 500,000Hz so microseconds value is result x 2 BUT! we can see the interrupt frequency is 7.63Hz. This means that you need at least 7.6 pulses / second otherwise the timer will overflow.

    Lets try 1:8 prescaler. Clock freq is 125,000Hz so period = result * 8, so less resolution, but interrupt frequency is 1.9Hz, so you only need at least 2 pulses / second to give a valid result.

    You need to decide what to do here, you may want 4 or 8 or even 16 pulses / revolution to give more accurate results over a wider range of RPM.

    The timer 0 interrupt you have called _TimePeriod. You need to have a service routine that just tells you that the timer has overflowed, and therefore the wind speed is too low to measure.

    Converting microseconds to wind speed will be tricky, since the higher the wind speed the lower your result. Thinking about it, it may be easier to count the number of pulses in the time it takes for the timer to overflow. This would need many pulses / rev, but the relationship between pulses & wind speed would be proportional and easier to scale.
    For example : prescaler of 1:16, preload timer with value 3036, this gives interrupt at 1Hz. So when timer interrupt happens, stop timer, scale pulse count, and display windspeed, zero the pulse count, set timer to 3036, start the timer, and return from interrupt. When not in interrupt simply increment the number of pulses in a loop. Forget preloading the timer, 1Hz is not required, since the result will need to be scaled anyway so knowing the exact time is not needed.

    Hope this helps.

    Bob...
    Last edited by BobEdge; - 1st November 2011 at 16:18.

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