different software times, impossible?


Closed Thread
Results 1 to 39 of 39
  1. #1

    Default different software times, impossible?

    example: i want 234 on-off software states on a port and, at the same time, 400 on-off software states on another port. Both start and finish at the same so with different pauses but with not reciprocal influences, impossible?

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


    Did you find this post helpful? Yes | No

    Default Re: different software times, impossible?

    lutherblisset,

    No not impossible at all, but it may depend on the clock speed that your micro is running at, AND your ability to dream up the code to make it happen

    A couple of possibilities (depending on whether the two pulse rates are symmetrical with regard to themselves)
    What I mean by that is... is the pulse rate for the first pin a fixed rate? can it be handled by a PWM peripheral within the PIC? (and the same question holds for the second port, is its rate also fixed and could it be handled by a second PWM peripheral?)

    You could also use a couple of timer peripherals within your micro along with timer interrupts. Letting one timer control one output and the other timer control the second output. If the pulse rate is not symmetrical you could pre load each timer as it expires (and interrupts your micro telling it to change the state of the given output) with a new and if necessary, different value, so that it will roll over and interrupt the micro at a different time to change the output state as necessary to meet your requirements.

    Can the PIC be running at a high enough clock rate such that it has time to set one port.pin high then go and set the second port.pin high then come back and set the first port.pin low then wait a given amount of time and then set the second port.pin low, etc. etc.

    All the while keeping what ever time base and pulse rate that your application demands??

    From my perspective (non professional programmer) Nothing ever happens "AT THE SAME TIME" within the PIC and the various port.pins. There will always be some delay or latency from one act (program directive) and the next, though this delay may be so short (a few microseconds) that it is as though it were "at the same time". The question for you to answer is, is the latency or delay (dependent on clock speed and program execution) "good enough"??

    Using assembly code (or "machine language" as I used to call it) as opposed to PICBASIC code at certain points in your program may also shorten the latency and make things happen closer to "the same time".

    Others may have better insight and you should try and provide more information as to time duration, pulse rate, pause duration, chosen microcontroller, etc. etc. so that we have enough information to better answer your specific question.

    Just a few things to consider...
    Last edited by Heckler; - 19th January 2016 at 18:25.
    Dwight
    These PIC's are like intricate puzzles just waiting for one to discover their secrets and MASTER their capabilities.

  3. #3


    Did you find this post helpful? Yes | No

    Default Re: different software times, impossible?

    hi heckler, thank you for the answer. Every pulse have its rate time, i need pauses of of 200-400 microseconds (picbasic pauseus) between every single pulse. But if the first train with 300 pulses start and finish after 10 seconds the second train with 500 pulses start and finish in synchrony with the first after 10 seconds too. Maybe you think at the pic with the hardware pwm but with them i think its impossible to set the number of the pulses.....

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


    Did you find this post helpful? Yes | No

    Default Re: different software times, impossible?

    What's the shortest time?
    What's the longest time?
    What's the needed resolution, ie will there be times that are 345us or is 200, 300, 400, that sort of thing enough?
    What kind of error can you accept?
    How many "channels"?
    Since you're talking microseconds it's either going to get "in the ballpark" or very very tricky if you need precision on many "channels".
    Do you have a PIC this needs to run and if so which one and at what Clock frequency is it runing? Or can you select the most optimal PIC for the task?

    I'm not pretending I have an ready to go answer but it's of no use to either of us describing possible solutions which clearly won't work once we know the details.

    So, more details are needed.

    /Henrik.

  5. #5


    Did you find this post helpful? Yes | No

    Default Re: different software times, impossible?

    the resolution its non critical, the range is from 200 to 600 us, at 50 microseconds steps possible rate ( 100,150,200 etc). i need two channels, the best i have is a pic16f876a with 20mhz quartz.
    Last edited by lutherblisset; - 19th January 2016 at 19:38.

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


    Did you find this post helpful? Yes | No

    Default Re: different software times, impossible?

    luther,

    In your earlier comment you mentioned the word "pauseus" which is the picbasic command to halt the micro for a specific number of microseconds. Please be aware that this "pauseus" statement will prevent the micro from doing anything else. (except being interrupted, I believe)

    The same goes for the "pause" statement. The micro is halted or "paused" for the specified duration. It will NOT continue on to the next instruction until the pause expires. So you may want to consider implementing the use of timers and interrupts. Such that the pic will just be servicing the timer interrupts and changing port.pin states as needed when the count of timer rollovers reaches your desired pulse duration.

    At this point, if I were you, I would get out my breadboard, a PIC and start blinking some LED's (or pulsing some port.pins and watching the effect (time duration) on an O'Scope) and developing some code building blocks.

    For me that is the only way to get going and learn.
    How do you eat an elephant?? One bite (or is it Byte?) at a time!

    good luck and keep asking questions
    The more specific the better and with whatever code you have implemented so far.
    Dwight
    These PIC's are like intricate puzzles just waiting for one to discover their secrets and MASTER their capabilities.

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


    Did you find this post helpful? Yes | No

    Default Re: different software times, impossible?

    assuming waveform duration <= 100mS
    using a resoloution of 100uS requires 1000 bits (125 bytes) to describe each wave [in a sampled fashion]

    easy enough to clockout two independant waves this way but a pic16f876a with only limited(384 bytes i think) ram is a bit tricky

    have you thought about other ways to "describe" your wave forms , are they fixed or do they vary . can the be subdivided into fixed and variable sections [header and footer maybe ?]

  8. #8


    Did you find this post helpful? Yes | No

    Default Re: different software times, impossible?

    the first train is fixed 400 pulses, 50% on and 50% off. for the second train i can set another number of pulses, but the totale time must be the same of the first train, same start same end, maybe two pic serially connected?

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


    Did you find this post helpful? Yes | No

    Default Re: different software times, impossible?

    so wave 1 is 400 pulses of [ pulse width x] : therefore duration = x * 800
    wave 2 is y pulses of duration/(y*2) ; assuming 50% duty

    y range is ?
    x range is ?
    tolerance is ?
    repeat rate is ?

  10. #10


    Did you find this post helpful? Yes | No

    Default Re: different software times, impossible?

    the only fixed thing is the 400 pulses of the x, with 300us on and 300us off, on the other side y i must have the choice to set different pulses (100 to 600). But whatever pulses have the y the goal must be to reach the end at the same time....
    Last edited by lutherblisset; - 20th January 2016 at 01:28.

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


    Did you find this post helpful? Yes | No

    Default Re: different software times, impossible?

    But whatever pulses have the y the goal must be to reach the end at the same time....
    how do you define the end ?

    depending on what you think a reasonable resolution is (and achievable) not all possible pulse counts in the range 100-600 will divide exactly into the duration .

    what is the duration 800 * 300 uS or 799 * 300 uS ?

    how do you intend the sync to be eg leading edge low to high transition to trailing edge high to low transition ?

    can the final y pulse just be truncated to fit ?
    Attached Images Attached Images  

  12. #12


    Did you find this post helpful? Yes | No

    Default Re: different software times, impossible?

    hello richard, first of all thank you. The y pulse can be always approximate to the unit, so it's never truncated. Only the pause change to reach the total time together at the x pulse. the x pulse is fixed 400*600=240000=240milliseconds, so the y pulses.

  13. #13


    Did you find this post helpful? Yes | No

    Default Re: different software times, impossible?

    i will make a test to see if the logical circuit connected to the pic accept "on" states duration other than "off" states, not symmetrical. Cause if the only important thing is the distance between the beginning of every "on" state maybe the software can be easier....

  14. #14
    Join Date
    Apr 2011
    Location
    Welches, Oregon
    Posts
    198


    Did you find this post helpful? Yes | No

    Default Re: different software times, impossible?

    It is, I understand, also possible to run more than one pic from a clock source. You mentioned connecting pics serially, but I do not see this as a solution; however, two (or more) sync'ed to the same clock...

  15. #15


    Did you find this post helpful? Yes | No

    Default Re: different software times, impossible?

    this is what the datasheet of the ic connected to the pic says:

    "An active low pulse on the input pin activate the logic. The activation occurs on the rising edge of the signal"

    clock input pin: low max 0,6v, high min 2v

    clock time: 0,5 us
    set up time: 1 us
    hold time: 4 us

  16. #16


    Did you find this post helpful? Yes | No

    Default Re: different software times, impossible?

    i tried with only 4us of "off" state and the input pin of the ic connected to the pic count the clock pulses very good, like the datasheet says

  17. #17


    Did you find this post helpful? Yes | No

    Default Re: different software times, impossible?

    it work with even 1us off state

  18. #18
    Join Date
    Nov 2005
    Location
    Bombay, India
    Posts
    947


    Did you find this post helpful? Yes | No

    Default Re: different software times, impossible?

    Are you looking to implement a frequency multiplier using PIC ?

  19. #19


    Did you find this post helpful? Yes | No

    Default Re: different software times, impossible?

    oh no, it's a stepper motors driver

  20. #20
    Join Date
    Nov 2005
    Location
    Bombay, India
    Posts
    947


    Did you find this post helpful? Yes | No

    Default Re: different software times, impossible?

    Well okay, a stepper motor driver should not be difficult to implement. You are possibly asking for some kind of multiplication factor between an input wave (encoder) and the output drive(Stepper). I'm not sure I understand the problem you described very well.
    Last edited by Jerson; - 20th January 2016 at 18:18.

  21. #21


    Did you find this post helpful? Yes | No

    Default Re: different software times, impossible?

    simply the stepper motor driver use the input clock to define the steps, one rising pulse is one step, 400 rising pulses are 400 steps

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


    Did you find this post helpful? Yes | No

    Default Re: different software times, impossible?

    So the PIC is what's going to generate the pulses for two step motor drivers and you're trying to implement linear interpolation in the PIC?
    Generally what you're looking for is Breshenhams algorithm but your case seems rather specific with one axis always moving the same distance so I don't know.

    /Henrik.

  23. #23


    Did you find this post helpful? Yes | No

    Default Re: different software times, impossible?

    if i choose the two pic serially connected solution the two separate quartz can produce an error in time or it will be negligible?

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


    Did you find this post helpful? Yes | No

    Default Re: different software times, impossible?

    it would be relatively easy to to emit 400 cycles of a 50% pw 600uS period wave [x] using a ccp module while toggling another pin at 2 to 12 mS intervals (100-600 pulses) . the pin toggle isr would count down the desired number of [y ] pulses (the period being predetermined) and terminate the ccp output and itself at that point . if a 16 bit timer is used for the isr then the resoution would be reasonable with a 20mhz clk.
    you could also look at a PoKeys57 module or an arduino running GRBL.
    your description of the problem at hand lacks sufficient detail for me to progress beyond this point , a classic xy problem http://xyproblem.info/

  25. #25


    Did you find this post helpful? Yes | No

    Default Re: different software times, impossible?

    hello richard so its possible to stop the pwm after a fixed time? Maybe its a solution, cause the 400 steps (or always multiply of 400) are fixed, i need only to stop the pwm output after the same time of y, its possible to stop the pwm at the exact point from the software?

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


    Did you find this post helpful? Yes | No

    Default Re: different software times, impossible?

    CPRxCON=12 PWM ON
    CPRxCON=0 PWM OFF

    You may need to set the CCPx output pin to 0 if the pin idle state is critical

  27. #27


    Did you find this post helpful? Yes | No

    Default Re: different software times, impossible?

    the lowest possible hpwm frequency is 245 hz (for a 4mhz quartz) and 1221hz for a 20mhz quartz, now i have to calculate the frequency of 400 pulses.....

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


    Did you find this post helpful? Yes | No

    Default Re: different software times, impossible?

    try thisName:  Untitled.jpg
