Newbie Question


Closed Thread
Results 1 to 15 of 15

Thread: Newbie Question

Hybrid View

  1. #1
    Join Date
    Feb 2006
    Posts
    89


    Did you find this post helpful? Yes | No

    Default algorithim

    I also have a 20mhz crystal. Would this be better to use? Also, I really don't know how to adjust the algorithim for any change in crystal speed, how would you do this? Additionally, on ProtectionsDynamoBen's post, do I need to include the following in the program:
    @ DEVICE pic16F628, HS_OSC ' System clock Options
    @ DEVICE pic16F628, WDT_ON ' Watch Dog Timer
    @ DEVICE pic16F628, PWRT_ON ' Power-on timer
    @ DEVICE pic16F628, BOD_ON ' Brown-out detector
    @ DEVICE pic16F628, MCLR_OFF ' Master Clear Options
    @ DEVICE pic16F628, LVP_OFF ' Low-voltage programming
    @ DEVICE pic16F628, CPD_OFF ' Data Memory Code Protect
    @ DEVICE pic16F628, PROTECT_OFF ' Program Code
    I noticed after time setup, the program changes the contitions of some of the registries. Do I need to do the same and what should they be?

    Sorry for being a hassle but I really appreciate you alls help on this.

    Thanks

  2. #2
    Join Date
    Jun 2005
    Location
    Wisconsin
    Posts
    382


    Did you find this post helpful? Yes | No

    Default

    The @ DEVICE statements are always at the top of my program. It automatically sets up my programmer when I load the file.

    If you change the crystal speed you will need to alter your timing. For now I would just mess around with 4mhz until you find your way around. If it works then great!

    The reason you need to adjust as you change the crystal speed is because the timer function is directly proportional to the crystal. Faster the crystal the faster the timer function will interrupt. If you move to a 20mhz crystal your interrupt will be 5 times faster. So instead of 1 second in your clock program it will be 200ms.

    One thing to remember, most everyone here learned by reading the manual and experimenting. You may have to experiment to answer some of your questions. You may want to pick up Nuts and Volts magazine this month. They are doing a series on PICs and PICBasic, very good if you’re just starting out.
    http://www.nutsvolts.com/
    Last edited by DynamoBen; - 26th February 2006 at 21:19.

  3. #3
    Join Date
    Feb 2006
    Posts
    89


    Did you find this post helpful? Yes | No

    Default Thanks

    Thanks for the help, I just dont understand how it works. I am assuming that if I increase my crystal speed to 20 mhz that I need to change my prescaler or am I way off? Can you explain how it works for me please? I have read the data sheet and understand how to adjust the registers I just don't know how to figure out what they should be.
    Last edited by Travin77; - 26th February 2006 at 23:38.

  4. #4
    Join Date
    Jun 2005
    Location
    Wisconsin
    Posts
    382


    Did you find this post helpful? Yes | No

    Default

    Sort of.

    Check this piece of software out. It really helped me to understand the timers and interrupt times.

    http://users.picbasic.org/projects/P...icTimerCal.htm

    BTW: The datasheet does have a calculation in it. Honestly I never understood it.

  5. #5
    Join Date
    Feb 2006
    Posts
    89


    Did you find this post helpful? Yes | No

    Default Thanks

    Thanks for the info but now I have other problems. While trying to compile the program in Microstudio using picbasic pro it gives me an error on this line:

    Serout portb.2, N9600, [254,1]

    I am trying to send this data out to the lcd which is serial. It gives me this error on every line with this command. I am using the code as before with the adjustments made. Here is a snipit of the top of the program, as I am sure this is the problem hopefully

    ' CONFIGURATION SETUP
    ' Oscillator: XT
    ' Watchdog Timer: OFF
    ' Power up Timer: OFF
    ' Master Clear Enable: Internal
    ' Brown Out Detect: OFF
    ' Code Protect: OFF
    ' Data EE Read Protect:OFF

    'lcd setup
    I con 254
    CLR con 1
    Line1 con 128
    line2 con 192
    line3 con 148
    line4 con 212

    DEFINE OSC 4


    'variables
    HzTimer VAR Word '1/2 second counter (2 Hz)
    HH VAR Byte ' Hours 1-12
    MM VAR ByTE ' Minutes 0-59
    SS VAR Byte ' Seconds 0-59
    X VAR Byte ' temp variable
    col VAR Bit ' colon 1=on, 0=0ff

    'initial conditions of controller
    PORTB.0 = 0 'PORTB.0 PIN LOW
    TRISB.O = 1 'PORTB.0 PIN input for button
    OPTION_REG=%00000111 'weak pullups on, TMRO prescale = ‘256
    HzTimer=$7A12 'for 1/2 Sec
    HH=0:MM=0:SS=0:col=0 'initial conditions
    Pause 1000 'settle Time for Serial LCD

    ' ************************************************** ************
    'SET INITIAL TIME WITH PUSH BUTTON (PART 1 of Program)

    Serout portb.2, N9600, [254,1] this and every other one like it give the same error "bad expression". What am I doing wrong? I am trying to compile the program. Thanks

  6. #6
    Join Date
    Jun 2005
    Location
    Wisconsin
    Posts
    382


    Did you find this post helpful? Yes | No

    Default

    Boy I had to say this but...on page 137 of the manual it states:

    The Mode names (e.g. T2400) are defined in the file MODEDEFS.BAS. To use them, add the line:

    Include "modedefs.bas"

    to the top of the PICBASIC PRO™ program.

    Use your manual, its the Bible of PICBasic. I use mine so much that its falling apart. I also have the web version bookmarked.

  7. #7
    Join Date
    Feb 2006
    Posts
    89


    Did you find this post helpful? Yes | No

    Default Thanks

    I noticed that a little later. One more question and I will leave you alone maybe =). I am trying to send this to the lcd controller:

    SEROUT LCD,6,[I,LINE4,"FAN IS RUNNING"]

    I am pretty sure the part "FAN IS RUNNING" is the problem, I just don't know how to fix it. I need this to appear on the lcd. Is the proper syntax?

Similar Threads

  1. Newbie 74hc595 question
    By manjero in forum mel PIC BASIC Pro
    Replies: 10
    Last Post: - 22nd January 2008, 22:22
  2. newbie with serial com question...
    By kevlar129bp in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 16th December 2006, 05:34
  3. Newbie Question - Info Please
    By ehoskins in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 2nd October 2006, 14:50
  4. Greetings from Newbie and a question
    By ChrisHelvey in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 24th July 2006, 15:52
  5. Newbie question
    By senojlr in forum General
    Replies: 7
    Last Post: - 11th April 2006, 21:23

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