Trying to inch my way to the finish line w/ a 16F1829.........


Closed Thread
Results 1 to 40 of 68

Hybrid View

  1. #1
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,612


    Did you find this post helpful? Yes | No

    Default Re: Trying to inch my way to the finish line w/ a 16F1829.........

    Hi,
    The 16F1829 has analog inputs on PortA, PortB and PortC but you're only disabling it on PortA. You absolutely MUST read the datasheet for these things. A pin in analog mode may seem to work when used as an output (but it will eventually bite you (RMW issue etc)), however when you're trying to read the state of that output pin (which is what you're doing (or originally did) in the ISR it will not give you the correct result. This is also clearly stated in the datasheet:
    Setting the appropriate ANSELA bit high will cause all
    digital reads on the pin to be read as ‘0’ and allow
    analog functions on the pin to operate correctly
    And the same thing applies for ANSELB and C of course. As you can see, if the ANSELx register isn't set correct any READ of that port-pin will return 0.

    Also, I don't see you're using the ADC for anything yet you're setting ADCON1=7, why is that?

    /Henrik.

  2. #2
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    3,170


    Did you find this post helpful? Yes | No

    Default Re: Trying to inch my way to the finish line w/ a 16F1829.........

    http://www.picbasic.co.uk/forum/showthread.php?t=18529

    If you want to see what you need to make pins digital.

    Robert

  3. #3


    Did you find this post helpful? Yes | No

    Default Re: Trying to inch my way to the finish line w/ a 16F1829.........

    Quote Originally Posted by HenrikOlsson View Post
    Hi,
    The 16F1829 has analog inputs on PortA, PortB and PortC but you're only disabling it on PortA. You absolutely MUST read the datasheet for these things. A pin in analog mode may seem to work when used as an output (but it will eventually bite you (RMW issue etc)), however when you're trying to read the state of that output pin (which is what you're doing (or originally did) in the ISR it will not give you the correct result. This is also clearly stated in the datasheet:
    And the same thing applies for ANSELB and C of course. As you can see, if the ANSELx register isn't set correct any READ of that port-pin will return 0.
    /Henrik.
    Ok sensei, but if that's the case, why did it work fine before? Does high/low set the pin to digital as well as setting the tris bit? Or just a fluke. When it comes to computers, I don't really put much stock in 'accidents' except in the context of "I accidentally screwed that up" lol

    Quote Originally Posted by HenrikOlsson View Post
    Also, I don't see you're using the ADC for anything yet you're setting ADCON1=7, why is that?
    /Henrik.
    I am not sure why it's there. This code started out on a 877a then went to something else when I smoked all 5 of those. Then back to 877a when more came in, then to this 1829 when I smoked all the new 877a's. This 1829 is actually the PICAXE20M2 that got me started on PIC vs Arduino. I came up on two of them scrapping something and saved them. Later, while going thru stuff, I realized they were MC's, and then what PICAXE was, and here I am..... But the code has been cut and pasted, and gone from MPLABX to MCS so idk....

  4. #4
    Join Date
    Jun 2009
    Location
    Sc*nthorpe, UK
    Posts
    333


    Did you find this post helpful? Yes | No

    Default Re: Trying to inch my way to the finish line w/ a 16F1829.........

    Quote Originally Posted by thasatelliteguy View Post
    This code started out on a 877a then went to something else when I smoked all 5 of those. Then back to 877a when more came in, then to this 1829 when I smoked all the new 877a's. This 1829 is actually the PICAXE20M2 that got me started on PIC vs Arduino. I came up on two of them scrapping something and saved them. Later, while going thru stuff, I realized they were MC's, and then what PICAXE was, and here I am..... But the code has been cut and pasted, and gone from MPLABX to MCS so idk....
    I wasted many an unhappy day copying and pasting code that did not work.

    I would start again and build up the program one step at a time. By adding small portions of code if the code stops working the small modification is the cause.

    A good place to start is with the main menu, simply to test HSEROUT and HSERIN. Then take another very small step.

  5. #5
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,612


    Did you find this post helpful? Yes | No

    Default Re: Trying to inch my way to the finish line w/ a 16F1829.........

    Hi,
    Ok sensei, but if that's the case, why did it work fine before? Does high/low set the pin to digital as well as setting the tris bit?
    No, HIGH/LOW only handles the TRIS bit. I'm surprised, and a bit sceptical to be honest, that it really did work before. Then, of course, there might be something I'm missing - wouldn't be the first time, for sure.

    When moving from one PIC to another you really do need to verify that what you set the registers to applies to the new chip as well. Usually it does but certainly not always - especially if you move from one series to another. CMCON is one example, someone searches the forum, finds a post where it says that CMCON=7 disables the comparators. This is true for the some PICs but not all.... It's tedious (some might even say boring) but reading the datasheet really is a must and you certainly do learn a lot from doing it.

    /Henrik.

  6. #6
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    3,170


    Did you find this post helpful? Yes | No

    Default Re: Trying to inch my way to the finish line w/ a 16F1829.........

    Or you do like me and let Alldigital tell you what to do.

    I go to the datasheet when I need a specific feature.

    Robert

  7. #7


    Did you find this post helpful? Yes | No

    Default Re: Trying to inch my way to the finish line w/ a 16F1829.........

    Quote Originally Posted by Demon View Post
    Or you do like me and let Alldigital tell you what to do.

    I go to the datasheet when I need a specific feature.

    Robert
    Well in this case I did that... It's just that it seems when trying to enable the hardware serial, there is A LOT of stuff to activate/set, and I just wasn't getting the combination correct. Still haven't... but haven't tried today either. I got sidetracked on another project... Gotta start a thread on that one now.

  8. #8
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    3,170


    Did you find this post helpful? Yes | No

    Default Re: Trying to inch my way to the finish line w/ a 16F1829.........

    Quote Originally Posted by thasatelliteguy View Post
    ... when trying to enable the hardware serial, there is A LOT of stuff to activate/set, and I just wasn't getting the combination correct. Still haven't...
    Datasheet p. 118, APFCON0, bits 2 and 7.

    The rest comes from Multicalc.

    Robert

  9. #9
    Join Date
    May 2013
    Location
    australia
    Posts
    2,645


    Did you find this post helpful? Yes | No

    Default Re: Trying to inch my way to the finish line w/ a 16F1829.........

    bit 7 of your config word should be 0 , having lvp enabled can lead to tears .
    the comparator needs to be disabled to use your porta pins as digital
    Last edited by richard; - 29th June 2014 at 05:44. Reason: typo

  10. #10


    Did you find this post helpful? Yes | No

    Default Re: Trying to inch my way to the finish line w/ a 16F1829.........

    So you have your BT sorted out?

    I use a BT chip on my boards with no converter. I have the BT chip running at 3.3v just like the PIC.

    I am not sure what you are meaning by handheld device but if you are using a BT chip, look into making the app work on your Android phone.

    Look into Basic4Android. Its a piece of cake to use. The wireless side is a bit cumbersome but once you get it going, its pretty slick. I use it to make an app to control up to 48 electrical motors sending data back and forth from the motor control boards to a tablet all wirelessly.

    http://www.basic4ppc.com/index.html

    If you get try it and need some help, email me at [email protected]

  11. #11


    Did you find this post helpful? Yes | No

    Default Re: Trying to inch my way to the finish line w/ a 16F1829.........

    Quote Originally Posted by richard View Post
    bit 7 of your config word should be 0 , having lvp enabled can lead to tears .
    the comparator needs to be disabled to use your porta pins as digital
    A thousand thank-yous my friend! It worked beautifully!

Similar Threads

  1. Replies: 2
    Last Post: - 31st May 2013, 18:19
  2. line truncate...again
    By queenidog in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 12th March 2012, 21:58
  3. Most Users Ever On-Line
    By skimask in forum Off Topic
    Replies: 1
    Last Post: - 26th April 2007, 19:06
  4. 2 Line Chars on a 2 Line LCD
    By Squibcakes in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 16th November 2003, 00:44

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