PBP migration from 16F88 to 16F1827


Closed Thread
Results 1 to 21 of 21

Hybrid View

  1. #1
    Join Date
    Aug 2006
    Location
    Omaha, Nebraska USA
    Posts
    263

    Question PBP migration from 16F88 to 16F1827

    Okay, I'm overlooking something. This program worked (albeit slowly) on a 16F88.

    5 analog pins sample and (after manipulation) produce a high or low to a pin. Here's the correspondence:

    AN0 to B5
    AN1 to B4
    AN2 to B3
    AN3 to B2
    AN4 to B1

    AN5 and AN6 each have the wiper of a different pot on them.

    Now, only AN4 to B1 works correctly. B5 is stuck high all the time (from power-up), even with no signal on AN0. The three in between are off if there is no signal but stick high as soon as a small signal is applied and remain that way until power-down.

    The pot on AN5 has the correct effect on the one working channel but AN6 does not appear to be working.

    Here's what I had in the (totally working) 16F88 version:

    DEFINE OSC 8

    ANSEL= %01111111
    CMCON= %00000111
    OSCCON= %01110000
    TRISA= %01111111
    TRISB= %11000001

    ADCON1.7=1

    DEFINE ADC_BITS 10
    DEFINE ADC_CLOCK 5
    DEFINE ADC_SAMPLEUS 12

    . . . and here's what I have for the 16F1827:

    DEFINE OSC 32

    ANSELA= %00011111
    ANSELB= %11000000
    OSCCON= %11110000
    TRISA = %01111111
    TRISB = %11000001

    ADCON1.7 =1
    CM1CON0.7=0
    CM2CON0.7=0

    DEFINE ADC_BITS 10
    DEFINE ADC_CLOCK 6
    DEFINE ADC_SAMPLEUS 12

    What thing(s) am I failing to do?
    Russ
    N0EVC, xWB6ONT, xWN6ONT

    "Easy to use" is easy to say.

  2. #2
    Join Date
    Aug 2006
    Location
    Omaha, Nebraska USA
    Posts
    263


    Did you find this post helpful? Yes | No

    Default

    I discovered the capacitive sensing module and have added:

    CPSCON0.7=0 to turn it off.

    The effect was that the one working channel continues to work.

    The pot on AN6 also now works.

    But now all the other four channels lock high at power-up, even with no signal, and stay there.

    I guess that's a tiny speck of progress.
    Last edited by RussMartin; - 25th February 2010 at 05:13.
    Russ
    N0EVC, xWB6ONT, xWN6ONT

    "Easy to use" is easy to say.

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


    Did you find this post helpful? Yes | No

    Default

    I have had trouble in the past with the built in ADC commands.
    You may want to try the method used here.
    http://www.picbasic.co.uk/forum/show...2&postcount=16
    Dave
    Always wear safety glasses while programming.

  4. #4
    Join Date
    Aug 2006
    Location
    Omaha, Nebraska USA
    Posts
    263


    Did you find this post helpful? Yes | No

    Default

    I've also tried to make sure the CCP/ECCP modules were off by adding:

    CCP1CON=%00000000
    CCP2CON=%00000000
    CCP3CON=%00000000
    CCP4CON=%00000000

    No change from previous result.
    Russ
    N0EVC, xWB6ONT, xWN6ONT

    "Easy to use" is easy to say.

  5. #5
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by RussMartin View Post
    What thing(s) am I failing to do?
    Well, you failed to include the part that reads the A/D, "Manipulates" it, then outputs it to a pin.
    <br>
    DT

  6. #6
    Join Date
    Aug 2006
    Location
    Omaha, Nebraska USA
    Posts
    263


    Did you find this post helpful? Yes | No

    Default

    I didn't include anything else because (a) everything ran fine on the '88 and (b) one of the five identically-processed channels is working just fine.

    All five channels are handled like this (different VARs, of course) in a loop, with the interrupt enabled:

    FOR SAMPLX=4 TO 1 STEP -1
    ADCIN 2,INMD
    IF INMD>TEMPMD THEN TEMPMD=INMD
    NEXT SAMPLX
    INMD=TEMPMD
    IF MODE=1 THEN GOTO HOP3
    IF INMD>341 THEN
    INMD=(INMD-342)*3
    ELSE
    INMD=0
    ENDIF
    HOP3:
    IF INMD<10 THEN COMP=0
    IF INMD<THRES THEN INMD=THRES+INMD+COMP
    INMD=INMD+COMP
    IF INMD>1023 THEN INMD=1023
    TEMPMD=0
    XMD=INMD/2

    The INT_INT handler looks like this:

    STATE:
    FOR INDEX=511 TO 1 STEP -1
    IF INDEX=XLO THEN OLO=1
    IF INDEX=XLM THEN OLM=1
    IF INDEX=XMD THEN OMD=1
    IF INDEX=XMH THEN OMH=1
    IF INDEX=XHI THEN OHI=1
    NEXT INDEX
    OLO=0 : OLM=0 : OMD=0 : OMH=0 : OHI=0
    @ INT_RETURN
    Russ
    N0EVC, xWB6ONT, xWN6ONT

    "Easy to use" is easy to say.

  7. #7
    Join Date
    Aug 2006
    Location
    Omaha, Nebraska USA
    Posts
    263


    Did you find this post helpful? Yes | No

    Default When all else fails . . . "blinky" test!

    Here it is:

    @ __config _CONFIG1, _FOSC_INTOSC & _WDTE_OFF & _MCLRE_OFF & _BOREN_OFF & _FCMEN_OFF
    @ __config _CONFIG2, _STVREN_OFF & _LVP_OFF

    OLO VAR PORTB.5
    OLM VAR PORTB.4
    OMD VAR PORTB.3
    OMH VAR PORTB.2
    OHI VAR PORTB.1

    DEFINE OSC 32

    ANSELA= %00011111
    ANSELB= %11000000
    CCP1CON=%00000000
    CCP2CON=%00000000
    CCP3CON=%00000000
    CCP4CON=%00000000
    OSCCON= %11110000
    TRISA = %01111111
    TRISB = %11000001

    MAIN:
    OLO=1 : PAUSE 1000 : OLO=0
    OLM=1 : PAUSE 1000 : OLM=0
    OMD=1 : PAUSE 1000 : OMD=0
    OMH=1 : PAUSE 1000 : OMH=0
    OHI=1 : PAUSE 1000 : OHI=0
    GOTO MAIN

    END

    No ADCs, no triac output, nothing but outputs low to high and back.

    Results:

    Each channel comes on in succession. The first four, however, than simply stay on. The fifth goes on and off exactly as you would expect.

    I even tried this on a "fresh" '1827. No difference.

    This is why I remain convinced that the problem hides in how I'm configuring something that affects B.2 through B.5 but permits B.1 to operate normally.
    Russ
    N0EVC, xWB6ONT, xWN6ONT

    "Easy to use" is easy to say.

  8. #8
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Try this Russ,

    Code:
    OLO     VAR LATB.5
    OLM     VAR LATB.4
    OMD     VAR LATB.3
    OMH     VAR LATB.2
    OHI     VAR LATB.1
    <br>
    DT

  9. #9
    Join Date
    Aug 2006
    Location
    Omaha, Nebraska USA
    Posts
    263


    Did you find this post helpful? Yes | No

    Default

    Sonofagun! It works. Thanks!

    What did we just do?

    And why was PORTB.1 working but not the others?
    Last edited by RussMartin; - 25th February 2010 at 22:46.
    Russ
    N0EVC, xWB6ONT, xWN6ONT

    "Easy to use" is easy to say.

  10. #10
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by RussMartin View Post
    Sonofagun! It works. Thanks!

    What did we just do?

    And why was PORTB.1 working but not the others?
    . . . and what is the "real" difference between LATB & PortB ?
    I am sensing a RMW issue . . . Thanks Darrel, in advance.
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

  11. #11
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    It's the old R-M-W issue (Read-Modify-Write).

    PIC's can't write to individual Pins in a PORT. It's not possible for the hardware to just set a pin high or low directly.
    It has to Read the entire PORT, Modify the bit it wants to change, then Write the value back to the Entire PORT.
    When it Reads the PORT, it actually reads the state of the Pins, not the state it was told to be in last.

    In your code ...
    Code:
    MAIN:
        OLO=1 : PAUSE 1000 : OLO=0
        OLM=1 : PAUSE 1000 : OLM=0
        OMD=1 : PAUSE 1000 : OMD=0
        OMH=1 : PAUSE 1000 : OMH=0
        OHI=1 : PAUSE 1000 : OHI=0
    GOTO MAIN
    The OLM=1 statement is executed immediately(125nS) after the OLO=0 statement.
    If the voltage on the OLO pin has not reached the level required to register a 0, then it reads OLO as 1 and writes that back to the PORT, ignoring that fact that you just told it to be 0.
    Capacitance on the Pin will increase the amount of time it takes to reach the requested state.
    Solderless breadboards can add quite a bit. LED's add some too.

    Just like the 18F's, the 16F1's have LATx (DATA LATCH) registers.
    If you use PORTB.0, it does the RMW on the PORT, then writes it to the LATB register which controls the pins state.

    If you write directly to LATB.0, it doesn't read the port first.
    It still does a read-modify-write, but what it reads is the LATB value (last requested state), not the state of the Pins.

    DO NOT! use HIGH, LOW, TOGGLE, or any other PBP commands like SERIN/OUT, PULSIN/OUT etc. with LATx.x as a Pin.
    It will cause big problems.

    But writing to the LATx bits directly with a 1 or 0 can eliminate the dreaded R-M-W problem.

    hth,
    DT

Similar Threads

  1. PBP Book
    By Bruce in forum Off Topic
    Replies: 83
    Last Post: - 4th October 2021, 12:55
  2. PBP, 16F1827, FSR, and Error 113
    By RussMartin in forum mel PIC BASIC Pro
    Replies: 11
    Last Post: - 13th January 2014, 09:04
  3. Can PBP & 16f88 really do 9600,8,E,1
    By retepsnikrep in forum mel PIC BASIC Pro
    Replies: 38
    Last Post: - 7th November 2010, 12:12
  4. Compiler differences between PBP 2.33 & 2.46
    By nikopolis in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 2nd May 2006, 19:01
  5. Newby- PBP wont compile for 18F (MPLAB)
    By jd76duke in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 17th December 2005, 23:30

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