newbie: 16F688 with COUNT & SEROUT


Closed Thread
Results 1 to 7 of 7
  1. #1
    Join Date
    Jun 2007
    Posts
    20

    Default newbie: 16F688 with COUNT & SEROUT

    New guy here with both microcontrollers and PBP...

    All I want to do is count the number of times a switch cycles over the timespan of a second and output it to a serial port. The serial output is working fine, but I'm getting only lines that read "Hertz:". I beleive that it's a problem with the registers, but I've tried various combinations without luck.

    The switch is connected between pin 12 (DIP package) on the PIC and +5VDC, and my code looks like this:

    Code:
    INCLUDE "Modedefs.bas"
    ' Have tried various registers. Here's what I currently have:
    ANSEL = %00000000 ' no analog inputs
    CMCON0 = %00000111 ' comparators off
    
    W1 Var word
    
    Loop:
     COUNT 1,1000,W1
     SEROUT 0,N2400,["Hertz: ",W1,13,10]
     PAUSE 1000
    GOTO Loop 
    
    End
    Any suggestions? Thanks!

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


    Did you find this post helpful? Yes | No

    Default Timer

    Hi Shortbus,
    You might try using a timer to count for you.
    Look at this thread: http://www.picbasic.co.uk/forum/show...ighlight=timer
    JS
    Last edited by Archangel; - 14th June 2007 at 01:40.
    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.

  3. #3
    Join Date
    Jun 2007
    Posts
    20


    Did you find this post helpful? Yes | No

    Default

    Thanks for the reply.

    Can you recommend a particular timer? Also, why can't COUNT be directly utilized for this application?

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


    Did you find this post helpful? Yes | No

    Default

    in your previous code, add a # sign before W1 and post your results.
    Code:
    SEROUT 0,N2400,["Hertz: ",#W1,13,10]
    Count is not bad, but using a timer allow much flexibility, accuracy, and use less code space.
    Steve

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

  5. #5
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by ShortBus View Post
    Thanks for the reply.

    Can you recommend a particular timer? Also, why can't COUNT be directly utilized for this application?
    You'll also be limited to about 50Khz at the input to the PIC if your PIC is running at 8Mhz.

  6. #6
    Join Date
    Jun 2007
    Posts
    20


    Did you find this post helpful? Yes | No

    Default

    Thanks for the replies!

    Even though it may not be the best solution this should work, right? (I'm just experimenting/learning)

    Are my registers set correctly? Is logical Pin 1 --> physical Pin 12 on the 16F688?

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


    Did you find this post helpful? Yes | No

    Default

    I'm not a PIN number fan/ser, i'll prefer to use the Pin Name instead
    Code:
    SEROUT PORTB.0,N2400,["Hertz: ",#W1,13,10]
    OR using a alias
    Code:
    SerialOutput    VAR PORTB.0
    '
    '
    '
    '
    '
    SEROUT SerialOutput,N2400,["Hertz: ",#W1,13,10]
    You can find an explanation on pin number in section 4.11 of the manual.

    HTH
    Steve

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

Similar Threads

  1. A Serial GLCD 128x64 Simple Project
    By Oldspring in forum Off Topic
    Replies: 0
    Last Post: - 8th March 2010, 20:58
  2. Serout to serial servo
    By azmax100 in forum mel PIC BASIC Pro
    Replies: 20
    Last Post: - 12th August 2009, 16:46
  3. COUNT is not counting again
    By jellis00 in forum mel PIC BASIC Pro
    Replies: 33
    Last Post: - 19th June 2009, 04:52
  4. Advice-scrutiny for my serial controller
    By kevlar129bp in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 13th December 2008, 17:11
  5. Keypad unlock (as in garage door possibly)
    By Fred in forum Code Examples
    Replies: 5
    Last Post: - 2nd April 2006, 04:26

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