Frequency Counter


Closed Thread
Results 1 to 16 of 16

Hybrid View

  1. #1
    Join Date
    Jun 2007
    Location
    Merango, IL
    Posts
    13


    Did you find this post helpful? Yes | No

    Default

    To Skimask:
    I tried out the code you gave me and it did write through the EEPROM like it was suppose to. I re-wrote the code I had and it gives me 00 00 when I do not move any of the inputs around at all if I pull the Pulse Wire in and out of ground it seems to give me random values not how many time I pull it in and out, it does seem kind of close though. The code is posted below if you see a problem with it. Thanks for your help btw. I've been working on this all day now and can't seem to get any repeatability.

    *************************************************
    @ DEVICE PIC12F683, INTRC_OSC_NOCLKOUT
    @ DEVICE PIC12F683, WDT_ON
    @ DEVICE PIC12F683, PWRT_ON
    @ DEVICE PIC12F683, MCLR_OFF
    @ DEVICE PIC12F683, BOD_ON
    @ DEVICE PIC12F683, CPD_OFF
    @ DEVICE PIC12F683, PROTECT_OFF

    TRISIO = %11111111

    Location var WORD

    Mult_Count VAR BYTE

    Was_Low VAR BIT

    Pulse var gpio.3
    Direction VAR gpio.5

    Mult_Count = 0
    Location = 0
    Was_Low = 0

    PAUSE 500

    main:

    IF Pulse = 1 AND Was_Low = 0 THEN
    IF Direction = 1 THEN
    Mult_Count = Mult_Count + 1
    ELSE
    Mult_Count = Mult_Count - 1
    ENDIF
    Was_Low = 1
    ENDIF

    IF Pulse = 0 THEN
    Was_Low = 0
    ENDIF

    IF Mult_Count = 10 THEN
    Location = Location + 1
    Mult_Count = 0
    ENDIF

    IF Mult_Count = -10 THEN
    Location = Location - 1
    Mult_Count = 0
    ENDIF

    WRITE 0, Location.Byte1
    WRITE 1, Location.Byte0
    GOTO main
    end

    *********************************************

    To mister_e:

    I can easily change the clock to 8MHz, I should have done that in the first place. The PWM signal I have done as well, using C code on this chip, and it works pretty nicely. I haven't used the timers before though, although I would really like to go this route with this. My only concern would be I need to be able to count up and down and I'm unsure if can I do so with these Timers. Maybe one way to do so would be to call a interrupt when a direction change is seen and save the timer value before resetting it to 0. Then do the math to another variable with the true position value. I'm gonna start reading on it while I'm still at work. Thanks for the idea it sounds like the best way to go. If you have any advice for going about it let me know. Thanks again.

    Anthony

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


    Did you find this post helpful? Yes | No

    Default

    See if this helps;

    CMCON0 = 7
    ANSEL = 0

    Comparators & A/D are enabled by default on power-up. To use some pins for
    digital I/O, you need to disable these.
    Regards,

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

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


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Asmith View Post
    To Skimask:
    I tried out the code you gave me and it did write through the EEPROM like it was suppose to. I re-wrote the code I had and it gives me 00 00 when I do not move any of the inputs around at all if I pull the Pulse Wire in and out of ground it seems to give me random values not how many time I pull it in and out, it does seem kind of close though.
    Anthony
    It might be working and counting multiple switch closures due to bouncing switch contacts (noise).
    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.

  4. #4
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,132


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Asmith View Post

    IF Mult_Count = -10 THEN
    Location = Location - 1
    Mult_Count = 0
    ENDIF
    Are you sure that PBP can do negatives???

    Ioannis

  5. #5
    Join Date
    Jun 2007
    Location
    Merango, IL
    Posts
    13


    Did you find this post helpful? Yes | No

    Default

    Bruce:
    Thank you I did forget to set up those two registers. I will fix that.

    Joe:
    I'm using a function generator on the input with a scope on it as well and there is no bouncing on the pin. In the end it will be from a hall effect switch which also should not have any bouncing.

    Ioannis:
    I believe PBP will do negative numbers, Location should never be a negative number anyways as 0 would be the lowest number of counts you can have it will be zero we it is set up.

    I think I'm going to try and use the internal timer which I haven't been able to work on it much as work has me burried. I did have some time to write out some code. I will post is below, if you guys would like to comment on it I would appreciate it. It might be a little chopy at the moment though.

    ************************************************** *****
    @ DEVICE PIC12F683, INTRC_OSC_NOCLKOUT
    @ DEVICE PIC12F683, WDT_ON
    @ DEVICE PIC12F683, PWRT_ON
    @ DEVICE PIC12F683, MCLR_OFF
    @ DEVICE PIC12F683, BOD_ON
    @ DEVICE PIC12F683, CPD_OFF
    @ DEVICE PIC12F683, PROTECT_OFF

    '* Hardware Setups *

    INTCON = %10001000
    PIE1 = %00000000
    PIR1 = %00000000
    OSCCON = %01110000

    '* I/O Pin Descriptions Below *
    '* PIN 1 - VDD - 5V *
    '* PIN 2 - T1CK1 - Input - Pulses from Hall Effect *
    '* PIN 3 -
    '* PIN 4 - GP3 - Input for the direction of the Hall Effect *
    '* PIN 5 - CCP1 - PWM Output to the Analog converter *
    '* PIN 6 -
    '* PIN 7 -
    '* PIN 8 - VSS - Ground *

    TRISIO = %00101000
    WPU = %00000000
    IOC = %00001000

    '* Timer Setup *
    T1CON = %00100111



    Location var WORD

    Mult_Count VAR BYTE

    Was_Low VAR BIT

    Pulse var gpio.3
    Direction VAR gpio.5

    Mult_Count = 0
    Location = 0
    Was_Low = 0

    PAUSE 500

    main:


    GOTO main
    end

    ************************************************** ***

  6. #6
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Asmith View Post
    Ioannis:
    I believe PBP will do negative numbers, Location should never be a negative number anyways as 0 would be the lowest number of counts you can have it will be zero we it is set up.
    Sure, PBP and assembly both will do negative numbers, but they won't show up the way you want them to...i.e.:

    5 - 6 = -1, but PBP will show 255 (for a byte variable), 65535 (for a word variable).

    You're going to want to add something like this to your program in post #4:

    main:
    IF Pulse = 1 AND Was_Low = 0 THEN
    IF Direction = 1 THEN
    Mult_Count = Mult_Count + 1
    ELSE
    if mult_count > 0 then mult_count = mult_count - 1
    ENDIF
    Was_Low = 1
    ENDIF
    ...............

    IF Mult_Count = -10 THEN(statement won't work the way you want it to in PBP)
    Location = Location - 1
    Mult_Count = 0
    ENDIF

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


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Asmith View Post
    Bruce:

    Joe:
    I'm using a function generator on the input with a scope on it as well and there is no bouncing on the pin. In the end it will be from a hall effect switch which also should not have any bouncing.




    ************************************************** ***
    It was worth checking.
    JS
    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.

Similar Threads

  1. Conway's Game Of Life
    By wellyboot in forum mel PIC BASIC Pro
    Replies: 45
    Last Post: - 28th May 2020, 06:14
  2. Audio Frequency Counter
    By mister_e in forum Code Examples
    Replies: 8
    Last Post: - 29th July 2009, 08:25
  3. frequency counter help and pointers
    By comwarrior in forum General
    Replies: 2
    Last Post: - 30th June 2009, 11:51
  4. Microcontroller with 2 way paging application problem
    By oneohthree in forum mel PIC BASIC Pro
    Replies: 30
    Last Post: - 20th April 2007, 17:27
  5. Frequency Counter using PIC and PicBasic
    By PICtron in forum mel PIC BASIC Pro
    Replies: 31
    Last Post: - 28th January 2005, 06:20

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