Strange Behavior 12F1822


Closed Thread
Results 1 to 11 of 11

Hybrid View

  1. #1
    Join Date
    Jan 2009
    Posts
    17


    Did you find this post helpful? Yes | No

    Default Re: Strange Behavior 12F1822

    Hello,
    did a wrong measurement yesterday.
    Only Ports RA0 and RA2 have the spikes.
    All other ports are working correct at 16MHz and 32MHz.
    I added DEFINE OSC 32 - nothing changed.
    I replaced the aliases for the LED with direct ports in the programm (PORTA.0=1) - nothing changed.
    Now i'll search for RMW as recommended.

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


    Did you find this post helpful? Yes | No

    Default Re: Strange Behavior 12F1822

    Hi,
    Replacing the alias with direct port adress doesn't make any difference. What I suggested was to write to the LAT register instead of the PORT register, ie:
    LATA.0=1 instead of PORTA.0=1
    or created the alias pointing on the LAT register instead of the PORT regsiter:
    LED1 VAR LATA.0 instead of LED1 VAR PORTA.0

  3. #3
    Join Date
    Jan 2009
    Posts
    17


    Did you find this post helpful? Yes | No

    Default Re: Strange Behavior 12F1822

    Hi Henrik,
    thank you for your great help, writing the LAT register did the job. Signals are perfect now.
    I also found now a second solution for the problem - using the "high porta.0" and "low porta.0" works also.
    Thank you very much,
    best regards
    Norbert

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


    Did you find this post helpful? Yes | No

    Default Re: Strange Behavior 12F1822

    Hi,
    HIGH PORTB.0 works because it takes longer to execute than PORTB.0=1. This is because it also sets the TRIS register each time they executes.
    In this case the extra delay introduced by the inherit write to TRIS was enough to allow the voltage on the pin to rise above the threshold within time to avoid the RMW issue. But there's no guarantee it'll work the next time as it depends on the oscillator speed (as you've noticed), load on the pin, PCB trace capacitance and so on. For devices which have both a PORT and a LAT register you really should write to LAT to avoid these kind of RMW issues.

    Good luck!
    /Henrik

  5. #5
    Join Date
    Jan 2006
    Location
    Istanbul
    Posts
    1,185


    Did you find this post helpful? Yes | No

    Default Re: Strange Behavior 12F1822

    Quote Originally Posted by nobner View Post
    Hi Henrik,
    thank you for your great help, writing the LAT register did the job. Signals are perfect now.
    I also found now a second solution for the problem - using the "high porta.0" and "low porta.0" works also.
    Thank you very much,
    best regards
    Norbert

    Norbert,

    So, your code is working as expected without having DEFINE OSC X in your code block?


    If you are using 32MHz or 16 MHz or 8Mhz you need to tell the compiler at what speed it is running.
    Otherwise, it will compile for 4Mhz.

    For High and Low commands, it may not reflect the difference;
    But, if you are using PWM commands especially something like MIBAM, there will be serious difference.

    For example, if you set your OSCCON register to 8Mhz and enable PLL (that gives 32Mhz), as you did, but do not have DEFINE OSC 32 , the chip will run at 32Mhz, but the compiler will compile your code for 4Mhz as default.

    If I am wrong with anything with my sayings here, someone please correct me.
    "If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte

  6. #6
    Join Date
    Jan 2009
    Posts
    17


    Did you find this post helpful? Yes | No

    Default Re: Strange Behavior 12F1822

    Hi Sayzer,
    i tried with DEFINE OSC 32 and without DEFINE OSC 32, it made no visible difference in my application,
    PWM-frequency is the same.
    Finally I put DEFINE OSC 32 in my code, everything works fine.
    Thanks to all for your support.

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