Newbie Question


Closed Thread
Results 1 to 15 of 15

Thread: Newbie Question

Hybrid View

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


    Did you find this post helpful? Yes | No

    Default

    Several things:

    1) First your crystal is connected incorrectly based on the text file. On a 16F628 the crystal needs to be tied to pins 15 and 16. (see datasheet for details)

    2) Depending on your baud rate you may want to move the speed of your crystal up. At 9600 baud I usually use 16 mhz crystal.

    3) Here is an example of a typical Device programming Options :

    @ 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 Protections

    NOTE: If you noticed above I have clock option set to HS not XT. At 16mhz this is considered High-Speed.

    4) When using a crystal don't forget to define the speed:
    DEFINE OSC 16 ' 16mhz XTAL

    5) The word "SYMBOL" is unneeded when you are defining constants. Use the follwing instead:
    line1 CON 128

    6) TRISB=%11111111 ' PORTB all Inputs
    TRISB=%00000000 ' PORTB all Outputs
    TRISB = %00000001 ' PORTB.0 PIN input for button

    These things should help get you running.
    Last edited by DynamoBen; - 26th February 2006 at 06:58.

  2. #2
    Join Date
    Feb 2003
    Location
    Salt Lake City, Utah USA
    Posts
    517


    Did you find this post helpful? Yes | No

    Smile

    With your code posting, if you fix the crystal location as DynamoBen suggested (and makd sure to add the caps to GND) and delete the “INTCONB=0 'interrupts off”
    line, the clock portion with display should work great as is.

    Note - for the code you have, you need to use 4MHz xtal. You could adjust the algorithm for 16MHz xtal if desired. One last thing, to “use the clock”, you can put something like

    If HH = 4 then ‘ turn on portb.1 at 4:15 and turn it off at 4:30
    If MM = 15 then portb.1=1
    If MM = 30 then portb.1=0
    Endif

    In the section labeled “do something here”

    Again, Good Luck,

    Paul Borgmeier
    Salt Lake City, Utah
    USA

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

  4. #4
    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 22:19.

  5. #5
    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; - 27th February 2006 at 00:38.

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

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

Similar Threads

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

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