PDA

View Full Version : dt int timer1 ignores offset value



DDDvvv
- 11th June 2010, 18:48
hi everyone. im trying to produce a sine wave with this section of code, on a 18f2431


INTCON = %11000000
T1CON = %10000001
TIMER = 64233
TIMER.BYTE0 = TMR1L ;= $E9
TIMER.BYTE1 = TMR1H ;= $FA
INCLUDE "DT_INTS-18.bas"
;----[High Priority Interrupts]-----------------------------------------------
ASM
INT_LIST macro ; IntSource, Label, Type, ResetFlag?
INT_Handler TMR1_INT, _SINE, asm, yes

endm
INT_CREATE

INT_ENABLE TMR1_INT

ENDASM


SINE:
PORTA.1 = 1
X = X + 1
IF X > 63 THEN X = 0
LOOKUP X,[127, 139, 152, 164, 176, 187, 198, 208, 217, 225, 233, 239, 244, 249, 252,_
253, 254, 253, 252, 249, 244, 239, 233, 225, 217, 208, 198, 187, 176, 164,_
152, 139, 127, 115, 102, 90, 78, 67, 56, 46, 37, 29, 21, 15, 10, 5, 2, 1,_
0, 1, 2, 5, 10, 15, 21, 29, 37, 46, 56, 67, 78, 90, 102, 115],SINEWAVE


PORTA.1 = 0

@ INT_RETURN

timer1 works to the preload value, but completely ignores my offset values.
yes, i checked all over the forum, and the solutions suggested was to use timer0. i really need to use this timer, because of its high resolution, and the other timers will be tied up in later programming stages. ive tried all this:

TIMER = 64233
TIMER.BYTE0 = TMR1L
TIMER.BYTE1 = TMR1H

and


TMR1L = $E9
TMR1H = $FA

what i'm doing wrong?

Darrel Taylor
- 11th June 2010, 19:51
Timer1 should be re-loaded each time in the handler.
It should be the first thing done in the handler, and it should be added to the timer value instead of just loaded.
Adding the value helps to compensate for interrupt latencies, keeping the frequency nice and stable.

To make it easier to add, RD16 (T1CON.7) should be turned off.



Timer1 VAR WORD EXT
@Timer1 = TMR1L

T1CON = %00000001
TIMER = 64233

;... Main program here

SINE: ; interrupt handler
T1CON.0 = 0 ; stop Timer
Timer1 = Timer1 + TIMER
T1CON.0 = 1 ; restart Timer

;... rest of handler
@ INT_RETURN

HenrikOlsson
- 11th June 2010, 19:52
Hi,
Not 100% sure what you mean but I think you're forgetting to reload the timer inside the ISR.

If you preset the timer to 12345 at the beginning of the program you'll interrupt after 65536-12345 cycles - the first time only. Then the timer will be free running and you'll get an interrupt every 65536th cycle (1:1 prescaler).

Or is that not at all what you're asking about?

/Henrik.

EDIT: Oh, well the man himself beat me to it - again.... ;-)

DDDvvv
- 11th June 2010, 22:12
thanks for coming to my aid, guys. reload the value within the isr. now i know. the timer is working, with the offset with a new problem; im aiming for 3840 hz, and thats = 64233 offset value.
instead, im getting 3030 hz. i used a different pic timer calculator because picmulticalc will not run in windows 7.
this is not really a big problem, as i can adjust the offset value to get the exact frequency that im aiming for.

Timer1 VAR WORD EXT ; what does the EXT stand for?

thanks

Darrel Taylor
- 11th June 2010, 22:27
im aiming for 3840 hz, and thats = 64233 offset value.
instead, im getting 3030 hz.
What OSC are you running at?

64233 would be close for 20Mhz.
With 16Mhz OSC it would give 3.06 Khz.


picmulticalc will not run in windows 7
Turn on XP compatability mode for PicMultiCalc.


Timer1 VAR WORD EXT ; what does the EXT stand for?

The EXT (external) modifier.
http://www.picbasic.co.uk/forum/showthread.php?t=3891

Scroll down to ... Using EXT with Variables.

DDDvvv
- 11th June 2010, 22:52
thanks again for the reply. yes, i have the osc set for 16 mhz. there's my problem!

about picmulticalc, it starts ok in windows 7 but when you click on any of the buttons (timer calc, timer helper, usart calc) i get a runtime error 713; missing msstdfmt.dll that needs to be installed. rather than troll the web searching for a "trojaned" file, i chose a different calc.

thanks

HenrikOlsson
- 12th June 2010, 08:08
Hi,
FYI, I run PICMultiCalc on Win7-64bit without any problems, no compatibility mode set or anything.

/Henrik.

mackrackit
- 12th June 2010, 08:47
Hi,
FYI, I run PICMultiCalc on Win7-64bit without any problems, no compatibility mode set or anything.

/Henrik.
Me too. And I can not find msstdfmt.dll on my machine??

DDDvvv
- 14th June 2010, 03:57
im using 32 bit windows 7. maybe thats the prob..

mackrackit
- 14th June 2010, 10:33
I also have win7 32 bit and no problems there either.
Maybe you have a bad copy of multicalc?

When I get back to the shop later to day I will upload the copy I have.

mackrackit
- 14th June 2010, 19:43
DDDvvv,
You can go here to get the version of MultiCalc that I have. Not sure if there is more than on version... This one works on win7, both 32 and 64 bit machines.
http://mackrackit.cambs.net/files/

Just saw your article on driving a stepper in hardware mode, missed that thread.
Cool project!!! Now something else to play with that I do not have time for... :)
Thanks!!!

Darrel Taylor
- 14th June 2010, 22:52
That's a really old version Dave.

Here's the latest ... v1.3.1
http://www.picbasic.co.uk/forum/content.php?r=159-New-PIC-Utility.-PICMultiCalc

mackrackit
- 15th June 2010, 01:18
WOW! I have an antique!!! Custom Character generator on the new one too!!!
I really need to get out more...
Thanks Darrel!

The new one works for me on win7, 32 and 64 bit machines with the exception of the custom character generator on the 64 bit. Says I am missing FM20.DLL.
Here is what Micro Soft says about it, but I did not try their solution.
http://support.microsoft.com/kb/214757
Why the 32 bit machine is "OK" with it is a mystery to me. I have Micro Soft Security Essentials and auto updates turned on for both machines.

DDDvvv
- 15th June 2010, 04:58
thanks for all the replies. i got both picmulticalc, 1.0.0 and 1.3.1 , and i still get the same missing file error. im thinking that it has something to do with the windows 7 version that im using. (upgraded from winxp running on an old computer)

i have a winxp notebook that runs the calc perfectly, so im using that for now. thanks for the help.

mr mackrackit, yes, the stepper project was interesting. i should have named it "hardware pwm stepper drive" . however, i did not put alot of r&d on that project because of two reasons: i moved on to servo dc motor control, and i use the sla 7078 stepper driver for all my stepper interfacing. hopefully, someone improves it to something practical.

mackrackit
- 15th June 2010, 09:53
hopefully, someone improves it to something practical.
I am sure someone will benefit from it. Thanks again for sharing.