PDA

View Full Version : SPWM and Elapsed Timer



CocaColaKid
- 23rd April 2008, 16:53
Is it possible to run these two beasts together since they both use TMR1?

Darrel Taylor
- 23rd April 2008, 20:23
You could change the Elapsed Timer to a different timer fairly easily.

SPWM should stay on Timer1, because it needs a 16-bit timer, and is harder to modify.
<br>

CocaColaKid
- 23rd April 2008, 20:31
Darrel,

What files would need to be modified? Just the Elapsed_INT.bas? Would you be able to help with the ASM part of it as it is for the most part greek to me. Oh yeah, the PIC I'm using it the 16F88 @ 10 MHz.

Darrel Taylor
- 25th April 2008, 10:28
Would you be able to help with the ASM part of it as it is for the most part greek to me.

That's too bad....
ASM is the Best part of Picbasic Pro. :)

Learning one without the other is like buying a space shuttle without the solid rocket boosters.
It looks nice, but it's not going to take you where you want to go. <hr>
Ok, here ya go.

The Elapsed Timer for use with Timer 2.


<font color="#0000FF"><b><i>; Initialze your hardware and LCD first

</i></b></font><font color="#008000"><b>INCLUDE </b></font><font color="#FF0000">&quot;DT_INTS-14.bas&quot; </font><font color="#0000FF"><b><i>' Required
</i></b></font><font color="#008000"><b>INCLUDE </b></font><font color="#FF0000">&quot;Elapsed-T2.bas&quot; </font><font color="#0000FF"><b><i>' Elapsed Timer for TMR2

</i></b></font><font color="#008000"><b>ASM
</b></font><font color="#000080">INT_LIST macro </font><font color="#0000FF"><b><i>; IntSource, Label, Type, ResetFlag?
</i></b></font><font color="#000080">INT_Handler TMR2_INT, _ClockCount, ASM, yes
endm
INT_CREATE </font><font color="#0000FF"><b><i>; Creates the interrupt processor

</i></b></font><font color="#000080">INT_ENABLE TMR2_INT </font><font color="#0000FF"><b><i>; Enable TMR2 Interrupts
</i></b></font><font color="#008000"><b>ENDASM

GOSUB </b></font><b>ResetTime
</b><font color="#008000"><b>GOSUB </b></font><b>StartTimer

Main</b>:
<font color="#008000"><b>IF </b></font><b>SecondsChanged </b>= <font color="#800000"><b>1 </b></font><font color="#008000"><b>THEN
LCDOUT </b></font><font color="#800000"><b>$FE</b></font>,<font color="#800000"><b>2</b></font>, <font color="#008000"><b>DEC </b></font><b>Days</b>,<font color="#FF0000">&quot;d-&quot;</font>,<font color="#008000"><b>DEC2 </b></font><b>Hours</b>,<font color="#FF0000">&quot;:&quot;</font>,<font color="#008000"><b>DEC2 </b></font><b>Minutes</b>,<font color="#FF0000">&quot;:&quot;</font>,<font color="#008000"><b>DEC2 </b></font><b>Seconds
SecondsChanged </b>= <font color="#800000"><b>0
</b></font><font color="#008000"><b>ENDIF
GOTO </b></font><b>Main</b>

CocaColaKid
- 25th April 2008, 13:24
Oh thank you very much. Now I have to compare the two and see exactly what is different and figure out why.

I know I have to learn ASM as it is the foundation on which PBP is built. It's just a lot harder to understand for us noobies.

CocaColaKid
- 6th May 2008, 16:27
Darrel,

Is there a better way to output a 82Hz PWM single than using your software routine. Your routine works perfect however I also need to read a frequency of 0-1kHz at the same time. With the resolution of 256 steps @ 82Hz its pretty interrupt hungry.

Here's what I'm trying to accomplish

TMR1 is being used for SPWM - 0-24VDC @ 82Hz
TMR2 is being used for HPWM - 0-10VDC

If I use the COUNT command it works perfect, only if I disable the interrupts though. This in turn kills the SPWM which I can't have happen. Any suggestions? Not looking for a hand out by any means, just some help pointing in the right direction. The best way to learn is do it yourself I believe.

ohararp
- 6th May 2008, 17:42
Many of the 18F devices have 2 HPWM ports. You may want to look at using a different pic.

CocaColaKid
- 6th May 2008, 17:49
Many of the 18F devices have 2 HPWM ports. You may want to look at using a different pic.

The problem is space is limited on the board. Also the HPWM minimum frequency is 245Hz @ 4MHz.

Darrel Taylor
- 6th May 2008, 21:14
Is there a better way to output a 82Hz PWM single than using your software routine. Your routine works perfect however I also need to read a frequency of 0-1kHz at the same time. With the resolution of 256 steps @ 82Hz its pretty interrupt hungry.

I'm sure there's a way to get what you need, but can you give me some more info to work with.

Which PIC?
What OSC?
How many SPWM channels?
What Freq is HPWM running at?
Is Timer0 available?
Which Pin is the 0-1khz on, and can it be moved?
Can whatever is on the T0CKI pin be moved?
Does it HAVE to be 82hz?
<br>

CocaColaKid
- 7th May 2008, 12:43
Oh, guess I missed posting all the relevant information.

16F88 @ 10MHz
Single 82Hz SPWM Channel
Single 1kHz HPWM Channel
Timer0 - Free, Timer1 - SPWM , Timer2 - HPWM
The 1kHz HPWM is being output on portb.3, it could be either portb.0 or portb.3
The porta.4/T0CKI can be made available for use, its just an input
Unfortunately the 82Hz is required, its the control signal for an ECM motor

Darrel Taylor
- 7th May 2008, 16:45
Oh, guess I missed posting all the relevant information.

16F88 @ 10MHz
Single 82Hz SPWM Channel
Single 1kHz HPWM Channel
Timer0 - Free, Timer1 - SPWM , Timer2 - HPWM
The 1kHz HPWM is being output on portb.3, it could be either portb.0 or portb.3
The porta.4/T0CKI can be made available for use, its just an input
Unfortunately the 82Hz is required, its the control signal for an ECM motor

There ya go. Now there's some room to play with.
But now you'll regret saying you want to do it yourself. :)

Since there's only 1 SPWM channel. I would recommend reverting the the original SSPWM program. It only uses 2 interrupts per cycle, 1 for the ON time, and 1 for the OFF time. But it would need to be modified to work at 82hz, since it currently runs at 100. And in the SSPWM routines, you can create a 1sec period for timing the input frequency's measurement.

Then by feeding the 0-1khz into Timer 0 (T0CKI), you should get a real good count/frequency that works in the background, unlike the COUNT command.

CocaColaKid
- 7th May 2008, 18:07
Let me see if I get this right. Bare with me because I am still very green on the whole timer thing. I need to set Timer0 to count the pulses coming in on T0CKI for 1 second once a clock is seen. This 1 second interval will be determined from Timer1?

Darrel Taylor
- 8th May 2008, 03:16
That's the plan.

Of course, it doesn't have to be a 1 second sample period.
As long as it's a constant time base, readings can be easily corrected to match the difference.
<br>