Strange register interaction on 18F2431


Results 1 to 9 of 9

Threaded View

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

    Default Strange register interaction on 18F2431

    Hi guys,
    I've been banging my head against the wall for a couple of days now and I just can't seem to figure this out. Needless to say I need some fresh eyes and ideas so if you have a minute, bare with me.

    Background:
    Working on my DC servo motor control code for a 18F2431. I've got a bunch of user settings stored in EEPROM which are changeable via a serial terminal - nothing fancy. All of a sudden I notice that one of the settings, namely the one for the digital encoder filter on the 18F2431 (DFLTCON register) isn't displayed properly even after a fresh reprogram of the code and "stock" EEPROM data.

    Basically I've got this
    Code:
    EE_EncFilter DATA BYTE 48
    Enc_Filter VAR BYTE
    READ EE_EncFilter, Enc_Filter
    DFLTCON = Enc_Filter
    The read part is obviously in a subroutine where I read all the other variables stored in EEPROM. The problem is that when my PIC starts and I "print" all the settings the value in DFLTCON is NOT 48 and I've spent days trying to figure out what the heck is going on. And now comes the fun part....

    When the program starts it calls a subroutine named ResetServo which does a bit of housekeeping to set everyhing up. I do not (and I repeat DO NOT) write to DFLTCON in this subroutine, yet the value changes while execting that subroutine. I've tracked it down to the following, and most of what I show now is for debug purposes:
    Code:
      HSEROUT["A-", DEC EncFilter,"  ", DEC DFLTCON,13,10]
      GOSUB DoServo                                 ' Run servo loop to update everything and set the PWM.
      HSEROUT["B-", DEC EncFilter,"  ", DEC DFLTCON,13,10]
      op_Fault_Output = 1                           ' Reset the fault output.  
      HSEROUT["C-", DEC EncFilter,"  ", DEC DFLTCON,13,10]
      
      ' This is the offending line. Whenever this is commented out
      ' the overwriting of DFLTCON stops. WTF??
      PTCON1.7 = 1                                  ' Turn on PWM timebase.
      
      HSEROUT["D-", DEC EncFilter,"  ", DEC DFLTCON,13,10]
      op_Enable_Output = 1                          ' Enable bridge drive
      HSEROUT["E-", DEC EncFilter,"  ", DEC DFLTCON,13,10]  
      BlinkPattern = Pattern_OK
      
    RETURN
    Now, all the HSEROUT stuff is just me trying to figure when and where DFLTCON changes, hence the letters A to E.
    I can call the ResetServo routine manually over the serial console and if I do that, as the code is shown above, here's what I get for a couple of "resets" (with comments is red):
    Code:
    A-48  63   (My variable is 48 but DFLTCON is NOT 48 for some reason and the bloody thing is being changed.....)
    B-48  63
    C-48  63
    D-48  65
    E-48  67
    Servo RESET!
    Y-Encoder filter: 2.5MHz   (Here I'm using the console to change the setting BACK to the default 48)
    A-48  48
    B-48  48
    C-48  48              (At this point both my variable and DFLTCON IS 48 as it should)
    D-48  50              (But now it's changed.)
    E-48  52              (And it's changed again)
    Servo RESET!
    A-48  53           (and it's changed)
    B-48  53
    C-48  53
    D-48  53
    E-48  55             
    Servo RESET!
    A-48  56  
    B-48  56
    C-48  56
    D-48  56
    E-48  58 
    Servo RESET!
    A-48  59
    B-48  59
    C-48  59
    D-48  59
    E-48  61
    Servo RESET!
    A-48  62
    B-48  62
    C-48  62
    D-48  64
    E-48  65
    Servo RESET!
    As you can see, my variable (Enc_Filter) stays intact but the content of DFLTCON is somehow changing.

    Oh, you're overwriting it somewhere in an ISR or whatever I here you say....
    My code base consists of multiple files and I've searched for DFLTCON thru each and every one of them. I'm writing to DFLTCON at exactly TWO places. One is at start up, where I'm reading the value stored in EEPROM into my variable (Enc_Filter) and writing that to DFLTCON. The other is in the code for the console where I can change the value as shown above. That's it. Yet the content of DFLTCON is somehow changing "on its own".

    Now, if I comment out the line where I'm enabling the PWM timebase (PTCON1.7 = 1) the problem dissapears (or is masked) and whatever is written to DFLTCON at startup (or when Enc_Filter is changed) stays there:
    Code:
    A-48  48
    B-48  48
    C-48  48
    D-48  48
    E-48  48
    Servo RESET!
    A-48  48
    B-48  48
    C-48  48
    D-48  48
    E-48  48
    Servo RESET!
    A-48  48
    B-48  48
    C-48  48
    D-48  48
    E-48  48
    Servo RESET!
    A-48  48
    B-48  48
    C-48  48
    D-48  48
    E-48  48
    Servo RESET!
    A-48  48
    B-48  48
    C-48  48
    D-48  48
    E-48  48
    Servo RESET!
    A-48  48
    B-48  48
    C-48  48
    D-48  48
    E-48  48
    Servo RESET!
    A-48  48
    B-48  48
    C-48  48
    D-48  48
    E-48  48
    Servo RESET!
    A-48  48
    B-48  48
    C-48  48
    D-48  48
    E-48  48
    Servo RESET!
    A-48  48
    B-48  48
    C-48  48
    D-48  48
    E-48  48
    Servo RESET!
    A-48  48
    B-48  48
    C-48  48
    D-48  48
    E-48  48
    Servo RESET!
    A-48  48
    B-48  48
    C-48  48
    D-48  48
    E-48  48
    Servo RESET!
    Setttings saved
    A-48  48
    B-48  48
    C-48  48
    D-48  48
    E-48  48
    Servo RESET!
    A-48  48
    B-48  48
    C-48  48
    D-48  48
    E-48  48
    Servo RESET!
    A-48  48
    B-48  48
    C-48  48
    D-48  48
    E-48  48
    Servo RESET!
    A-48  48
    B-48  48
    C-48  48
    D-48  48
    E-48  48
    Servo RESET!
    A-48  48
    B-48  48
    C-48  48
    D-48  48
    E-48  48
    Servo RESET!
    I can't for the life of me see why writing to PTCON1.7 in itself would cause this. I would have thought it was something in the subroutine DoServo (which isn't exectued when the PWM timebase isn't running) that's ACTUALLY causing it. However, (as you can see) I AM Calling DoServo manually between outputs 'A' and 'B' in the code above and DFLTCON is NEVER changed at that point so nothing in DoServo is accidently accessing DFLTCON as far as I can see.

    On top of that I've tried calling DoServo in a loop, from my Main routine (ie, the timebase isn't running and therefor the ISR that's normally calling DoServo isn't executed) but DoServo is called at 1ms intervals anyway but again, DFLTCON is left alone at whatever value it's set to. It's ONLY when that line (PTCON1.7=1) is "enabled" that the problem occurs.

    Any ideas what might be going on here?

    /Henrik.

    EDIT: Oh, and remember, it's not the variable in RAM that's changing (like an array accessed outside its bounds or something).
    The variable stays intact, it's the actual SFR at location F60h that's changing. I've crossreferenced the datasheet against the MPASM .INC file and the adresses for DFLTCON and PTCON1 both seems correct.
    Last edited by HenrikOlsson; - 26th December 2014 at 16:03.

Similar Threads

  1. New user: port configuration problem/unexpected interaction/16F887
    By Experimenter in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 14th March 2014, 20:25
  2. 18f2431 QEI Help
    By krism13 in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 5th June 2013, 15:26
  3. pwm 18f2431
    By robertpeach in forum mel PIC BASIC Pro
    Replies: 20
    Last Post: - 21st August 2009, 08:55
  4. interaction between Bluetooth and PIC MCU
    By veenadari in forum Bluetooth
    Replies: 1
    Last Post: - 23rd June 2009, 15:03
  5. HPWM and A to D interaction question 18F252
    By tcbcats in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 10th May 2006, 03:50

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