1. Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.
    Dismiss Notice

Use of the the Count feature

Discussion in 'Oshonsoft' started by steve langner, Feb 15, 2017.

  1. steve langner

    steve langner New Member

    Joined:
    Aug 2, 2014
    Messages:
    27
    Likes:
    0
    If Count is used in a main loop to continuously update number of incoming pulses, the iterations of the loop are held up for the duration the "pulse-collecting " interval, typically 1000 mSec. This suggests that any operation within the same loop , for example a multiplexing loop, is also held up for that interval with undesirable results. Is there any way in which these secondary operations can be continued without interruption by the count operation? I believe, for example, that there is a feature in Microsoft's Visual Basic called Do Events which facilitates this. Help here will be much appreciated.
     
  2. Nigel Goodwin

    Nigel Goodwin Super Moderator Most Helpful Member

    Joined:
    Nov 17, 2003
    Messages:
    39,216
    Likes:
    640
    Location:
    Derbyshire, UK
    The use of interrupts, which is what something like Visual Basic basic uses - as does Windows, for it's pseudo multi-tasking.

    It's a very common operation with microcontrollers, which have specific implementations of it - these vary considerably though from device to device.
     
  3. steve langner

    steve langner New Member

    Joined:
    Aug 2, 2014
    Messages:
    27
    Likes:
    0
    Hi Nigel. Thanks for the tip. I've never used interrupts, but note that Oshonsoft's Reference Manal has a briefish section on interrupts with a couple of examples which I can't begin to understand --yet. I'll study these to see if I can make any sense of them, but I'll probably be back I'm afraid.
     
  4. dave

    Dave New Member

    Joined:
    Jan 12, 1997
    Messages:
    -
    Likes:
    0


     
  5. Ian Rogers

    Ian Rogers Super Moderator Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    9,161
    Likes:
    909
    Location:
    Rochdale UK
    ONLINE

    You don't need interrupts for counting.... Most Pic micros will allow you to gate the timer to an incoming train of pulses ..

    There is normally a T0CK and a T1CK pin so the count is done in the background.... The downside is the counter only ever counts up!!
     
  6. steve langner

    steve langner New Member

    Joined:
    Aug 2, 2014
    Messages:
    27
    Likes:
    0
    I'm sorry, I'm not well versed in micros so I don't understand your drift. I'm wondering if maybe I didn't make the problem clear. Specifically I'm trying to produce a frequency counter, the frequency being displayed on a SMA420560 LED display module.
    The counter, under "Count," samples the incoming pulses for a second and dumps the number received into a variable. This gives me a direct reading of the source frequency. The value is then processed and for display.

    The counter operates in a main loop in which there is a second loop which effectively multiplexes the digits of the display module. Unfortunately, at the beginning of the main loop, the counter is refreshed for a second, during which time the loop is held up, which holds up the multiplexing loop, which extinguishes the display module for that second in every iteration of the main loop. I need to prevent this constant periodic extinguishment. So the loop in which the display code resides needs to continue unhampered by the Count refreshing episodes. My code as it stands is, I'm afraid, a bit lengthy and convoluted, so I'm reticent about inflicting it on you patient guys.
     
  7. sagor1

    sagor1 Member

    Joined:
    Dec 11, 2014
    Messages:
    52
    Likes:
    2
    Steve, you may have to look at Interrupts to prevent main code "delays". Look into using Timer0 or Timer1 as an interrupt that is PIC clock based, and set it up to count to 1000mS. Most PIC clocks run too fast to make it 1 second with one timer interrupt setup. Set up a interrupt routine, perhaps triggering every 100mS, that counts 10 times to reach 1000mS. Then, look into a pin to interrupt on change (IOC pin), and in that interrupt routine, increment a counter, whether it be a byte, word, or long word. That increment is what you are counting of course. When timer0 interrupts for the 10th time, stop all interrupts, read the value you incremented in the other interrupt routine, and set a simply bit/byte flag for the main routine to check if "time is up". Your main routine can then process the value, then clear the timers and interrupt stored value and re-enable interrupts.
    This way, your main routine runs forever with no pauses.
    I use the following utility to calculate PIC timer values, including which registers to set. It is not exactly the same register names as Oshonsoft, but very close, you can easily set the equivalent registers. This calculator has an option to show settings in C, Basic or Pascal. It is from another compiler vendor, but seems open to the public:
    https://libstock.mikroe.com/projects/view/398/timer-calculator

    Next time, it would help if you mentioned what PIC you are using...
     
  8. Ian Rogers

    Ian Rogers Super Moderator Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    9,161
    Likes:
    909
    Location:
    Rochdale UK
    ONLINE
    Thats exactly what I was saying...... The "count" is fed into a timer... Lets say timer 1... The other timer, timer 0 will count seconds... When Timer 0 reaches a certain time, timer1 is read and the count per second is displayed..

    There is an example of this in my articles... But as this is in the Oshonsoft area, I take it you want to use Basic!!
     
  9. steve langner

    steve langner New Member

    Joined:
    Aug 2, 2014
    Messages:
    27
    Likes:
    0
    Thanks for your comprehensive reply; unfortunately I believe you are all crediting me with far more knowledge and experience of micros than I actually possess. I'm sure your post contains the key to answering my need, but I will require time to absorb and assimilate it. I think it's a pity that the problem of a loop being held up by an external pause operation, seems not to have been addressed in the Oshonsoft software. Surely it's not unique? Anyway, thanks again for your help .
     

Share This Page