12F683, 12LF1840 - Port ON/OFF speeds are different!


Closed Thread
Results 1 to 18 of 18
  1. #1
    Join Date
    Feb 2013
    Posts
    1,078

    Default 12F683, 12LF1840 - Port ON/OFF speeds are different!

    Hello.

    I'm building an push-pull converter driver using these chips. The code is as follows:

    Code:
    'PUSH PULL DRIVER
    
    ANSELA = %00000000  'TURN OFF ANALOG  
    TRISA=%00000000     'SET PORTS TO OUTPUT
    OSCCON = %11111111  'SET INTOSC TO 32MHZ
    
    
    tavuka:
    
    PORTA.2=1
    PORTA.2=0
    PORTA.4=1
    PORTA.4=0
    
    GOTO TAVUKA
    The problem is, that measured port OFF times are longer than ON times, as you can see on attached scope:

    Name:  hugedelay.jpg
Views: 752
Size:  27.0 KB

    Any ideas how to fix this?

  2. #2
    Join Date
    May 2013
    Location
    australia
    Posts
    2,383


    Did you find this post helpful? Yes | No

    Default Re: 12F683, 12LF1840 - Port ON/OFF speeds are different!

    OSCCON = %11111111 'SET INTOSC TO 32MHZ
    looks wrong
    OSCCON = %11110000 'SET INTOSC TO 32MHZ would be more appropriate assuming int osc and pll

    porta.x = y on a 12f1840@32mhz is just asking for trouble use lata.x=y

  3. #3
    Join Date
    Feb 2013
    Posts
    1,078


    Did you find this post helpful? Yes | No

    Default Re: 12F683, 12LF1840 - Port ON/OFF speeds are different!

    Yes, config is wrong, but problem is same at ANY clock speed.

    Tried with LATA - no difference. ON time is about 220ns, OFF time is about 760ns. In terms of PWM, this means 50% duty, so another 50% is simply wasted.

  4. #4
    Join Date
    Feb 2013
    Posts
    1,078


    Did you find this post helpful? Yes | No

    Default Re: 12F683, 12LF1840 - Port ON/OFF speeds are different!

    As I see, this is caused by loop, which returns program to beginning.

    For example, I've tried to lengthen code by repeating commands 4 times without using loop, and 4 pulses are correct.

  5. #5
    Join Date
    Sep 2009
    Posts
    737


    Did you find this post helpful? Yes | No

    Default Re: 12F683, 12LF1840 - Port ON/OFF speeds are different!

    I hope that you are kidding with us...
    Here is your code explained:
    tavuka:
    PORTA.2=1'<turn on PORTA.2, need 4 osc clock to do that, then next instruction
    PORTA.2=0'<turn off PORTA.2 need 4 osc clock to do that, then next instruction
    PORTA.4=1'<4 clock to do this, but it doesn't do anything with PORTA.2
    PORTA.4=0'<4 clock to do this, but it doesn't do anything with PORTA.2
    GOTO TAVUKA '<4 or 8 clocks(can remember) to do this, but it doesn't do anything with PORTA.2
    So when you count all clock, you have 4 osc clock long high state on PORTA,2, and 16 clock low state on PORTA.2.
    Similar situation is with PORTA.4...
    Program execute exactly what you are tell, Not what you want...

  6. #6
    Join Date
    Feb 2013
    Posts
    1,078


    Did you find this post helpful? Yes | No

    Default Re: 12F683, 12LF1840 - Port ON/OFF speeds are different!

    Even if code is like this:

    Code:
    HEAD:
    PORTA.2=1
    PORTA.2=0
    GOTO HEAD
    the "goto" occupies much more time. Is there a way to shorten it?

  7. #7
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,518


    Did you find this post helpful? Yes | No

    Default Re: 12F683, 12LF1840 - Port ON/OFF speeds are different!

    No, there's not way to shorten the execution time (in instruction cycles that is) of a GOTO. What you can do is to "lengthen" the time of the other instructions.
    Code:
    Head:
    PortA.2 = 1
    @ NOP   ' Two nops to compensate for the GOTO
    @ NOP
    PortA.2 = 0
    GOTO Head
    Obviously this will also change the frequency.

    /Henrik.

  8. #8
    Join Date
    Dec 2007
    Location
    Finland
    Posts
    191


    Did you find this post helpful? Yes | No

    Default Re: 12F683, 12LF1840 - Port ON/OFF speeds are different!

    How about if you toggle pin in loop?

    Code:
    HEAD:
    TOGGLE PORTA.2
    GOTO HEAD

  9. #9
    Join Date
    Feb 2013
    Posts
    1,078


    Did you find this post helpful? Yes | No

    Default Re: 12F683, 12LF1840 - Port ON/OFF speeds are different!

    I don't want to "lengthen" time, because it significantly lowers the frequency, from about 1mhz to 200khz, which is bad. I've found a partial workaround - I've inserted

    Code:
    PORTA.2=1
    PORTA.2=0
    PORTA.4=1
    PORTA.4=0
    16 times, so now having about 90% duty cycle, which is ok.

    But, is there a way to fix this otherwise?

    Try 18 series PIC, or 24 series?

  10. #10
    Join Date
    Oct 2009
    Location
    Utah, USA
    Posts
    427


    Did you find this post helpful? Yes | No

    Default Re: 12F683, 12LF1840 - Port ON/OFF speeds are different!

    Have you considered doing this in assembly??
    Dwight
    These PIC's are like intricate puzzles just waiting for one to discover their secrets and MASTER their capabilities.

  11. #11
    Join Date
    Sep 2009
    Posts
    737


    Did you find this post helpful? Yes | No

    Default Re: 12F683, 12LF1840 - Port ON/OFF speeds are different!

    It's same thing in ASM.
    ASM
    tavukaASM:
    BSF PORTA,2
    BCF PORTAM2
    BSF PORTA,4
    BCF PORTA,4
    GOTO tavukaASM
    ENDASM

    That is ASM code equivalent of his PBP code.
    Still same situation....
    Last edited by pedja089; - 3rd February 2015 at 21:09.

  12. #12
    Join Date
    Dec 2007
    Location
    Finland
    Posts
    191


    Did you find this post helpful? Yes | No

    Default Re: 12F683, 12LF1840 - Port ON/OFF speeds are different!

    Would it be easier to do this with PWM module? With 32MHz you can reach 4MHz output frequency and accurate duty cycle.
    I think these PIC's have just one PWM module. If that is not enough, then select other which have more PWM outputs.
    At least, trials can be run with your current PIC's.
    Last edited by Gusse; - 3rd February 2015 at 21:50.

  13. #13
    Join Date
    Feb 2013
    Posts
    1,078


    Did you find this post helpful? Yes | No

    Default Re: 12F683, 12LF1840 - Port ON/OFF speeds are different!

    Well, I asked that before...

    I use 2 channels as you can see from scope, and I need to have adjustable dead time between outputs, to avoid short circuit. Is it possible to synchronise 2 PWM generators in that way?

  14. #14
    Join Date
    Dec 2007
    Location
    Finland
    Posts
    191


    Did you find this post helpful? Yes | No

    Default Re: 12F683, 12LF1840 - Port ON/OFF speeds are different!

    I think that you will not be able to do phase shift (delay) between 2 PWM outputs in same PIC. With 2 PIC's this might bee possible.

    If your system is so time critical that GOTO-command will generate problems then how you will monitor and adjust outputs?
    Therefore I don't see any other options than using HW modules (PWM) and PIC code just monitor and control HW module(s).

  15. #15
    Join Date
    Sep 2009
    Posts
    737


    Did you find this post helpful? Yes | No

    Default Re: 12F683, 12LF1840 - Port ON/OFF speeds are different!

    With another pic, it can be done easy.

    PIC18F14K22 have everything what you need:
    Enhanced Capture/Compare/PWM (ECCP)
    module:
    - One, two or four PWM outputs
    - Selectable polarity
    - Programmable dead time
    - Auto-shutdown and Auto-restart
    - PWM output steering control
    And all that controlled from comparators outputs.
    If comparator output is low or high(selectable) pwm outpu can go to some state, high or low.
    You can turn on/off hysteresis on comparators, etc...
    Just read this 404 pages and you will know everything you need

  16. #16
    Join Date
    Feb 2013
    Posts
    1,078


    Did you find this post helpful? Yes | No

    Default Re: 12F683, 12LF1840 - Port ON/OFF speeds are different!

    Another guess is that PIC18F14K22 won't be available in SOIC-8....

  17. #17
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,518


    Did you find this post helpful? Yes | No

    Default Re: 12F683, 12LF1840 - Port ON/OFF speeds are different!

    Take a look at the 12F1501, it might do what you want and comes in 8pin package.

  18. #18
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,611


    Did you find this post helpful? Yes | No

    Default Re: 12F683, 12LF1840 - Port ON/OFF speeds are different!

    the 1840 in ECCP half bridge mode looks to be fine too, no ???

    Alain
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

Similar Threads

  1. Pulsin ir receiver and osc speeds
    By jimseng in forum mel PIC BASIC Pro
    Replies: 10
    Last Post: - 24th March 2012, 20:12
  2. 18F2520 - problem configuring fuse for port B as digital port.
    By hwhisperer in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 11th October 2010, 12:41
  3. LCD R/S works on Port A but not Port B
    By TDonBass in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 10th February 2009, 13:41
  4. Dual clock speeds on a PIC
    By BrianT in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 24th January 2008, 02:34
  5. Duplicating port input to port output
    By lwindridge in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 26th April 2004, 22:43

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