How long does this take to execute


Closed Thread
Results 1 to 24 of 24

Hybrid View

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


    Did you find this post helpful? Yes | No

    Default Re: How long does this take to execute

    The correct 18F would allow you to run at 64MHz while I believe the 16F tops out at 32MHz but I might be wrong, haven't verified. Another benefit is that an 18F series device will allow you to have a single 512byte wide array for your DMX data. This doesn't work in the 16F series (max array length is 96). I'm not saying it can't be done on a 16F series just that I think you need some good reasons for selecting a 16F series chip over an 18F series device.

    DT-Ints (Instant interrupts) is available for both 16F and 18F series so that doesn't matter but for this application I'm not entirely sure they're the correct aproach, especially if you're writing the ISR in PBP (which you are since you're using DT-Ints.....). The reasom I'm not too sure they're the right aproach is the overhead they add due to the system variable save/restore it has to do each time an interrupt occurs. This takes dozens and dozens of instruction cycles and at an interrupt rate of 25kHz it's going to eat away you're processing power.

    With that said there are ways around that but they're not straight forward and you really need to know what you're doing so instead I'd look at one large loop type program calling tight subroutines with known execution time(s) and keep feeding the UART in between. Like,

    * Feed the UART - OK, we've got 40us to do something useful.....
    * Start the ADC - it'll take xx us to complete - go do something else....
    * Read a pin
    * Do something with it
    * Write a pin
    * Wait for the UART, Feed it.
    * ADC done? Get result.
    * Start ADC, next channel.

    And so on.

    An interrupt driven sender would be cleaner and if "all" the ISR is doing is indexing a 512 byte long array then examining the generated code and manually saving ONLY the system variables actually USED by the ISR will make DT-Ints work a lot faster but as I said, it's tricky and a very sensitive and delicate way of doing it from a code maintanence and expansion perspective.

    /Henrik.

  2. #2
    Join Date
    Nov 2003
    Posts
    98


    Did you find this post helpful? Yes | No

    Default Re: How long does this take to execute

    incredibly helpful!, thanks so much again Henrik
    want a job ?

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


    Did you find this post helpful? Yes | No

    Default Re: How long does this take to execute

    Glad I could help.
    As for the job, I'm fortunate to have one that pays the bills but it's not as fun as developing PBP code so if you're serious about that then drop me PM and we can talk :-)

  4. #4
    Join Date
    Nov 2003
    Posts
    98


    Did you find this post helpful? Yes | No

    Default Re: How long does this take to execute

    it almost makes want to think about external hardware UART that has a 512 or 1k buffer, but i guess getting the data into that would be an issue too
    are there such things ?

  5. #5
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,624


    Did you find this post helpful? Yes | No

    Default Re: How long does this take to execute

    Took a quick look at the Digikey and of the chips they've got the largest FIFO buffer available is 256bytes. I think you need at least 1k to really benefit from an external UART - and I think the interface would have to be parallel or really fast SPI or you'll spend most of the time sending data to the UART just as you would when using the on chip UART.

    What would be ideal is a PIC with DMA but that feature doesn't exist in the 16F or 18F series. But really, this should be totally doable with a PIC and on chip UART but it'll take some careful planning.

    /Henrik.

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


    Did you find this post helpful? Yes | No

    Default Re: How long does this take to execute

    Hi,
    I've played around with this a bit, trying to get a feel for what's possible and what's not. It's actually not as bad as I originally thought - but not that great either.

    A 18F25K20 running at 64MHz, interrupting every 44us using DT-Ints slows down the PIC a fair bit. A 100ms pause in the main routine becomes 185ms in reality, a CPU load of 54%. At 32MHz it'll probably not work at all since all avilable CPU cycles will be consumed by the ISR and (mostly) the overhead.

    The good news is that it does work using DT-INTS if you can run at 64MHz. The bad news is of course that any commands used in the main routine, that relies on soft timing, will be WAY off.

    /Henrik.

  7. #7
    Join Date
    Nov 2003
    Posts
    98


    Did you find this post helpful? Yes | No

    Default Re: How long does this take to execute

    well now you've done it Henrik

    i was just warming up to the idea of doing everything in a polled loop and carefully squeezing activities in

    re DT-Ints when you say "soft timing" do you mean things like counting the number of times through the Main Loop (or sub loop) to create a crude counter / timer ?
    i do that a lot for certain imprecise timing requirements, yeah i know it is not good practice and has many down sides but it is good enough for many things

    or do you mean things like PAUSE and PAUSEus ?
    or both ?

    my plan at the moment is to use 18F25K22 (Charles has been most supportive!) and it will do 64Mhz and does 5V which the '20 does not (big advantage as DMX transceiver i am told must be 5V due to custom and practice even though there are 3.3V RS485 transceiver chips out there)

    as to OSC, the way i read the data sheet i can get 64MHz using 4X PLL either with INTOSC or XTAL at 16MHz
    do you think 1% is good enough for RS-485 250k baud comms ?
    my instinct was no and at this point am not inclined to get into calibration schemes (how good do they get?)

Similar Threads

  1. Unable to execute mpasmwin
    By oldmainframer in forum General
    Replies: 3
    Last Post: - 18th December 2016, 00:01
  2. Interrupt won't execute.
    By bison_bloke in forum mel PIC BASIC Pro
    Replies: 23
    Last Post: - 26th March 2010, 16:46
  3. Replies: 5
    Last Post: - 24th February 2009, 19:55
  4. Proteus Execute Error
    By pramarn in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 6th October 2006, 09:51
  5. SEROUT2 takes 1400ms to execute?
    By droptail in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 16th March 2006, 18:08

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