![]() |
|
#1
|
|||
|
|||
|
Timer B Oflag
I like the timers and their flexibility.
However, I am now trying to figure out how to use the OFLAG as an output which is connected to an external device. I post my question to avoid pulling an ISOPOD out of a system for testing. I am to count 200 pulses on TB0 (as set up in the CMP1 register) and then output a pulse, preferably on the IND1 pin. My understanding from the DSP56F800 is that I should be able to assign a timer pin as an output. Any thoughts are welcome. Cheers and thanks. Per |
|
#2
|
|||
|
|||
|
Hey Per, Good to hear from you.
I like the timers and their flexibility, too. Best, most flexible timers I've ever found. Quote:
Guess I need to ask the depth of your question, because if you are asking can you set the timer output high or low, yes, that's easy. IND1 pin shares the TB2 pin. So when you get your 200 count flag, you could just TB2 ON TB2 OFF to generate a pulse. The deeper question might be, how can I generate a timed pulse width for the output. The deeper question yet might be how do I generate a timed pulse width output in hardware. But the deeper questions are a bunch of work to write up, and I want to be sure the simple answer is not what you're looking for first. Last edited by RMDumse : 05-30-11 at 06:27 PM. |
|
#3
|
|||
|
|||
|
Hi Randy.
Yep, still around... :-) Trying to solve some technical problems before proceeding with an idea.... The core question for me is to be able to generate the pulse every 200 count by using the hardware... Set registers etc. and rely on the timers to do the work. I am using the Group A for measuring pulse-width for various purposes. That works great. Now, looking at the Control register for TimerB2 (IND1); If I select the primary counter input as pin 0 in the B group and enable the OFLAG output, will the IND1 become the output? Now that would be too simple..... Cheers, Per |
|
#4
|
|||
|
|||
|
I think the answer to your question is basically, yes, it is that simple. From the manual:
14.5.3 OFLAG Output Signal The primary output of each Counter/Timer is the output signal OFLAG. The OFLAG output signal can be set, cleared, or toggled when the counter reaches the programmed value. The OFLAG output signal may be outputted to an external pin shared with an external input signal. The OFLAG output signal enables each counter to generate square waves, PWM, or pulse stream outputs. The polarity of the OFLAG output signal is selectable. |
|
#5
|
|||
|
|||
|
I'm still concerned about the output pulse width. Your options as listed above are setting or clearing the output pin, or toggling the output pin.
If you want to run without processor intervention, then you'll need to toggle the pin high and toggle the pin low. Essentially you'd be making a "divide by 200" frequency counter. But you'd count 100 and toggle to get the effect. So it depends on what your desired output is like. If your pulse can be 100 counts high and then 100 counts low, this can be the easier way. But if you want a shorter pulse, then you'd have to work with (perhaps) the PWM mode. |
|
#6
|
|||
|
|||
|
Hi Randy,
Your thoughts and ideas are welcome. All I need is actually just a short pulse every 200 counts and looking at the OFLAG options, I can set it to toggle. The pulse width is not that important as the pulse is only triggering a TTL or CMOS input. The input will vary with a max frequency of 8Khz. My thought here is that there is hardware available capable of doing the work rather than taking up memory space and processing time... "Set and forget...." I don't know how big the code will become at this point so I delegate early on.... I will probably use all the timers available and then some for various functions... I currently have 2 ISOPODs connected with CAN and it is quite amazing how fast the communication is... No lags that I can see. Once I get past the prototype stage then I will need to create some PCB motherboards and add some PODs, linked by CAN.... Cheers, Per |
|
#7
|
|||
|
|||
|
Quote:
Okay, you're intent on working me hard. ![]() Let's see if we can figure this as a frequency divider first, and then see if we can figure out how to make the pulse shorter. First point of information, it's all about CNTRL and STATUS register set up. So let me list all the possiblities first. Code:
So as I understand your desired set up, you'll have an input to the timer for other uses (duration of pulse width perhaps) so we'll assume it's coming in on a pin and we'll be counting on every rising edge of it. So we choose rising edges and counter pin TB0 (or modify to suit): 001 ( COUNT RISING EDGES OF PRIMARY SOURCE 0000 ( Counter #0 input pin There's no secondary count input needed so 00 is as good as any: 00 ( SECONDARY COUNT Counter # 0 input We'll want the process of counting to be repeated: 0 ( COUNT ONCE - 0 REPEATEDLY And run to the comparison of 200 then reinitialize: 1 ( COUNT LENGTH COUNT UNTIL COMPARE AND REINITIALIZE Might as well count from 0 up: 0 ( DIR COUNT UP And we don't FORCE any other timers: 0 ( COINIT NO FORCE BY OTHER CHANNELS For output mode, we'll toggle each compare: 011 ( TOGGLE OFLAG OUTPUT ON SUCCESSFUL COMPARE So putting the pieces together we get a pattern like this 001 0000 00 0 1 0 0 011 Assembled into binary: 001 0000 00 0 1 0 0 011 or: 0010000000100011 then grouped for easy hex conversion: 0010 0000 0010 0011 Looks like we want a CNTL reg value of 2023 Now to the STATUS 00 TCF, TCFIE 00 TOF, TOFIE 00 IEF, IEFIE 0 IPS 0 INPUT 00 CAPTURE DISABLED 0 MASTER 0 EEOF 0 VAL 0 FORCE 0 OPS 1 OEN which is an obvious conversion to hex: 0001 More as I think it up... |
|
#8
|
|||
|
|||
|
Hi Randy.
It all works beautifully... We even agreed on the h2023 CTRL setting as I had done that. I made the Status a bit more complex than h1... Made a silly error with the registry offset which threw me off a bit until I realized my typo. I did a bit of neural surgery and got access to the wires... Hooked up a scope and watched.... It is so simple that I am tempted to file a complaint... :-) I initially thought of it as more complicated... By storing new values in the COMP1 registry I could watch the change on the output.... Nice and clean.... Soo, thanks for your help and input. Cheers, Per. Last edited by Norse : 06-01-11 at 12:30 PM. |
![]() |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|