Ports interacting?? 16F1826


Closed Thread
Results 1 to 12 of 12
  1. #1
    Join Date
    Jan 2009
    Posts
    50

    Default Ports interacting?? 16F1826

    OK, any ideas on this one? This is my code:


    Code:
    ;----[16F1826 Hardware Configuration]-------------------------------------------
    #IF __PROCESSOR__ = "16F1826"
      #DEFINE MCU_FOUND 1
    #CONFIG
    cfg1 = _FOSC_HS               ; HS Oscillator, High-speed crystal/resonator connected between OSC1 and OSC2 pins
    cfg1&= _WDTE_OFF              ; WDT disabled
    cfg1&= _PWRTE_OFF             ; PWRT disabled
    cfg1&= _MCLRE_OFF             ; MCLR/VPP pin function is digital input
    cfg1&= _CP_OFF                ; Program memory code protection is disabled
    cfg1&= _CPD_OFF               ; Data memory code protection is disabled
    cfg1&= _BOREN_OFF             ; Brown-out Reset disabled
    cfg1&= _CLKOUTEN_OFF          ; CLKOUT function is disabled. I/O or oscillator function on the CLKOUT pin
    cfg1&= _IESO_OFF              ; Internal/External Switchover mode is disabled
    cfg1&= _FCMEN_OFF             ; Fail-Safe Clock Monitor is disabled
      __CONFIG _CONFIG1, cfg1
    
    cfg2 = _WRT_OFF               ; Write protection off
    cfg2&= _PLLEN_OFF             ; 4x PLL disabled
    cfg2&= _STVREN_OFF            ; Stack Overflow or Underflow will not cause a Reset
    cfg2&= _BORV_HI               ; Brown-out Reset Voltage (Vbor), high trip point selected.
    cfg2&= _LVP_OFF               ; High-voltage on MCLR/VPP must be used for programming
      __CONFIG _CONFIG2, cfg2
    
    #ENDCONFIG
    
    #ENDIF
    
    ;----[Verify Configs have been specified for Selected Processor]----------------
    ;       Note: Only include this routine once, after all #CONFIG blocks
    #IFNDEF MCU_FOUND
      #ERROR "No CONFIGs found for [" + __PROCESSOR__ +"]"
    #ENDIF
    
    DEFINE OSC 4
    TRISA = %00000000
    TRISB = %00000000
    
    Low PORTA.1 
    Low PORTA.4 
    
    PORTA.1 = 1
    pause 1000
    PORTA.4 = 1
    pause 1000
    PORTA.4 = 0
    PORTA.1 = 1
    end
    :
    When I run the code, and LED attached to PORTA.1 goes ON as expected. However, when I code PORTA.4 = 1, then PORTA.1 goes low and the LED turns OFF!

    After the second 'pause 100', then PORTA.1 = 1 does indeed turn the LED back ON.

    Are these two ports interacting in some way that I am not aware of?

    Help! :-)

  2. #2
    Join Date
    Jan 2009
    Posts
    50


    Did you find this post helpful? Yes | No

    Default Re: Ports interacting?? 16F1826

    Disregard the above thread! :-)

    BTW, how can I delete a thread??

  3. #3
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,521


    Did you find this post helpful? Yes | No

    Default Re: Ports interacting?? 16F1826

    Hi,
    I don't think you can delete a thread and I don't think you should, but that's my personal thoughts of course.
    Instead post what the problem was, how you found it and how you solved it. That way others can read about it and perhaps learn something - which is what a forum like this is all about.

    Was it perhaps a R-M-W issue?

    /Henrik.

  4. #4
    Join Date
    Jan 2009
    Posts
    50


    Did you find this post helpful? Yes | No

    Default Re: Ports interacting?? 16F1826

    Quote Originally Posted by HenrikOlsson View Post
    Hi,
    I don't think you can delete a thread and I don't think you should, but that's my personal thoughts of course.
    Instead post what the problem was, how you found it and how you solved it. That way others can read about it and perhaps learn something - which is what a forum like this is all about.

    Was it perhaps a R-M-W issue?

    /Henrik.
    Good point Henrik! I thought it was a bad circuit board, that is why I thought the thread should be forgotten. However, it ended up being a bad LED. :-)

  5. #5
    Join Date
    May 2013
    Location
    australia
    Posts
    2,389


    Did you find this post helpful? Yes | No

    Default Re: Ports interacting?? 16F1826

    found this video on the microchip site about r-w-m issues , its a "c" demo but the physical cause of the r-w-m problem is explained in a easy to follow way and is worth looking at.
    http://www.microchip.com/webinars.mi...cName=en556253

  6. #6
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,521


    Did you find this post helpful? Yes | No

    Default Re: Ports interacting?? 16F1826

    > However, it ended up being a bad LED. :-)

    Wow, you're out of luck with your LEDs aren't you? Or is this proplem the same as the other thread where you had busted LED - and the thread on MELABS forum?

    Anyway, glad you've figured it out!

    /Henrik.

  7. #7


    Did you find this post helpful? Yes | No

    Default Re: Ports interacting?? 16F1826

    Keep in mind

    All of the new "Enhanced 12FXXXX and 16FXXXX" parts use the LATx register for changing the output state. Portx register for reading the input state.

  8. #8
    Join Date
    Jan 2009
    Posts
    50


    Did you find this post helpful? Yes | No

    Default Re: Ports interacting?? 16F1826

    Quote Originally Posted by HenrikOlsson View Post
    > However, it ended up being a bad LED. :-)

    Wow, you're out of luck with your LEDs aren't you? Or is this proplem the same as the other thread where you had busted LED - and the thread on MELABS forum?

    Anyway, glad you've figured it out!

    /Henrik.
    Ha!! Nope, same issue on several sites looking for clues. At least I am not going too far mad!

  9. #9
    Join Date
    Jan 2009
    Posts
    50


    Did you find this post helpful? Yes | No

    Default Re: Ports interacting?? 16F1826

    Quote Originally Posted by mark_s View Post
    Keep in mind

    All of the new "Enhanced 12FXXXX and 16FXXXX" parts use the LATx register for changing the output state. Portx register for reading the input state.
    I would like to know more about "LATs". Know zero. Does PIC Basic Pro support these? Tell me more please! Sounds interesting!!

  10. #10
    Join Date
    Jan 2009
    Posts
    50


    Did you find this post helpful? Yes | No

    Default Re: Ports interacting?? 16F1826

    Quote Originally Posted by HenrikOlsson View Post
    Hi,
    I don't think you can delete a thread and I don't think you should, but that's my personal thoughts of course.
    Instead post what the problem was, how you found it and how you solved it. That way others can read about it and perhaps learn something - which is what a forum like this is all about.

    Was it perhaps a R-M-W issue?

    /Henrik.
    I also see that I probably ran into a R-M-W issue as well...or got it to work in an unstable state. Good info!!!!!!! Thanks!!! Again, new to R-M-W. Cool.

  11. #11


    Did you find this post helpful? Yes | No

    Default Re: Ports interacting?? 16F1826

    Quote Originally Posted by SOTASOTA View Post
    I would like to know more about "LATs". Know zero. Does PIC Basic Pro support these? Tell me more please! Sounds interesting!!
    Hi,

    Lat is short for latch. I not a good communicator, so I can't explain it better than the data sheet. The main thing to understand is that on the older pic16's we used portx.x to read or write to a pin. This could lead to R-M-W problem that Henrik pointed out. On the new pic16fxxxx,pic12fxxxx, pic18, dspic, and pic32 we use Latx.x to change the output. Portx.x is used to read a port pin. So on the above code you provided.
    Code:
    Low PORTA.1 
    Low PORTA.4 
    
    PORTA.1 = 1
    pause 1000
    PORTA.4 = 1
    pause 1000
    PORTA.4 = 0
    PORTA.1 = 1
    This is how it should be, as someone pointed out in the other thread.
    Code:
    Low LATA.1 
    Low LATA.4 
    
    LATA.1 = 1
    pause 1000
    LATA.4 = 1
    pause 1000
    LATA.4 = 0
    LATA.1 = 1
    Here a similar thread

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

  12. #12
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,521


    Did you find this post helpful? Yes | No

    Default Re: Ports interacting?? 16F1826

    Hi,
    Just to clarify, writing to the PORT registers still works on ALL devices. The thing is that newer devices can run much faster (64MHz) compared to older (20MHz) so the risk of running into RMW issues are bigger.

    Using the LAT register (when available) for outputs is a good idea. However, I'm not entirely sure that using HIGH/LOW (or any high level pin/port command) on LAT works, actually I don't think it does, but I'd be happy to stand corrected on that.

    /Henrik.

Similar Threads

  1. 16F1826 cannot get MCLR to act as an INPUT
    By SOTASOTA in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 13th February 2014, 02:31
  2. Help to setup ADC for 16F1826
    By SOTASOTA in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 12th February 2014, 00:06
  3. ADC problems with a 16F1826 chip
    By alec in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 1st September 2012, 22:09
  4. Using two AtoD channels - they're interacting?!
    By HankMcSpank in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 13th April 2010, 19:21
  5. LCD ports
    By electronicsuk in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 20th February 2004, 02:26

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