View previous topic :: View next topic |
Author |
Message |
iso9001
Joined: 02 Dec 2003 Posts: 262
|
Does changing a timer prescale reset its count ? |
Posted: Mon Sep 20, 2004 1:09 am |
|
|
I'm working on a pulse wave maker that will eigther output 100us or 200us pulses depending on the bits in my X varaible...
I cant use delay_us since I have other priority things going on.
I was thinking of setting up a timer so that it made an int every 100us, but if I saw that my next bit will be a long pulse then it changes the postscale or prescale so that it will int at 200us then next time around, when I then check the next bit and adjust the scale if it needs it,
Maybe there is an eaisy way to do this ? I need somthing that is FAST since I have a little math to do before I know what the scale needs to be and 100us on a 1MHz chip is pushing it, ESP with the interupt overhead.
Ideas ? |
|
|
Haplo
Joined: 06 Sep 2003 Posts: 659 Location: Sydney, Australia
|
|
Posted: Mon Sep 20, 2004 2:15 am |
|
|
Use the PWM module is your PIC has it. It is a hardware module and will not have any software overhead. |
|
|
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
|
Posted: Mon Sep 20, 2004 7:44 am |
|
|
Another option is to try using the CCP module. |
|
|
iso9001
Joined: 02 Dec 2003 Posts: 262
|
|
Posted: Mon Sep 20, 2004 5:12 pm |
|
|
How could I use PWM to output my square wave if one pulse is short then there might be two longs and then maybe 3 shorts ?
The same goes for CCP... isn't that for capture, compare and pwm ? |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Sep 20, 2004 5:24 pm |
|
|
See the CCS example file, EX_CCP1S.C which shows how to generate
a pulse by using the CCP.
Look in this folder: c:\Program Files\Picc\Examples
-------
Edited for a typo.
Last edited by PCM programmer on Mon Sep 20, 2004 9:41 pm; edited 1 time in total |
|
|
iso9001
Joined: 02 Dec 2003 Posts: 262
|
|
Posted: Mon Sep 20, 2004 6:33 pm |
|
|
Oh, I see....
So thats what Compare is for.... well, hmm... How can I use this to output a long string of bits witout using an interupt ? |
|
|
J_Purbrick
Joined: 16 Sep 2003 Posts: 9
|
|
Posted: Mon Sep 20, 2004 9:12 pm |
|
|
I don't think you can send a "long string of bits" without an interrupt. And if you use CCS's interrupt service routine, the time to process each one ("pushing" and "popping" registers) will gobble all your cycles and more, if your oscillator really is 1MHz. With 20MHz you shouldn't have much trouble.
People have worked marvels with assembly language carefully arranged to take exact times between events, but you'd need to be desperate.
You could set up a serial port to produce a few sequential bits with your choice of 1's and 0's in a pattern, but you'd be stuck with the start and stop bits. |
|
|
iso9001
Joined: 02 Dec 2003 Posts: 262
|
|
Posted: Tue Sep 21, 2004 1:09 pm |
|
|
I figured I could do it by keeping track of what bit I'm on and as the code loops around inside the main while() I could progress like that... but even THAT seems desperate,
I'm just going to figure out the 5 3 byte commands I need, and do what I'm doing now, which is
output_high; delay_X;
output_low; delay_X;
output_high; delay_X;
output_low; delay_X;
Its not really the best way sinceI basically shutting the rest of the functions of untill I'm done, but it does save on cpu time. Besides the rest of my functions have +- 5 ms of tollerance, I think I should be ok |
|
|
|