Code Problems with 16F684


Closed Thread
Results 1 to 6 of 6

Hybrid View

  1. #1
    Join Date
    Sep 2006
    Location
    Indiana, USA
    Posts
    72


    Did you find this post helpful? Yes | No

    Default Figured out part of it.

    I guess I was thinking that 1000 mS was equal to 1 second and 3000 mS was equal to 3 seconds in PIC time. turns out I was wrong, tweaked my pauses a little and got it to work right.
    However, still having serial issues, unimportant now, But I suspect if I were using a better OSC it would clear up. I have a cap across the rails right at the pic but I may tack on a smaller one right across the power pins to see if that helps.

    While I'm using up a post I might as well ask another question. I getting ready to do something with serial again, and I want to use a "two's complement addition" error checking routine and I'm a bit afraid of the math involved. I guess an example of some code could help, or if someone could explain how to add three bytes with no carries or how to discard the overflow bits? To explain it in terms of (A+B+C) ? discard some things = 0 using actual PBP operators would be the most helpful. Or if someone has a ready to use routine? or is there something easier?


    Thanks as always ahead of time.

  2. #2
    Join Date
    Aug 2010
    Location
    Maryland, USA
    Posts
    869


    Did you find this post helpful? Yes | No

    Default

    I don't know about your current question, but I think I can shead some light on you solution. You have OSC = 8 for an 8meg clock, but the pic you are using defaults to 4 meg. To use 8 you need to set up OSCCON reg for 8 meg clock. The DEFINE OSC just tells PBP how fast you INTEND to run, so it is able to calculate the delays for your pause. I am guessing your pauses were taking twice as long? so 1000 = 2 sec and 3000 = 6 sec?

    This will also affect your serial issues
    -Bert

    The glass is not half full or half empty, Its twice as big as needed for the job!

    http://foamcasualty.com/ - Warbird R/C scratch building with foam!

  3. #3
    Join Date
    Mar 2003
    Location
    Commerce Michigan USA
    Posts
    1,166


    Did you find this post helpful? Yes | No

    Default

    Ryan7777, I can't help but notice that you are missing a compare value in the last statement:
    IF aTOd < 45 AND aTOd ??????? THEN DutyCycle1 = 1023
    ENDIF

    I think I would write this routine it as follows to save you some cycles:

    SELECT CASE aTOd
    CASE < 94
    DutyCycle1 = 10
    CASE < 187
    DutyCycle1 = 10
    CASE < 280
    DutyCycle1 = 30
    CASE < 373
    DutyCycle1 = 50
    CASE < 466
    DutyCycle1 = 70
    CASE < 559
    DutyCycle1 = 90
    CASE < 652
    DutyCycle1 = 110
    CASE < 745
    DutyCycle1 = 130
    CASE < 838
    DutyCycle1 = 150
    CASE < 931
    DutyCycle1 = 170
    CASE <= 1023
    DutyCycle1 = 200
    END SELECT

    That should save you some cpu cycles...

    Dave Purola,
    N8NTA

  4. #4
    Join Date
    Sep 2006
    Location
    Indiana, USA
    Posts
    72


    Did you find this post helpful? Yes | No

    Default Awesome!

    Thanks for your replies. I had always assumed that the 16F68Xs just defaulted to 8 instead of 4 Mhz. I'll OSCTUNE it to 8, as you said, it seems like everything is timing out to be twice as long. That explains a lot, Thanks! And yeah, I'll re-write it for select case for the end version, I was still hashing it out and ended up with rough code trying to figure out the timing issue. Now that I have that figured out, and If i can use serout to debug my dimming feature, I can tighten it all up.

    Thanks again to the both of you, You guys are awesome.

    Ryan

  5. #5
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    i'll osctune it to 8
    nope!!!
    Code:
    DEFINE OSC 8              
    OSCCON = %01110000
    Dave
    Always wear safety glasses while programming.

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