Need help with Counter/Timer application


Closed Thread
Results 1 to 22 of 22

Hybrid View

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


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Melanie
    A PIC already multi-tasks...
    That's because it's got the HARDWARE to do it. However, until we get multi-core PICs, it can only execute one software instruction at a time. ....

    That is what I meant.

    For example:

    Code:
    While PORTB.0 = 0 
      do a kind of loop here...
    wend
    
    While PORTA.0 = 1
      do another kind of loop here...
    wend

    These two while statements can not execute et the same time. This is just an example.

    BTW; humans also multi-task albeit most of us do not even realize that we do.


    ---------------
    "If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte

  2. #2
    Join Date
    Feb 2003
    Posts
    432


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by sayzer
    That is what I meant.

    For example:

    Code:
    While PORTB.0 = 0 
      do a kind of loop here...
    wend
    
    While PORTA.0 = 1
      do another kind of loop here...
    wend

    These two while statements can not execute et the same time.

    ---------------
    True... because of the way the program is written it will repeatedly service the PortB loop until such time as PORTB.0 = 1

    If you want BOTH loops to be serviced then there is a way of doing that. Admittedly they wont be serviced simultaneously but each will be repeatedly serviced

    Code:
    ExampleLoop:
    
    If PORTB.0 = 0 then
      do a kind of loop here...
    Endif
    
    If PORTA.0 = 1
      do another kind of loop here...
    Endif
    
    Goto ExampleLoop
    I have a project where a PIC is decoding IR signals and also receiving short commands over a serial port. The main loop is basically

    Code:
    Main:
    Gosub CheckForIR
    Gosub CheckForSerial
    Goto Main
    The IR check takes the most time but that is the main activity that the PIC has to do. Serial data is received by the USART so will buffer upto two characters. Servicing the Serial data normally takes only 1ms so that it returns more or less immediately unless serial data is received at which point it waits in the serial loop a bit longer to receive any extra data as that now becomes the priority.

    Its not true multi tasking but everything does get done OK
    Keith

    www.diyha.co.uk
    www.kat5.tv

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


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by keithdoxey
    .....

    True... because of the way the program is written it will repeatedly service the PortB loop until such time as PORTB.0 = 1

    If you want BOTH loops to be serviced then there is a way of doing that. Admittedly they wont be serviced simultaneously but each will be repeatedly serviced.....

    I wanted to indicate that when a continious loop is in progress and you need that progress as long as your circuit is in operation, you will not be able to do other things.

    In my example above, "While" statements have loops inside.
    They are not a single line of instructions, they are loops.

    One must be completed so that other can run. But, if you need an infinite loop, it will never exit that loop.

    However, if we had a dual core PIC as Melanie mentioned or quad core, then you can do a simple thing as below. Say CORE1, CORE2, CORE3 etc. are new commands of PBP's 2010 version.


    Code:
    CORE1    'Separate Job Handler.
    
    While PORTB.0 = 0 
       Do a loop here....
    Wend
    
    END CORE1
    
    CORE2     'Separate Job Handler.
    
    While PORTB.A = 1 
       Do a loop here....
    Wend
    
    END CORE2
    
    
    CORE3      'Separate Job Handler.
    ...
    END CORE3
    
    ..
    ...
    ....
    
    etc...
    they all work simultaneously.


    Am I being too much imaginery here?
    Last edited by sayzer; - 1st September 2006 at 10:24.
    "If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte

  4. #4
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,115


    Did you find this post helpful? Yes | No

    Default

    OK. Multi-core MCU I think is expensive. Using more than one chip also.

    So why not use a bigger PIC with more memory to do the job of all others smaller PIC's?

    How? Well I have never done it but for a long time I was thinking to do it like that:

    1. All tasks even loops should execute only for a fraction of time, a slot.
    2. An interrupt handler would share time slots to all loops or subs.
    3. The interrupt handler might also grab the serial characters and buffer them as long as the serial transmission is slower than the handler execution time.
    4. If a loop has to execute 10 times, then a counter and a flag could be used so that every time that loop is given time, it knows where it was and what to do.

    In general I think these are the main rules to make an RTOS on a PIC. May be if we work together we can built an RTOS of our own for control applications. One man is difficult to accomplish this task.

    Ioannis

  5. #5
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,648


    Did you find this post helpful? Yes | No

    Wink Think simple ...

    Hi,Sayzer

    You're a bit complicated in your thoughts ...

    just need to send keywords to other " slave" PICs to have them running or waiting ... WHILE your main program ( and CORE ...) is running. as you can write a full port at a time, that make 8 perfectly synchronized "slaves" ... for an 8 bits device.


    Now, if TRUE multitasking is really needed, nothing keeps you away from two processors running on the same clock ... and sharing some of their inputs, even a full 8 bits bus.

    BUT, a good analysis of the problem greatly simplifies the hardware ... say 999 times upon 1000... Humour.

    A good peripheral use is also something to think at ... as we always overuse our CPU's ... for little stupid things ( i.e. translate in physical units instead of "counts" !!! )

    assembler is a really good programming teacher ...

    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 " !!!
    *****************************************

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


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Acetronics
    You're a bit complicated in your thoughts ...
    When I was 13 yrs old, in 1989, I was telling about my thoughts to some electronic engineers around me.

    One thought was about having a wireless network card (1989 !).
    I was playing with FM transmitters and was thinking how can I get rid of the wires of the LAN cards (old ones with BNC); could it be possible to adapt an FM transmitter to a LAN card etc.

    The engineers that I mentioned this to told me "You're a bit complicated in your thoughts ..."

    They said it would be useless, who would need a wireless LAN ? !!!!

    Well...no comment there today!

    A few yrs later, I was telling about having wireless earphones for cell phones.
    Guess what? who would need it? Just put the phone on your ear!!!

    Well, Bluetooth is kind of thing that people tend to use!

    Alain, pls do not take it personal, it is not about you. I am sure you understand my point.

    This is why my signature is like that.

    But,

    Quote Originally Posted by Acetronics
    Now, if TRUE multitasking is really needed, nothing keeps you away from two processors running on the same clock ... and sharing some of their inputs, even a full 8 bits bus.
    This is a good idea and I have seen some similar examples of it albeit not really true multi tasking.

    Having say 12F508, cheap ones, as slaves to do small jobs etc. could be nice. I will have a drawing to see what I can do. But, ONE PIC with TRUE multitasking is not that.



    -------------
    "If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte

Similar Threads

  1. Simple TMR1 application example needed
    By flotulopex in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 4th February 2010, 09:52
  2. Unusual Interrupts Application Problem
    By Joe Rocci in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 8th May 2009, 11:55
  3. PIC16F877A for application in mobile robot...
    By mcbeasleyjr in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 30th January 2009, 14:47
  4. DS1307 automotive application
    By DynamoBen in forum Schematics
    Replies: 10
    Last Post: - 31st August 2006, 00:33
  5. Timer Application
    By charudatt in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 16th February 2004, 06:05

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