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 Problems as usual

    Thanks for the code. I almost got it to work i think. The problem is I don't know how to adjust/configure my registers. I looked at both the 12f625 and 16f629a datasheets to compare the original code to the updated code but my pic has alot registries naturally. I am also not sure if I have the crystal pins setup correctly or not. Here is my code and schematic. The oscillator has built in caps. I also forgot to ask what code I would need to make something happen at a given time. Thanks for any help you all can give.
    Attached Files Attached Files
    Last edited by Travin77; - 26th February 2006 at 03:10.

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

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

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

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

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

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

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