Multi-Threading


Closed Thread
Results 1 to 23 of 23

Thread: Multi-Threading

Hybrid View

  1. #1
    Join Date
    Jul 2003
    Posts
    2,358


    Did you find this post helpful? Yes | No

    Default

    Ted stop winding people up that are trying to help you. Folks give up their time for free around here. If you don't like an answer then be polite, say "Thank You" to acknowledge the time they may have devoted to potentially a lost cause, and move on.

    In case you're not aware... the short answer to your question at Post #1 is Yes.

    If yor PIC has ADC, Comparators, CCPM, USART etc the you can SIMULTANEOUSLY perform any or all of those functions whilst doing something else altogether AT THE SAME INSTANT IN TIME. Go do a forum SEARCH, this has been discussed before.

    Alternatively you can TIME-SLICE your code... in the simplest form, using your flashing LED for example, say the LED is flashing at a 2Hz rate, you can switch ON your LED, then go do something else for 250mS before you need to devote an instruction to switching it OFF Gee... at 4MHz, that's a shed load of instructions you can carry out whilst that LED is ON, and again when it's OFF. To the casual observer, it will appear as if the PIC is doing multiple tasks.

  2. #2


    Did you find this post helpful? Yes | No

    Default

    How would you use the ADCIN command to read the value of a pot while simultaneously doing something else?

  3. #3
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    Setup a hardware peripheral like capture, hardware PWM, counter, UART, etc and enable
    it. They will all run simultaneously in the background while you're sampling the A/D input.
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  4. #4
    Join Date
    Sep 2008
    Posts
    19


    Did you find this post helpful? Yes | No

    Default

    Hello. I am using the instant interrupt routine. I also posess a servo motor like ted,
    so I wand to start a pulsout every 20ms. I did this in the tmr0-interrupt routine(tmr0
    initialized by OPTION_REG = 1) I am using a 20Mhz quarz.

    I think: 20 / 4 = 5Mhz. OPTION_REG means prescaler = 1:1. Means 1/(5,000,000) equals 0.2us.

    TMR0 = 8Bit => 256 * 0.2us = 51.2us.

    So every 51.2us there will be an interrupt. So

    20,000 / 51.2 = 390.625 = 391. So as soon as the interrupt will have occurred 391 times 20ms
    should have been passed. I wrote
    Code:
      main:
       '...do xyz
       counter = 0
       END
    
      IRRoutine:
       IF counter = 391 THEN
        pulsout servo, duration
       ENDIF
       IF counter > 391 THEN
        counter = 0
       ENDIF
       IF counter < 391 THEN
        counter = counter + 1
       ENDIF
       @ INT_RETURN
    But the servo is choppy. What is wrong?
    Last edited by Security; - 2nd September 2008 at 04:29.

  5. #5
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    How does this work?
    Code:
      main:
       '...do xyz
       counter = 0
       END
    
      IRRoutine:
       IF counter => 391 THEN
        pulsout servo, duration
        counter = 0
       ELSE
        counter = counter + 1
       ENDIF
       @ INT_RETURN

  6. #6
    Join Date
    Sep 2008
    Posts
    19


    Did you find this post helpful? Yes | No

    Default

    Well.

    But the servo is still choppy.

    I found the reason: Option_reg was wrong. I had a prescaler of 2:1.
    Last edited by Security; - 2nd September 2008 at 06:00.

Similar Threads

  1. Multi Slow speed PWM and Instant Interrupts
    By DaveC3 in forum mel PIC BASIC Pro
    Replies: 8
    Last Post: - 2nd November 2010, 12:50
  2. multi functions button press
    By malwww in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 27th May 2009, 00:12
  3. 16-48 pin Multi slow PWM
    By krohtech in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 28th March 2009, 03:28
  4. Multi diomencinal array
    By morphyn in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 11th February 2009, 21:19
  5. parallel port multi pic programmer?
    By SuB-ZeRo in forum Schematics
    Replies: 8
    Last Post: - 25th June 2005, 10:20

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