Views: 663
Size:  54.3 KB

  29. #29


    Did you find this post helpful? Yes | No

    Default Re: different software times, impossible?

    400*300+300=240.000 us
    1.000.000 us /240.000 us =4,1666666667
    4,1666666667*400 pulses =1.666,66666668 hz for one second if the quartz is precise.......

  30. #30


    Did you find this post helpful? Yes | No

    Default Re: different software times, impossible?

    the pwm work good and the frequency counter confirm the exact frequency and its possible to stop it at a fixed point, now i need a second timer to count the y pulses other than 400) with a same time of x. The x train with 400 pulses do the work in: 400*300+300=240.000us. I need the same time for y, with pulses other than 400....

  31. #31


    Did you find this post helpful? Yes | No

    Default Re: different software times, impossible?

    what's the lowest possible increment in uS units of the two other timers with 20mhz quartz?

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


    Did you find this post helpful? Yes | No

    Default Re: different software times, impossible?

    what's the lowest possible increment in uS units of the two other timers with 20mhz quartz?
    i think thats the wrong question

    1. first thing is what time intervals are required to toggle the output at to achieve for the given number of pulses in the time frame
    2. are they all possible within the available timer resolution ? how many pulses do you really need ? steps of 5 10, 50 ,1 ,2 ?
    3. what method will be fast enough to toggle the output and count the pulses too .ie an isr or a fast loop to monitor timer overflows

    PULSES TOGGLES PERIOD uS
    100 199 1204.52
    101 201 1192.54
    150 299 801.67
    200 399 600.75
    250 499 480.36
    300 599 400.17
    350 699 342.92
    400 799 300.00
    450 899 266.63
    500 999 239.94
    550 1099 218.11
    599 1197 200.25
    600 1199 199.92

  33. #33


    Did you find this post helpful? Yes | No

    Default Re: different software times, impossible?

    hi richard, to match the x pulses (1666hz) for the y pulses i need to set a range from 500us (250high+250low) to 7500us (3750high+3750low) the increment can be 50us. For your 3rd question i need your help....

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


    Did you find this post helpful? Yes | No

    Default Re: different software times, impossible?

    if you go down that path then


    Code:
    toggle /time pulses
    250 479
    300 399
    350 342
    400 299
    450 266
    500 239
    550 217
    600 199
    650 184
    700 171
    750 159
    800 149
    850 141
    900 133
    950 126
    1000 119
    1050 114
    1100 108
    1150 104
    1200 99
    1250 95
    1300 92
    1350 88
    1400 85
    1450 82
    1500 79
    1550 77
    1600 74
    1650 72
    1700 70
    1750 68
    1800 66
    1850 64
    1900 63
    1950 61
    2000 59
    2050 58
    2100 57
    2150 55
    2200 54
    2250 53
    2300 52
    2350 51
    2400 49
    2450 48
    2500 47
    2550 47
    2600 46
    2650 45
    2700 44
    2750 43
    2800 42
    2850 42
    2900 41
    2950 40
    3000 39
    3050 39
    3100 38
    3150 38
    3200 37
    3250 36
    3300 36
    3350 35
    3400 35
    3450 34
    3500 34
    3550 33
    3600 33
    3650 32
    3700 32
    3750 31
    then :-
    1. your range is 31 to 479 pulses nothing like the 100-600 initially specified
    2. not every period produces a different pulse count
    3. pulses will not always finish synchronously within the 400 pulse stream
    4. the pulse count varies in a non-linear manner
    Name:  Untitled.jpg
Views: 529
Size:  25.2 KB

  35. #35


    Did you find this post helpful? Yes | No

    Default Re: different software times, impossible?

    hi richard, i understand. The 31-479 possible pulses of y for every 400 pulses of x are for me necessary, it's impossible for me to change those three parameters. i know it's a problem of "times", they are like two "digital gears" and i must find the way to match the reciprocal "teeth". The frequency of x now is 1666 hz (240.000uS) but the x motor accept other frequencies too. More difficult for me is understand interrupts, overflow, ticks, to find my way and the possible solution

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


    Did you find this post helpful? Yes | No

    Default Re: different software times, impossible?

    More difficult for me is understand interrupts, overflow, ticks, to find my way and the possible solution
    the forum is crammed full of examples

    search "blinky" to see some relevant ideas

    perhaps if you provide more detailed information about what you are trying to achieve preferably with some examples of the code that you have tried , more help would be offered.
    as it stands your goal is a mystery and worse still the goalposts seem to keep moving . speculation wastes everyone time and patience.
    (I'm thinking now that an electronically variable gearbox might be your target , if so this approach is not going to work) but that's just speculation

  37. #37


    Did you find this post helpful? Yes | No

    Default Re: different software times, impossible?

    anyway the pwm (the only way to have two pulses on different ports of a pic at the same time) it's not good for me cause i work with stepper motors and i have to define closed number of steps, not frequencies. Cause i must define fix numbers, not number of pulses for second. I can't tell the pic to count until 9600 on a port and to count until 120000 on another port at the same time (the quartz of course) its impossible.

  38. #38


    Did you find this post helpful? Yes | No

    Default Re: different software times, impossible?

    from what you have described so far, it may be easier than it seems to implement this..... maybe.
    1, you have to use timer interrupt at 50micro seconds..... the highest common value for both times
    2, you implement a while/wend loop with block of code for main X....hi/low and total run ... and block of code for Y .... with values you calculated
    3, using counters in blocks to toggle pins and exit while when pulses/count are reached
    4, outside of while blocks to get/calculate new Y's.... do other stuff then startup a new round of pulses
    5, the constraint is all the code inside blocks have to be less than 50micro seconds..... at 20 MHZ should able to do about 100 to 200 instructions in 50micro seconds

  39. #39


    Did you find this post helpful? Yes | No

    Default Re: different software times, impossible?

    thank you amgen, i have to work with the timers for generate the correct number of pulses for two ports with the lowest possible latency.

Similar Threads

  1. WDT times not as expected 18f46k80
    By longpole001 in forum mel PIC BASIC Pro
    Replies: 11
    Last Post: - 18th July 2015, 05:22
  2. MCSP, PBP260, Win7 - is it impossible?
    By HenrikOlsson in forum General
    Replies: 18
    Last Post: - 26th January 2010, 18:08
  3. Drive relay between two times
    By Pedro Pinto in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 15th December 2009, 10:19
  4. Instruction times
    By BobEdge in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 5th June 2009, 10:16
  5. Calling Subroutines Multiple Times
    By Forkosh in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 17th March 2008, 08:11

Members who have read this thread : 2

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