PDA

View Full Version : Instant Interrupts - Revisited



Pages : [1] 2 3 4

Darrel Taylor
- 7th February 2006, 07:03
This is a series of include files that simplify the process of creating interrupt driven programs for PicBasic Pro. MPASM required.

Once you try this, you may never use ON INTERRUPT again.

Features:
Assembly language Interrupts
Basic language Interrupts
Both ASM and Basic interrupts in the same program
Service Multiple Interrupt sources
Prioritized execution order
Very easy to use


No ON INTERRUPT "Code Bloat"
No ON INTERRUPT " I'll service your interrupt whenever I feel like it." mentality.
.
One of the best things about this system, is that you don't have to remember where all the Enable bits and Interrupt flags are located.

Each interrupt "source" is given a unique name that is used to reference it.
The system "Looks Up" the correct bit locations for that name. Reducing those RTFM sessions to a minimum.
The following table lists the Named Interrupts.
Note: More interrupts have been added .. please visit http://darreltaylor.com/DT_INTS-14/intro.html

Available Interrupt Sources 14-bit
INT_INT -- INT External Interrupt
RBC_INT -- RB Port Change Interrupt
TMR0_INT -- TMR0 Overflow Interrupt 16F
TMR1_INT -- TMR1 Overflow Interrupt
TMR2_INT -- TMR2 to PR2 Match Interrupt
TX_INT -- USART Transmit Interrupt
RX_INT -- USART Receive Interrupt
CMP_INT -- Comparator Interrupt
EE_INT -- EEPROM/FLASH Write Operation Interrupt
BUS_INT -- Bus Collision Interrupt
PSP_INT -- Parallel Slave Port Read/Write Interrupt
AD_INT -- A/D Converter Interrupt
SSP_INT -- Master Synchronous Serial Port Interrupt
CCP1_INT -- CCP1 Interrupt
CCP2_INT -- CCP2 Interrupt

Here's a simple example of toggling an LED using the external interrupt (INT). (Hello World)

LED1 VAR PORTB.1

INCLUDE "DT_INTS-14.bas" ' Base Interrupt System
INCLUDE "ReEnterPBP.bas" ' Include if using PBP interrupts

ASM
INT_LIST macro ; IntSource, Label, Type, ResetFlag?
INT_Handler INT_INT, _ToggleLED1, PBP, yes
endm
INT_CREATE ; Creates the interrupt processor

INT_ENABLE INT_INT ; enable external (INT) interrupts
ENDASM

Main:
PAUSE 1
GOTO Main

'---[INT - interrupt handler]---------------------------------------------------
ToggleLED1:
TOGGLE LED1
@ INT_RETURN
Code Size = 234 words

This project, and it's associated files, have been moved.
Please download them from my website.
DT_INTS-14 (12F-16F)
http://darreltaylor.com/DT_INTS-14/intro.html

DT_INTS-18 (18F)
http://darreltaylor.com/DT_INTS-18/home.html

.

Darrel Taylor
- 7th February 2006, 07:16
The ultimate overkill Blinky Light program ... using Timer 1


LED1 VAR PORTB.1

INCLUDE "DT_INTS-14.bas" ' Base Interrupt System
INCLUDE "ReEnterPBP.bas" ' Include if using PBP interrupts

ASM
INT_LIST macro ; IntSource, Label, Type, ResetFlag?
INT_Handler TMR1_INT, _ToggleLED1, PBP, yes
endm
INT_CREATE ; Creates the interrupt processor
ENDASM

T1CON = $31 ; Prescaler=8, TMR1ON
@ INT_ENABLE TMR1_INT ; enable Timer 1 interrupts

Main:
PAUSE 1
GOTO Main

'---[TMR1 - interrupt handler]--------------------------------------------------
ToggleLED1:
TOGGLE LED1
@ INT_RETURNCode Size = 240 words

OK, Why? ... You might ask.
Well, for one, this Blinky Light program will continue Blinking at the same rate, no matter what else you add to the Main: program loop. Try doing that with pauses.

Darrel Taylor
- 7th February 2006, 08:01
The NEW Elapsed Timer does, ... well .. it does exactly the same thing as the old Elapsed Timer (http://www.picbasic.co.uk/forum/showthread.php?t=190). But now it works with the Instant Interrupt system. Which means that you can use many other interrupts in the same program without much trouble at all. Unlike the last version.

Here's an example of just the Elapsed Timer by itself.

INCLUDE "DT_INTS-14.bas"
INCLUDE "ReEnterPBP.bas"
INCLUDE "Elapsed_INT.bas" ; Elapsed Timer Routines

ASM
INT_LIST macro ; IntSource, Label, Type, ResetFlag?
INT_Handler TMR1_INT, _ClockCount, PBP, yes
endm
INT_CREATE ; Creates the interrupt processor

INT_ENABLE TMR1_INT ; Enable Timer 1 Interrupts
ENDASM

GOSUB ResetTime ' Reset Time to 0d-00:00:00.00
GOSUB StartTimer ' Start the Elapsed Timer

Main:
IF SecondsChanged = 1 THEN
SecondsChanged = 0
LCDOUT $FE,2, DEC Days,"d-",DEC2 Hours,":",DEC2 Minutes,":",DEC2 Seconds
ENDIF
GOTO Main Code Size = 537 Words

This will create a Clock counting at 1/100 seconds. It runs in the background of PBP without any other program intervention required.

The time is kept in the variables:

Ticks var byte ' 1/100th of a second
Seconds var byte ' 0-59
Minutes var byte ' 0-59
Hours var byte ' 0-23
Days var word ' 0-65535 The time can be easily displayed with a single line:
LCDout $FE,2, dec Days,"d-",dec2 Hours,":",dec2 Minutes,":",dec2 Seconds
For each of the variables (Seconds, Minutes, Hours and Days) there is a flag
that indicates when the value of that variable has changed. The Flags are:

SecondsChanged var bit
MinutesChanged var bit
HoursChanged var bit
DaysChanged var bit

If you wanted to display the time like a clock, you could wait until
SecondsChanged = 1, display the time, then reset the flag.


Loop1:
if SecondsChanged = 1 then
LCDout $FE,2, dec Days,"d-",dec2 Hours,":",dec2 Minutes,":",dec2 Seconds
SecondsChanged = 0
endif
Goto Loop1
If you only wanted to display the time each minute instead of every second
just do the same thing using the MinutesChanged flag.


Loop1:
if MinutesChanged = 1 then
LCDout $FE,2, dec Days,"d-",dec2 Hours,":",dec2 Minutes
MinutesChanged = 0
endif
Goto Loop1

The timer can be Stopped and Started, like a stopwatch.

Gosub StopTimer
Gosub StartTimer

Darrel Taylor
- 7th February 2006, 09:37
So far I've shown one interrupt source being used at a time, but as I said in the first post, you can easily service Multiple Interrupt Sources.   So what if we wanted to join the previous 3 examples into one program.   NOT a problem!

To add more interrupt "Handlers", simply add them to the INT_LIST, and create a subroutine for them.

Since both the Blinky Light, and Elapsed Timer used TMR1, lets move the Blinky Light over to TMR0. Elapsed will still use TMR1.


LED1 VAR PORTD.0
LED2 VAR PORTD.1

INCLUDE "DT_INTS-14.bas" ' Base Interrupt System
INCLUDE "ReEnterPBP.bas" ' Include if using PBP interrupts
INCLUDE "Elapsed_INT.bas" ' Elapsed Timer Routines

ASM
INT_LIST macro ; IntSource, Label, Type, ResetFlag?
INT_Handler INT_INT, _ToggleLED1, PBP, yes
INT_Handler TMR0_INT, _ToggleLED2, PBP, yes
INT_Handler TMR1_INT, _ClockCount, PBP, yes
endm
INT_CREATE ; Creates the interrupt processor

INT_ENABLE INT_INT ; enable external (INT) interrupts
INT_ENABLE TMR0_INT ; enable Timer 0 interrupts
INT_ENABLE TMR1_INT ; Enable Timer 1 Interrupts
ENDASM

OPTION_REG = OPTION_REG & $80 | 1 ; Set TMR0 Prescaler to 256, leave RBPU alone
GOSUB ResetTime ' Reset Time to 0d-00:00:00.00
GOSUB StartTimer ' Start the Elapsed Timer

Main:
IF SecondsChanged = 1 THEN
SecondsChanged = 0
LCDOUT $FE,$C0, DEC Days,"d-",DEC2 Hours,":",DEC2 Minutes,":",DEC2 Seconds
ENDIF
GOTO Main

'---[INT - interrupt handler]---------------------------------------------------
ToggleLED1:
TOGGLE LED1
@ INT_RETURN

'---[TMR0 - interrupt handler]-------------------------------(Blinky Light)------
T0Count VAR WORD
ToggleLED2:
T0Count = T0Count + 1
IF T0Count = 512 THEN T0Count = 0 : TOGGLE LED2
@ INT_RETURN
<font size=-2>Code Size = 711 Words</font>

Now we have all three interrupt sources working together in the same program.
LED1 responds to the external INT
LED2 flashes, timed by TMR0
and, the elapsed timer is maintained via TMR1
And, all of this is happening behind the scenes of your normal PBP program.

Darrel Taylor
- 10th February 2006, 12:55
<table cellpadding=6><tr><td valign=center>http://www.darreltaylor.com/files/INT_Layers_asm.gif</td><td>The Instant Interrupt System consists of several "Layers".

The Bottom Layer is "DT_INTS-14.bas". This file contains everything required to use Interrupts at the ASM level. &nbsp; It handles all of the "Context Saving/Restoring", detects which interrupt has been triggered, and calls the appropriate "User Routine".

The next layer up is created from the INT_LIST macro you define in the program. &nbsp; It defines the Interrupt sources to use and the corresponding subroutines that will be called. &nbsp; They can be either simple subroutines, or complete "Modules" in a separate Include file, like the Elapse Timer. &nbsp; Up to 14 separate INT_Handler's can be in the LIST.

And, the Top Layer is the normal PBP program that runs in the foreground.

If Basic Laguage interrupts are not being used, then DT_INTS-14.bas is the only file you need to include.</td></tr></table>Here's another example of a Blinky Light program using TMR1 with an Assembly Language Interrupt handler


LED1 VAR PORTD.0
LOW LED1 ; Set to Output Low

INCLUDE "DT_INTS-14.bas" ; Base Interrupt System

ASM
INT_LIST macro ; IntSource, Label, Type, ResetFlag?
INT_Handler TMR1_INT, ToggleLED1, ASM, yes
endm
INT_CREATE ; Creates the interrupt processor

INT_ENABLE TMR1_INT ; Enable Timer 1 Interrupts
ENDASM

T1CON = $31 ; Prescaler=8, TMR1ON

Main:
PAUSE 1
GOTO Main

'---[TMR1_INT - interrupt handler]------------------------------------------
ASM
ToggleLED1
btfsc _LED1
goto $+3
bsf _LED1
goto $+2
bcf _LED1
INT_RETURN
ENDASM
<font size=-3>Code Size = 104 Words</font>

Notice that the INT_Handler's Type is ASM, and the Label does not have an underscore before it.<hr><table cellpadding=6><tr><td>http://www.darreltaylor.com/files/INT_Layers_pbp.gif</td><td valign=top>By using this type of Layering scheme. It allows us more flexability, depending on the type of interrupt we want to use. &nbsp; If we want to add Basic Language Handlers, all we need to do is Include "ReEnterPBP.bas", and it will insert another Layer in-between the Base and the Handlers.

With this layer included, you can have any combination of ASM and PBP interrupts in the same program</td></tr></table>
<br>

Darrel Taylor
- 10th February 2006, 13:51
October 05, 2002 was a good day. &nbsp; Because that's the day that Tim Box released his "INT_CTRL.pbp" program. &nbsp; The original "Instant Interrupts"

Tim had discovered that the only reason you couldn't use Basic statements in a normal interrupt, was because the PBP system variables currently being used by the statement that got interrupted, would be overwritten by the Basic statements in the interrupt routine. &nbsp; And that, all you have to do is save the state of the system vars at the start of the interrupt, and restore them back to the way they were before exiting the interrupt and you can use any Basic statements you want.

I've probably said it too many times already but ... Thanks again Tim!
<hr>
ReEnterPBP.bas is an adaptation of the same concept, but it allows the Interrupt system to determine if it needs to save the variables or not.

For instance, if you have a program with both ASM and PBP interrupt handlers, and an interrupt triggers an ASM handler, there's no need to save the variables first, it would just be waisting valuable time. And if more than 1 Basic handler is triggered at the same time, it only saves the variables once, and processes all the Interrupts on the same pass, before restoring the system vars, again saving time.

However, it does still take a lot of time to save all those variables. Usually it takes around 70 instruction cycles to save the vars. Then another 70 cycles to restore them again. At 4mhz it's 140us total save and restore time, which limits the maximum interrupt frequency to just over 7khz. At 20mhz OSC, you can go up to almost 36khz. That's fast enough to receive RS232 at over 250Kbaud with the USART. &nbsp; But is still considerably slower than you can get with ASM interrupts.

<br>

Darrel Taylor
- 19th March 2006, 21:33
<table><tr><td>http://www.darreltaylor.com/files/Bug_report.gif</td><td>While working on the 18F version, I discovered a bug in the ReEnterPBP file.
It was not restoring the RS1 and RS2 system variables properly.</td></tr></table>The file has been updated to version 3.2, and anyone using Instant Interrupts for the 14-bit PIC's should update the file as soon as possible.


<br>

Darrel Taylor
- 11th July 2006, 11:20
<table><tr><td>http://www.darreltaylor.com/files/Fireworks_5.gif</td><td>
At long last.

The Instant Interrupt system for 18F PIC's is now available.

It's become increasingly harder to keep things up to date here on the forum, so I've moved everything over to my website.
I'm still working on some of the pages, but everything you need is already there. It seems to take longer to make the web pages, than it does to write the program. :)

http://darreltaylor.com/DT_INTS-18/home.html</td></tr></table>

<br>

Christopher4187
- 12th July 2006, 04:03
Darrel,

Awesome program for a 18F4550. I never realized it takes so many lines of code just to blink an LED. Where can I adjust the duty cycle of the LED?

Thanks,

Chris

Charles Linquis
- 12th July 2006, 04:22
Many thanks to Darrel Taylor ! I'll have to try this immediately.


His techniques probably make most of what I'm about to write obsolete - but last night I promised that I would post what I learned about assembly-language interrupts and PBP from Tim Box, Charles Leo (of MELABS) and my own testing. The information presented is believed to be accurate, but I cannot guarantee this without complete testing - something I will do within the next few days. If I find any mistakes, I'll post an update.

1)
Some of the newer 18F parts have a new instruction -

RETFIE FAST

This instruction AUTOMATICALLY saves and restores the W,STATUS and BSR registers. Unless you mess around with pointers (such as FSR0x), this is all you need to do use. No extra instructions for saving and restoring context are needed. Just put it in place of the ordinary 'retfie' instruction. Check your datasheet to make sure if your part offers this. The 18F8720 and '8722 have this instruction.

2)
If your part does NOT have the "fast interrupt" enhancement, you should *normally* only need to save and restore W,STATUS and BSR.

3)
ALL of the variables declared by PBP but used in the assembly routine should be declared as 'bankA'.

4)
Variables declared by PBP are given an underscore "_" before the name when used in assembly. For example: 'MyVar var BYTE bankA' in PBP becomes '_MyVar' in assembly. To allow the same name in both PBP AND assembly, you need to define the variable as 'system' . For example 'MyVar BYTE bankA
system' has the name 'MyVar' in assembly (The assembler variable doesn't require an underscore as long as the variable is declared as 'system'.)

5)
Don't declare BIT variables in PBP to later be used in an assembly routine.
Use BYTE or WORD variables only. If you just need a bit to act as a flag, declare a PBP variable such as 'FLAGVAR' and set/reset one of the bits.

6)
Since your are only using the Access Bank (bankA) in your assembly-language routine, you don't need to use GOTOs. Use the BRA (branch) instruction instead.

7)
If you have two interrupt levels (high and low priority), you can use the PBP defines -
DEFINE INTHAND (label of high-priority interrupt handler) and
DEFINE INTLHAND (label of low-priority interrupt handler)

Save and restore context the same way as described above. RETFIE FAST works on the low-priority interrupt, too.

SteveB
- 12th July 2006, 04:42
RETFIE FAST works on the low-priority interrupt, too.

Just to clarify one important item. Here is snippet from the PIC18F8722 Datasheet under Memory Organization:



5.1.4 FAST REGISTER STACK
...
If both low and high priority interrupts are enabled, the
stack registers cannot be used reliably to return from
low priority interrupts. If a high priority interrupt occurs
while servicing a low priority interrupt, the stack register
values stored by the low priority interrupt will be
overwritten. In these cases, users must save the key
registers in software during a low priority interrupt.

So, more accurately, RETFIE FAST works when low-priority interrupts are enabled, as long as software saves & restores key registers during the low priority interrupts, and RETFIE FAST is only used to return from high-priority interrupts.

Steve

Darrel Taylor
- 12th July 2006, 06:12
Charles,

Well, you got 1 of them right. The other six get the game Buzzer. ennnhhh.

1) and 2)
All 18F's have shadow registers which store the key registers on any interrupt. As Steve already pointed out, if using High Priority Ints, you can't use the Shadow RAM for Low Priority Ints because they will be overwritten by a High Pri. Int. But since Low Pri. Ints can't interrupt High Pr. Ints, Shadow RAM is always valid for High Pri.

3) You can acces any variable in any bank of ram in an Int Handler. You just have to switch to that bank before using the variable. If you couldn't switch Banks in an interrupt handler, there wouldn't be a reason to save BSR at the beginning.

CHK?RP is the easiest way. There are some complicated issues with goto's and pbp's PREV_BANK variable. but once you figure out how it works. It's a piece of cake.

4) Correct.

5) They probably said to do BIT vars that way because PBP automatically puts BIT variables in alphabeticaly sorted order towards the end of used RAM. And since that's not BANKA, it didn't fit in with number 3). Switch the BANK, and you can access them too.

6) Again, BANKA is not a limitation.

7) Seven would have been ok except for the "RETFIE FAST works on the low-priority interrupt, too" which was covered in 1) and 2).

So, just use DT_INTS-18 with Basic Language Interrupts, and you don't have to worry about Any of that stuff. It's already handled for you.
<br>

Darrel Taylor
- 12th July 2006, 06:50
Chris,

For the examples, I simply used the timers overflow to TOGGLE a pin, so the duty cycle is always 50%. But then, it's just an example. If you increase the frequency of the timer Overflows, either by reducing the prescaler, or by re-loading the timer on each interrupt, or both, you can control the duty cycle within the interrupt handler. By incrementing a variable you can have it turn on for 10 interrupts and off for 246, or whatever resolution you want.
<br>

Charles Linquis
- 12th July 2006, 16:52
Darrel,

Thanks for the clarifications.

I'm not very familiar with bank switching, so at this time I didn't feel comfortable with dealing with that. You mention "CHK?RP" as an easy way to deal with the issue. I have no idea how to use this. I assume this is a macro that comes from somewhere. Could you please elaborate?

mister_e
- 12th July 2006, 17:28
CHK?RP is a PBP macro wich send you to the correct bank of a x register

CHK?RP PORTA

not much, using this one avoid you to read the x PIC datasheet to see where the x register is placed and do the bank switching yourself. Really handy stuff!

Bruce
- 13th July 2006, 05:06
Nice work Darrel.

Darrel Taylor
- 13th July 2006, 07:43
Bruce,

Thank You, Thank You, Thank You!

But I gotta ask.

Have you tried it yet?
Or does it just Look Cool?

Apprehensively,
&nbsp; Darrel

Bruce
- 13th July 2006, 15:46
Hi Darrel,

I've tested it on a Lab-X1 with 18F452. Timers 0, 1 and 3 hi-pri. USART rx
low-pri, and it works as advertised...;o}

P.S. I thought this was pretty slick;
movff FSR#v(F)L, fsave#v(F)Pr
movff FSR#v(F)H, fsave#v(F)Pr + 1

Darrel Taylor
- 14th July 2006, 02:26
Excellent!

Thanks for that.

And, yeah. The "Text Substitution" comes in pretty handy.
A bit Cryptic looking, but it is "Slick". Finding more uses for it with each new program.
<br>

mister_e
- 14th July 2006, 04:57
Darrel,
i'm developping an USB device to be release within let's say a year if everything work as expect. I have to use few interrupts source(4 as now.. but it grows). Today i decided to implement the instant interrupt in. All i can say is that it really reduce the latency. Worked well before... by far better now. You really save me to spend hours in the asm developpement...

Anyways i'll probably have no choice to use asm if i really don't want to move to the DsPIC. It's still in developpement so far.

Thanks!

Darrel Taylor
- 14th July 2006, 21:06
Sounds great Steve,

Were you using ON INTERRUPT before? or ASM?
<br>

mister_e
- 14th July 2006, 22:12
On interrupt first.. thereafter trying to do a real pure assembler ISR wich was a real improvement but didn't finished to implement/debug all of them 'cause you bum decide to stop me and release the 18Fs version ;) and worst for FREE!

I may want to waste my time one day to do a pure asm ISR and compare both... but not for now as it's work really fine and i'm still unsure of the real final requirement 'round this device. You know how it is.. sometimes we see it bigger than it have to be :)

i'll keep you post anyways!

b1arrk5
- 16th July 2006, 01:05
I tried it, played with it for over three hours, nothing but compilation errors. I'm using Picbasic Pro 2.46 and MPASM 5.03. Any ideas?

Darrel Taylor
- 16th July 2006, 01:12
What were the errors?

And which example were you trying?
<br>

Charles Linquis
- 16th July 2006, 01:40
Darrel,

I finally had a chance to try DT_Ints-18, and it works (of course) as advertised. I can't thank you enough for working on this and finishing it just as I had a pressing need.

Keep up the good work!

Can I ask for HI2CREAD and HI2CWRITE next? Real FUNCTIONS?

b1arrk5
- 16th July 2006, 01:56
That was fast!

My errors are as follows,
Warning[230]c:\pbp\18f4550inc 20:_config has been deprecated for PIC18 devices. Use directive CONFIG. (this is listed five times, then,)
Error[128]c:\progra~1\Mecani~1\example2.asm 1150:missing arguement(s)
Error[113]c:\ "" 602: Symbol not previously defined (INTFLAGREG)
603: Symbol not previously defined (INTFLAGBIT)
218: " (INTFLAGREG)
218: " (INTFLAGBIT)
656: ERROR (INTERRUPT SOURCE (INTFLAGREG,INTFLAGBIT) NOT FOUND
713: ERROR:(INT_ENABLE - Priority State Not Found)

Thanks, I'm dying to try this out!

Jerry Gavin

mister_e
- 16th July 2006, 03:20
about the CONFIG warning error look at the FAQ
http://www.picbasic.co.uk/forum/showthread.php?t=543

Now be sure all files are in the same directory (source code, include and so on)

Still having problem? post your whole code here.

HTH

mister_e
- 16th July 2006, 03:22
Can I ask for HI2CREAD and HI2CWRITE next? Real FUNCTIONS?

what you mean by 'real function' ? unless using Macro and INCLUDE files and as far as i'm aware of, we can't add in the existing function list... i would be so much handy.

Darrel... Yet another Plug-In application ;)

b1arrk5
- 16th July 2006, 15:49
When you have eliminated all possible problems, the only one left, no matter how improbable must be the solution, to paraphrase Sherlock Holmes. I noticed that two of the files that I downloaded were showing up as smaller than the file sizes listed on Darrel's site. I deleted them and downloaded again, and everything compiled perfectly the first time! Works Great! I had just received a few 18F4550s to play with so Darrel's timing was perfect.

Also, thanks to Steve for the note regarding the Config problem.

Thanks to all,

Jerry Gavin

Darrel Taylor
- 16th July 2006, 19:18
Jerry,

Great, I'm so glad you found it. Never would have figured that out from here.

Charles,

You're welcome,

I think the HI2C, and HI2CSLAVE should be pretty easy now with DT_INTS. As well as HSPI and HSPISLAVE, PSPSLAVE, SSPWM, Multi-SSPWM, PWPS, Multi-PWPS, etc. etc. etc.

However, in order to facilitate some of those types of commands, I think the next step is a universal FIFO (First In First Out) buffer structure. Already have it working, but it looks real ugly right now.

As for Functions, I think Steve's right. Until we can gain control over the compiler, or the IDE, or maybe create a Pre-compiler, Functions will remain on the PBP wish list.

DT

P.S. My "Timing" is still not perfect though, since I've been totally sidetracked from the Elapsed Timer/Oscillator accracy problem. :(
<br>

Demon
- 16th July 2006, 19:34
This is just so cool, this stuff is exactly what I needed to service USB without having to figure out how much to sprinkle within the code.

Can't wait to try this after dinner.

Robert
:cool:

Christopher4187
- 16th July 2006, 20:17
Darrel,

You said "If you increase the frequency of the timer Overflows, either by reducing the prescaler, or by re-loading the timer on each interrupt, or both, you can control the duty cycle within the interrupt handler."

When I look at your program, I am completely lost. Can you tell me exactly what variable(s) I have to changed to get the LED blink faster or slower?

Thanks,

Chris

Darrel Taylor
- 17th July 2006, 00:26
Chris,

The prescaler can be changed with T1CON.
$31 = 1:8
$21 = 1:4
$11 = 1:2
$01 = 1:1

And the Timer is reloaded by putting values in TMR1H:TMR1L.

So first, decide what frequency you need, I'll go with 100hz.

Then, go to this thread...
Testing Forms [TimerCalc] Working I think?
http://www.picbasic.co.uk/forum/showthread.php?t=2031

Enter the OSC value you are using, say 20mhz.
I'll also go with 1:1 prescaler, enter that. (ok, it's already there)
Then enter 100 in the Freq field at the bottom.

Now you can see that it will take a total of 50,000 counts (ticks) to achieve 100hz.

Decide what resolution you want for the Duty-Cycle. ummm, 8-bit (256).

Now you just calculate the ON count from that with...
50000*DutyCycle/256 which is the same thing as...
50000*/DutyCycle in PBP
and the OFF count is 50000 - ONcount

Ok, so let's put that into the Blinky Light example






; Initialize your hardware first.


INCLUDE &quot;DT_INTS-18.bas&quot; ' Base Interrupt System
INCLUDE &quot;ReEnterPBP-18.bas&quot; ' Include if using PBP interrupts


LED1 VAR PORTB.1
DutyCycle VAR BYTE


TotalCount CON 50000
ONcount VAR WORD
OFFcount VAR WORD


ASM
INT_LIST macro ; IntSource, Label, Type, ResetFlag?
INT_Handler TMR1_INT, _ToggleLED1, PBP, yes
endm
INT_CREATE ; Creates the interrupt processor
ENDASM


T1CON = $00 ; Prescaler=1:1, TMR OFF
@ INT_ENABLE TMR1_INT ; enable Timer 1 interrupts


Main:
FOR DutyCycle = 0 TO 255 ; Ramp up
GOSUB SetDutyCycle
PAUSE 5
NEXT DutyCycle


FOR DutyCycle = 254 TO 1 STEP -1 ; Ramp down
GOSUB SetDutyCycle
PAUSE 5
NEXT DutyCycle
GOTO Main




SetDutyCycle:
ONcount = TotalCount*/DutyCycle
OFFcount = TotalCount - ONcount
IF DutyCycle = 0 THEN
T1CON.0 = 0 ; turn off timer
LOW LED1 ; idle LOW
ELSE
T1CON.0 = 1 ; timer on if DutyCycle &gt; 0
ENDIF
RETURN


DISABLE DEBUG
'---[TMR1 - interrupt handler]------------------------------------------------
@Timer1=TMR1L ; map timer registers to a word variable
Timer1 VAR WORD EXT


ToggleLED1:
IF LED1 THEN
LOW LED1
T1CON.0 = 0 ; stop the timer
Timer1 = OFFcount ; Load OFF count
T1CON.0 = 1 ; start timer
ELSE
HIGH LED1
T1CON.0 = 0 ; stop the timer
Timer1 = ONcount ; Load ON count
T1CON.0 = 1 ; start timer
ENDIF
@ INT_RETURN
ENABLE DEBUG

Darrel Taylor
- 17th July 2006, 00:48
OK, So once you try that, you'll realize that the RAMP is not linear.

It's more a function of the LED output than the PWM routine itself.

Changing it to 10-bit, and creating a lookup table that matches the LED brightness, seems to work. But I'm sure someone can come up with a better idea.
<br>

Demon
- 17th July 2006, 01:41
Darrel, if all goes well I hope to be able to commercialize this project within the next 57 years. Can I have your permission to include all this nice stuff within my code?

Hey, when I first started this project it was supposed to be nothing but a few switches and LEDs. That must have been over 2 years ago. Now I'm using a 320x240 graphic LCD, an 18F4550, two 16F628, 2 MCP23016, surface mount components, USB full speed, VB and eventually an Access database (I'm Tim The Toolman Taylor of home electronics).

Having to learn electronics kinda put me slightly behind schedule.

Robert
:lol:

Darrel Taylor
- 17th July 2006, 01:53
Hi Tim :)

If you do it in the next 57 days (or 5.7), you can still use everything to your hearts content.

Of course, you could add some routines to the pot.

Help keep the Internet Free!
<br>

Demon
- 17th July 2006, 02:23
Thank you, thank you, thank you, thank you, thank you!
Thank you, thank you, thank you, thank you, thank you!

You can be sure that I will post anything useful that I can contribute; like the stuff for the SED1335 graphic LCD. Last time I Googled, there were no code examples for that one.

But I'm afraid there's not much I can add; you, Mister E and the other regulars have already covered anything I could conjure (and then some).

Robert
:)

Darrel Taylor
- 17th July 2006, 02:37
But I'm afraid there's not much I can add;
Well, I'm no philosophy major, but I figure...

The Day you decide you Can't, is also the Day you won't.

Give it a try.
Added: or should I say more tries (examples). (SED1335 320x240 graphic LCD)

DT

Oh, and, You're Welcome, You're Welcome, You're Welcome,
You're Welcome, You're Welcome, You're Welcome.

Charles Linquis
- 18th July 2006, 01:13
Darrel,

I'm trying to work your Instant Interrupts in to my regular code.

When compiling, I get the following error messages:

WARNING:Unable to fit variable RetAddrH in requested bank 16
WARNING:Unable to fit variable RetAddrL in requested bank 16
WARNING:Unable to fit variable INT_Flags in requested bank 16
WARNING:Unable to fit variable HP_Vars in requested bank 0


Since these are just warnings, do I need to be concerned?
Is there a solution?

Demon
- 18th July 2006, 01:20
I'm the proud owner of an interupt routine in a PIC 16F628, my very first. It handles USART RX from a PIC 18F4550 wonderfully.

As mentionned on Darrel's information, I had to switch from MP to MPASM and encountered some delays in setting up the _CONFIG switches properly. But once I got that cleaned up I was up and running, this is just awesome!

(Charles, any chance you are using MP?)

Robert
:)

Charles Linquis
- 18th July 2006, 02:14
No chance.

Darrel Taylor
- 18th July 2006, 02:48
Do you have anything else designated as BANKA.

PBP uses some of it, and there's only 128 bytes.

Arrays, eat it up fast too.

??
<br>

Demon
- 18th July 2006, 02:58
I have a habit of placing INCLUDES at the top of a program. I would assume Darrel's routine would allocate whatever it wants in whatever bank first, then my program would take up what is left.

If I run out of space I know I have to trim excess fat from my code, or upgrade the mcu.

Robert
:)

Darrel Taylor
- 18th July 2006, 03:15
And a good habit it is.

I also tend to put initialization code in the Include files that need to run before the main program starts. So the top is the best, and don't jump over them.

DT

Charles Linquis
- 18th July 2006, 04:10
This is what I have. This is before I decare any other variables. I figure I'm not using anything close to 128 bytes. Any other ideas?
I AM declaring a LOT of variables after this block, however.


MasterClock VAR WORD bankA system
FanClock VAR WORD bankA system
Fan1Counter VAR WORD bankA system
Fan2Counter VAR WORD bankA system
Fan3Counter VAR WORD bankA system
Fan4Counter VAR WORD bankA system
Fan5Counter VAR WORD bankA system
Fan6Counter VAR WORD bankA system
Fan7Counter VAR WORD bankA system
Fan8Counter VAR WORD bankA system
Fan9Counter VAR WORD bankA system
changedB VAR BYTE bankA system
OldPortB VAR BYTE bankA system
changedC VAR BYTE bankA system
Temp VAR BYTE bankA system
TPE VAR BYTE bankA system

Darrel Taylor
- 18th July 2006, 04:36
I found that if I select a 16F877A, instead of an 18F part, I get the exact same errors. Could Be?

DT

Charles Linquis
- 18th July 2006, 05:34
18F8720

If you want to try it yourself, send me your email address to

[email protected]

Darrel Taylor
- 19th July 2006, 01:24
Charles,

Got the program. It's a monster.

And, I've learned a couple things today. First, Microchip pulled a fast one on me.

Chips like the 18F252/452/1220 etc. etc. have 128 bytes designated in the lower half of BANKA, ranging from 00h to 7Fh.

But, the larger chips such as 18Fxx20's only have 96 bytes, 00h to 5Fh. It's really odd, because they've taken the extra space, and turned it into "Note 1: Unimplemented registers are read as ‘0’.". I guess they're saving it for Future Use.

That wasn't very nice of them.

Second, it seems the SYSTEM modifier is doing some things that I didn't expect.
Sometimes I use the SYSTEM to simply remove the Underscore from variable names in ASM routines. But, it appears that SYSTEM does a little more than that with these chips.

If a variable is declared as...

<pre>Avar VAR BYTE SYSTEM ; without specifying the bank</pre>it will be placed in BANKA, even though BANKA wasn't specified.

This seems to happen because PBP sorts things alphabetically, and with SYSTEM removing the underscore it causes them to be sorted in with the BANKA SYSTEM variables.

Same thing happens with the PBxx BIT variables too. And, the complex octal formulas have created 12 temp (T) word variables, that also go in BANKA.

So BANKA is filling up with stuff that wasn't designated as BANKA, and now that there's less BANKA available, it's running out of room.

This problem also continues out into the other banks too. In ReEnterPBP-18, I have...

<pre>HP_Vars VAR WORD[22] BANK0</pre>Which you would think will automatically go into BANK0 before it starts allocating other variables, but it doesn't. It only fits in BANK0 if it also happens to line up alphabetically. So all variables from _A... to _H... get assigned first. Then HP_Vars throws an error.

Adding SYSTEM after it...

HP_Vars VAR WORD[22] BANK0 SYSTEM

Removes the underscore, and allows it to "sort" into the list before all the _A.._Z variables, and therefore fits in BANK0 just fine.

At this point, I'm stopping short of calling it a Bug in PBP, because maybe it's just different than what I'm expecting. However, when you declare a variable in BANK0, you would expect it to be placed there! But that's not necessarily what happens.

<hr>Now then, what to do about it.

On my end, I've pulled as much as I could out of BANKA and BANK0, and specified BANKs for all system variables. This should help with the smaller BANKA. Still need a few in there but its only about 6 bytes. I've updated the files on the website. Please download them again.
http://www.pbpgroup.com/modules/wfsection/article.php?articleid=21

On your end, since you don't actually use the BANKA modifier in your ASM routines (except for a couple PORTB accesses) all your BANKA variables would be just as happy in BANK0. But I think there's still enough room now if you want to leave them.

But the biggest thing to do is with the temp vars. This line...

IF (((OCT [0]-48)*100) + ((OCT [1]-48)*10) + (OCT [2] -48) > 255) OR (((OCT [3]-48)*100) + ((OCT [4]-48)*10) + (OCT [5] -48) > 255) OR (((OCT [6]-48)*100) + ((OCT[7]-48)*10) + (OCT [8] -48) > 255) OR (((OCT [9]-48)*100) + ((OCT [10]-48)*10) + (OCT [11] -48) > 255) THEN

Is creating 12 temp vars (T1-12). ReEnterPBP-18 is only set up for 7. So you'll either need to cut the formula into smaller pieces, or modify the ReEnterPBP-18 files to be able to handle that many temp vars. I'd recommend cutting it.

There were some other things missing, but I assume that was from not being able to compile it.

Thanks for the "HUGE" program example, It's easy to miss that kind of stuff with the little ones.

Added: Forgot to mention, Don't jump over the INT_LIST and INT_ENABLEs. They have to actually execute, to work properly.

<br>

Charles Linquis
- 19th July 2006, 04:36
Darrel,

Thanks for all the work!

I keep telling people that I probably have the "world's biggest running PBP program", maybe now I have a witness.

The reason it wouldn't compile is that I was in the process of working DT_Ints into the program but didn't have everything completed. Sometimes, I know that there are unresolved issues, but I hit "compile" anyway so that the compiler can do some of the work of finding errors for me.

Now, I'll have to see if I can make it all work at my end. I'll let you know.

Again, thanks for your help.

Charles Linquis
- 19th July 2006, 07:01
Darrel,

It compiles and assembles "clean". I changed my test for invalid IP addresses.
T5 is the last temp variable used.

Now I just have to "wire" in the ISR's to the rest of the program and test.


YAAAAAAAAAAY !

Darrel Taylor
- 19th July 2006, 08:03
Sweet! :)

Squibcakes
- 20th July 2006, 07:01
Hi Darrel,

This is pretty neat code ;) Pretty amazing really. Hahaha

Anyway, I have a problem with my PIC hanging up because of an Idle State logic level error see <a href="http://www.picbasic.co.uk/forum/showthread.php?t=4301"> Here</a> on a serial input pin.

I dont want to over complicate the circuit with extra hardware to get around this so I thought that I could use you interrupts to to side step this problem and do it all in software.

Unfortunately the TMR1 interrupt stops working as well while waiting for serial data eg

HSERIN [WAIT ("SOME DATA")]

I was hoping that these interrupts routines were bullet proof regardless of what the program was doing.

Any ideas?

Regards
Squib

Darrel Taylor
- 20th July 2006, 14:41
Squib,

TMR1 interrupts will not stop when using HSERIN. Unless the HSERIN is also in an interrupt handler.

As for the Hanging, the USART will give a Framing Error (RCSTA.2) if the RX pin is held low. Check for the error before trying to HSERIN.
<br>

Demon
- 23rd July 2006, 05:37
Darrel,

Any obvious reason why this program takes over 10 seconds to start up on a PIC 18F4550?

If I comment out the Interrupt settings at the top (includes and asm) and the ReceiveUSART handler further below, it takes less than 2 seconds.

Robert
:)

Darrel Taylor
- 23rd July 2006, 07:07
Not sure about this, but gotta start somewhere.

The RX_INT is being ENABLEd before the USART registers are set-up. Or, more accurately, since HSERIN/OUT are used in the program, PBP initializes the USART first, then RX_INT is enabled, then the USART registers are changed.

It may be causing a false interrupt that sends it to the ReceiveUSART: handler, which is expecting to see 2 bytes being received, that were never sent. So it sits there.

Try using this...
DEFINE HSER_CLROERR 1 ' Hser clear overflow automatically
DEFINE HSER_RCSTA 90h ' Hser receive status init
DEFINE HSER_TXSTA 24h ' Hser transmit status init
DEFINE HSER_SPBRG 0 ' Hser spbrg init

While PIR1.5 = 1 ; clear the buffer
HSERIN [varByte]
Wend

@ INT_ENABLE RX_INT ; enable RX interrupts
In place of..
@ INT_ENABLE RX_INT ; enable RX interrupts


DEFINE HSER_SPBRG 0 ' 1250 KBAUD @ 20 MHz (CPU)

BAUDCON.3 = 0 ' BRG16 Select 8 bit baud rate generator

TXSTA.5 = 1 ' TXEN Enable USART transmitter
TXSTA.4 = 0 ' SYNC Asynchronous communication
TXSTA.2 = 1 ' BRGH High speed baud rate

RCSTA.7 = 1 ' SPEN Enable USART receiver
RCSTA.4 = 1 ' CREN Enable continuous receive

Demon
- 23rd July 2006, 17:13
Nope, wasn't it. But as I was putzing around trying other stuff I noticed a few attempts were within 2 seconds, but for no apparent reason. For some reason it appeared to be an unstable setup and I remembered that unset pins can do this. And that's when I remembered this from page 235 of the 18F4550:

-----------------------------------------------------------------------
The pins of the Enhanced USART are multiplexed with
PORTC. In order to configure RC6/TX/CK and
RC7/RX/DT/SDO as a USART:
• bit SPEN (RCSTA<7>) must be set (= 1)
• bit TRISC<7> must be set (= 1)
• bit TRISC<6> must be cleared (= 0) for
Asynchronous and Synchronous Master modes
or set (= 1) for Synchronous Slave mode
-----------------------------------------------------------------------

I had ignored this paragraph 'cause I had never seen a need for these resistors, I thought it was only for the Enhanced USART. So I added the 4K7 resistors on TX (pulldown) and RX (pullup) and everything works fine, even with my old code.

Thanks D!

Robert
:)

Demon
- 23rd July 2006, 17:31
Well, I misunderstood what I was supposed to do but when I removed the resistors and put in the TRIS statements it took 9 seconds again. So I set the port pins to 0, same thing, I set them to 1, same thing.

It works properly with just the 4K7 resistors.

EDIT: I tried pulling both pins down and that works as well.

Robert
:)

Demon
- 25th July 2006, 04:28
This is great stuff Darrel. I've added interrupts for USART communication between a master and 2 slaves and it works like a charm.

Now I need to service the USB line every "once in a while" and read a previous reply of yours:
http://www.picbasic.co.uk/forum/showpost.php?p=23259&postcount=33

This stuff went WHOOOOSH right over my head, you lost me as soon as you started talking about hertzes. From your post I know I have to adjust the prescaler, as well as possibly manage a counter, but that's about it. I have no idea what values to use as a reasonable starting value (I figure some tweaking will be necessary).

This is the base I have so far, including relevant oscillator information:

Robert
:)

Darrel Taylor
- 25th July 2006, 08:53
"master and 2 slaves", mmm kinky!

Well, I can answer part of it.

Just change ...

<pre>T1CON = $11 ; Prescaler = 2, TMR1ON</pre> @ 48mhz, that will give an interrupt every 10.9 ms. No need to reload the timers.

According to the PBP manual, USBservice should be called every 10ms, but it doesn't have to be that precise.

However,

I have no idea what will happen when you interrupt another USB routine and try to do a USBservice.
My guess is that it won't be pretty.

More than likely, you will need to INT_DISABLE the TMR1_INT, before doing anything else with the USB, then INT_ENABLE it when it's done.
<br>

Demon
- 25th July 2006, 14:02
Ok, I added the disable/enable at both assembler USB routines generated from HIDMaker but the device is not recognized. I rummaged through the datasheet for TMR1 and T1CON and found this:

================================
When Timer1 is enabled, the RC1/T1OSI/UOE and
RC0/T1OSO/T13CKI pins become inputs. This means
the values of TRISC<1:0> are ignored and the pins are
read as ‘0’.
================================

Now that sucks, I'm using those pins as output to a LCD. I expected the LCD to spaz out but it's working fine.

I had started with an 18F4550 QFP but had downgraded to a 18F2550 SOIC, easier to solder. I don't have any output pins to spare either, the only pin I'm not using is A3.

I hate to have to yank all this off the breadboard to put back the 18F4550, again, but I might not have any choice.

I think I'm going to comment out all unnecessary code (interrupts/HSERIN/HSEROUT) until I have a working USB program again (sprinkling USBSERVICE everywhere). Then I'll put the USB interrupt back in and go on from there.

Robert
:(

Demon
- 25th July 2006, 14:21
D'oh! Enabling the USB interrupt before USBINIT was not one of my better ideas.

Step 1: I commented out everything except the LCD and sprinkled USBSERVICE everywhere it is recognized.

Step 2: I comment out all USBSERVICE and restored the TMR1 interrupt for USBSERVICE and it failed to be recognized (enabling it immediately after USBINIT).

Robert
:(

Demon
- 25th July 2006, 14:29
Step 3: I skipped over all code relating with the LCD and it still is not recognized.

So now I've narrowed it down to the TMR1 interrupt not working perfectly. How can I tweak it to interrupt at a faster rate?

I assume I have to accelerate the prescaler, I just don't know which way is which. And then possibly adding a counter to fine-tune the interval between USBservice.

Robert
:)

Demon
- 25th July 2006, 14:36
I had screwed up the disabling/enabling of the interrupt during USB subroutines.

Step 4: Disabled TMR1 _before_ the assembler loop, manually issue USBSERVICE within the loop and then enabled TMR1 after the loop and the device is recognized.

Robert
:)

Demon
- 25th July 2006, 14:44
Step 5: Reactivated LCD logic along with USART and RX interrupt and device is still recognized.

Go figure, the LCD works properly even if I'm using pins C0 and C1 to output the data and commands to the LCD.

Robert
:)

EDIT: I'm thinking the LCD works because I'm not using an external oscillator for the timer.
================================
When Timer1 is enabled, the RC1/T1OSI/UOE and
RC0/T1OSO/T13CKI pins become inputs. This means
the values of TRISC<1:0> are ignored and the pins are
read as ‘0’.
================================

dhouston
- 27th July 2006, 02:00
Can DT_INTS-14.bas be used with 12Fxxx PICs?

Darrel Taylor
- 27th July 2006, 02:56
YES!

It's a little tight for RAM and program space. But it should work.

DT

Demon
- 27th July 2006, 04:00
One note of interest, I kept hanging at the end of one of the interrupt modules, like it lost an address on the stack or something. I ran ICD and I saw the execution just hang on the ENDIF at the very bottom.

I have an RX interrupt that would write out to an I2C device 2 bytes received via USART. I removed the I2C command from within the interrupt and instead set a flag. Then I checked the flag from within the main logic and issued the I2C write and everything worked perfectly.

Darrel, here are some screenshots in case you see something obvious. Sorry, I didn't keep a copy of the code.

Robert
:)

Demon
- 27th July 2006, 04:04
2nd pic:

The program USB 18F2550 is for the master processor, that is not the one I am debugging. I am running the next program, MCP23016 16F628A.

Robert
:)

Darrel Taylor
- 27th July 2006, 08:38
Interrupts and the MCSP debugger, don't get along together very well.

You should use DISABLE DEBUG before any interrupt routines, Including the Handlers.

Then ENABLE DEBUG after them.

It is possible to save the debugger variables in the same way as ReEnterPBP, but it's a waste of space when not debugging, so I didn't include them

HTH,
&nbsp; DT

Demon
- 27th July 2006, 17:32
The weird part is that the interrupts and the debugger worked nicely as long as the I2C command was outside the interrupt routine.

I suppose there are probably exceptions, but disabling/enabling debug in and out of interrupts isn't the end of the world. It's not like we need to debug your work.

Robert
:)

Darrel Taylor
- 27th July 2006, 19:43
It's kind of like standing on the white line in the middle of a highway.

Everythings fine for a while, with cars wizzing past at 90mph.

But take one step to the left or right and, <img src=http://www.darreltaylor.com/files/splash.jpg height=70 width=70 align=top></img>

Bruce
- 27th July 2006, 19:47
Go like splat ehh...;o}

Darrel Taylor
- 28th July 2006, 02:27
Oh yeah, goes like big Splat!
There's a thump thump involved too, but you won't hear that part.

And, much like the highway, everything comes to a halt until the investigation is completed.

I'm just affraid I killed off Spock.
Who else would leave a green Splat?

Well, the moral of the story is two fold.

1. Don't stand in the middle of the Highway.

2. Don't try to Debug your interrupt routines.

LOL,
&nbsp; DT

dhouston
- 30th July 2006, 16:51
Can DT_INTS-14.bas be used with 12Fxxx PICs?YES!

It's a little tight for RAM and program space. But it should work.
With a 12F629 my app gets lots of "beyond ram_end" messages; with a 12F683, only two, so I might be able to pare it down to fit.

Darrel Taylor
- 30th July 2006, 18:54
If you don't have any complex math formula's in the program, you can reduce the number of T?_Save variables.

From ReEnterPBP.bas...
T1_Save VAR WORD
T2_Save VAR WORD
T3_Save VAR WORD
T4_Save VAR WORD

Start with T4. Comment it out and recompile. If no error, try T3, etc.

Then try ...
RS1_Save VAR BYTE
RS2_Save VAR BYTE

Might save a few bytes of RAM.

Just remember to un-comment them if you write a program for another chip.

DT

jblackann
- 31st July 2006, 17:02
I am trying to use the instant interrupts to add the funnctionality of interrupts to my programs but I am having problems with the example that found on Darryl's site. I was trying to do the example with turning a LED on and off with an external interrupt but I am having some problems. I have downloaded the latest files form Darryl's site and have saved them to same folder. I have copied the code from hiw webpage also.
I am using PICBASIC Pro vers.2.46
I am using the PIC16F687.

I am getting the following errors
Error TOGGLE~1.ASM 490 : [224] local directive only for use in macros
Error TOGGLE~1.ASM 490 : [225] undefined symbol 'iflagreg'
Error TOGGLE~1.ASM 490 : [226] numeric constant or symbol name expected
Error TOGGLE~1.ASM 490 : [201] ')' expected
Error TOGGLE~1.ASM 490 : [300] too many errors

I commented out the Wsave's that were not needed. I have some experiece with writing programs in assembly and working with interrupts. I have looked through the include files to see if I could make sense of what is going on but I am having problems figuring it out.
Can you direct to anywhere that will give me more information about macros? Any suggestions? Thanks for your time and help.

Josh

EDIT
Looking at the datasheet for the 16F687 there IS an External interrupt on RA2 instead of RB0. There is a Port change interupt on both Port A and B. Do I have to modify the file to include the interrupt on PortA? I would want to place any available interrupt pin that I can.

Bruce
- 31st July 2006, 17:19
Use the MPASM assembler.

dhouston
- 31st July 2006, 17:55
If you don't have any complex math formula's in the program, you can reduce the number of T?_Save variables.
There's no math but it didn't help. I think I'll have to try to learn enough ASM for this application. I just need TMR0 to toggle a pin every 8-10mS and TMR1 to give me a 500µS or 1000µS interval after each TMR0 rollover.

Darrel Taylor
- 1st August 2006, 01:43
Hi Josh,

The INT_INT should work ok, even with it on PORTA.

For the Interrupt on change with PORTA and PORTB, just add these two lines in the ASM section right before the INT_LIST

RBIF = RABIF
RBIE = RABIE
(no space at the beginning of the line)

Then use RBC_INT. I'll add RABC_INT, C1_INT and C2_INT names in DT_INTS-14 later, but that should get you going for now.

HTH,
&nbsp; Darrel

Darrel Taylor
- 1st August 2006, 02:09
dhouston,

For the 12F683...
Did you comment out the wsave2 and wsave3 variables in DT_INTS-14?

DT

dhouston
- 1st August 2006, 14:06
For the 12F683...
Did you comment out the wsave2 and wsave3 variables in DT_INTS-14?Not until seeing your question. That seems to do it. It compiles and only uses 593 words so I think it will be OK, now.

Will the pin change functions work with the 12F683?

Darrel Taylor
- 1st August 2006, 18:31
Awesom,


Will the pin change functions work with the 12F683?
Sure will.

Add these two lines in the ASM section right before the INT_LIST

RBIF = GPIF
RBIE = GPIE
(no space at the beginning of the line)

Then use RBC_INT.
<br>

dhouston
- 1st August 2006, 19:14
Add these two lines in the ASM section right before the INT_LIST

RBIF = GPIF
RBIE = GPIE
(no space at the beginning of the line)

Then use RBC_INT.
Thanks. Spending $0.25-0.30 more for the 12F683 vs. the 12F629 is worth it to be able to use Instant Interrupts.

Darrel Taylor
- 1st August 2006, 19:57
I like the 683 too. If for nothing more than the CCP module. Of course the extra RAM and program space is also handy.

With the 629 only having 64 bytes of RAM,
PBP uses 24-26 bytes
and DT_INTS-14 and ReEnterPBP want 31 bytes of it (without T? vars)

Which only leaves about 6-7 bytes for the program. Not much you can do with that.

But, when using ASM interrupt handlers, DT_INTS-14 only needs 7 bytes of RAM, leaving around 38 bytes for the users program. Now that, is workable. It also uses less program space that way.

You mentioned earlier that you only needed to toggle a pin in the interrupt, so you might take a look at this page...

DT_INTS-14 (Assembly Language Interrupts)
http://www.darreltaylor.com/DT_INTS-14/asm_ints.html

The ToggleLED1: handler does just that. And if the other handlers aren't too tuff, you might still fit it in a 629.

HTH,
&nbsp; DT

DynamoBen
- 10th August 2006, 18:12
Darrel

I'm going to be moving a project from a 16F88 to an 18F1320. The reason for the move is the 18F1320 has 3 external interrupts, 2 of which I will be using. Currently I'm using instant interrupts and INT_INT on the 16F88. The question is will instant interrupts work with multiple external interrupts? I see in the datasheet that the external interrupts have numbered flags.

SteveB
- 10th August 2006, 20:40
Darrel

I'm going to be moving a project from a 16F88 to an 18F1320. The reason for the move is the 18F1320 has 3 external interrupts, 2 of which I will be using. Currently I'm using instant interrupts and INT_INT on the 16F88. The question is will instant interrupts work with multiple external interrupts? I see in the datasheet that the external interrupts have numbered flags.

See http://darreltaylor.com/DT_INTS-18/home.html. Darrel has done a good job documenting the Instant Interrupts, and it shows on the right side of the page that multiple external interrupts are implemented.

Steve

DynamoBen
- 10th August 2006, 21:02
Thanks Steve, I forgot that he was using a separate version for the 18Fs.

f_lez
- 12th August 2006, 08:47
Its now 7:34 am, I just read this thread from start to finish, I would like to say it went completely over my head but some must have aimed a bit lower as I now have one hell of an headache........

I read it as I have just got a shiny new programmer and a 18f2550, I was looking for ways to port some old f88 stuff I wrote that used serial comunication, I want to it to use usb...

I found that they are some examples to make the 2550 emulate a serial port, and I may go that way, seems easier to port that way.

Then I read more and got more ambitious, and was wondering if I can port it over with the 2550 running fake serial over usb, but drop a bootloader in it before my old f88 code and use the bootloader over usb, then I wont need to use my pc serial port at all?


To summise, can I re-burn the chip via usb with a boot loader to debug my ported f88 code?

If I can, am I right in thinking all I need is to give up one i/o line to a switch to trigger the bootloader?

And like most things come in three's (especially questions), how to edit/burn to usb? with the f88 I usually create a hex file, quit basic, load the programmer software (winpic/whatever) and burn chip, remove from programmer, get a pin stuck in thumb and lose blood, stick in proto board, bend a pin etc...

Demon
- 14th August 2006, 19:29
Lez, you might want to check the USB forum for that information.

Robert
:)

Demon
- 14th August 2006, 19:35
Darrel

I'm going to be moving a project from a 16F88 to an 18F1320. The reason for the move is the 18F1320 has 3 external interrupts, 2 of which I will be using. Currently I'm using instant interrupts and INT_INT on the 16F88. The question is will instant interrupts work with multiple external interrupts? I see in the datasheet that the external interrupts have numbered flags.


Maybe assigning high & low priorities might help you:
http://darreltaylor.com/DT_INTS-18/LowPriority.html

One problem I am having now is that an internal interrupt (USB Service) seems to lose connection after I use an external interrupt (incoming USART data). Assigning a priority to each is just what I'm about to test and see how things go.

Robert
:)

Darrel Taylor
- 14th August 2006, 19:43
Sounds like a good idea.

Since an HSERIN can take up to several hundred milliseconds (depending on baud rate and data size), it's best to have HSERIN in a Low Priority handler.

And things that "must" go without fail, in the High Priorities.

DT

Demon
- 14th August 2006, 20:40
Yup, that's what I was thinking, having the USB SERVICE come first, and have the USART interrupt 'whenever'.

Edit: WEEE !!!

Robert
:)

Demon
- 15th August 2006, 05:27
Darrel,

How about this one? I have one interrupt to generate a USB Service, that part works fine. I'd like to add another interrupt for USB reception, is that what USB_INT is for?

Here is a snip of code:



;----[High Priority Interrupts]-----------------------------------------------
ASM
INT_LIST macro ; IntSource, Label, Type, ResetFlag?
INT_Handler TMR1_INT, _ServiceUSB, PBP, yes
INT_Handler USB_INT, _ReceiveUSB, PBP, yes
endm
INT_CREATE ; Creates the High priority interrupt processor
ENDASM

'---[USB - interrupt handler]------------------------------------------------
ReceiveUSB:
@ INT_DISABLE TMR1_INT ; disable USB service interrupt
USBBufferCount = USBBufferSizeRX
DoUSBIn:
USBservice ; Generate USB Service manually
USBIn 1, USBBuffer, USBBufferCount, DoUSBIn
varUsbIn = conByteHigh ' Set flag data has arrived
@ INT_ENABLE TMR1_INT ; enable USB Service interrupts
@ INT_RETURN

'---[TMR1 - interrupt handler]--------------------------------------------------
ServiceUSB:
USBservice
@ INT_RETURN

Does that make sense? Or can I leave the USB Service interrupt enabled throughout the USB Reception interrupt?

Robert
:)

mister_e
- 15th August 2006, 08:54
almost 3 Am here.. it sounds good to me BUT i'll suggest to remove the USBSERVICE in the INT handler... m i'm sure i miss something anyway...

Darrel Taylor
- 15th August 2006, 09:04
Well, I don't really know.

But, the datasheet for the 18F4550 shows 12 different interrupts from the USB module that all funnel into the single USB_INT. So I doubt it's that easy.

But if I were going to try it, I might set the ...

TRNIE: Transaction Complete Interrupt Enable bit

and see what happens.

DT

Added: and then all the others just to be sure. :)

Darrel Taylor
- 15th August 2006, 09:25
almost 3 Am here..

See there, you're always ahead of me. Was only midnight here. :)

DT

f_lez
- 16th August 2006, 11:20
Lez, you might want to check the USB forum for that information.

Robert
:)

Either I'm really dumb today (I blame last night) or their is no usb sub forum etc on here!

found a few threads, gave me some stuff to read and I'm about ready to try and knock up a pcb to test the chip with, then i'll have a go with the mouse circle hid to test wiring, then throw in the serial demo and expand on that, thanks.

Darrel Taylor
- 17th August 2006, 01:07
Here's the USB forum
http://www.picbasic.co.uk/forum/forumdisplay.php?f=18

Must have been a Good Night :)
<br>

Demon
- 17th August 2006, 02:58
Well, I don't really know.

But, the datasheet for the 18F4550 shows 12 different interrupts from the USB module that all funnel into the single USB_INT. So I doubt it's that easy.

But if I were going to try it, I might set the ...

TRNIE: Transaction Complete Interrupt Enable bit

and see what happens.

DT

Added: and then all the others just to be sure. :)


WHAT DO YOU MEAN "You don't know?" :D


Hmmm, I would tend to believe that flag does not distinguish between upload and download transactions; I really need a PC-to-PIC complete flag.

Well, since I have an interrupt controlling user input on the PIC, I can just loop the PC-to-PIC USB routine. This will make things much easier to manage, I'm not very fond of using that all-encompassing USB_INT interrupt.

Now if I can only find out why Windows won't recognize the device, things would be peachy:
http://www.picbasic.co.uk/forum/showpost.php?p=24298&postcount=55

Robert
:)

Demon
- 18th August 2006, 18:27
Hi Darrel,

I've found out why my device is not recognized, the USBSERVICE interrupt is either not working fast enough, or not working at all.

I used the generated PBP program from EasyHID to test the interrupt logic. If I comment out the default USBSERVICE the device is not recognized, and then it works if I reinstate them. Any idea what I'm doing wrong?

Robert
:)

mister_e
- 18th August 2006, 18:59
i can't try it here now, but here's a couple of suggestions.



ProgramStart:
' gosub DoUSBIn ; remove it
gosub DoUSBOut
goto ProgramStart


DoUSBOut:
'------- Disable INT here
USBBufferCount = USBBufferSizeTX
USBOut 1, USBBuffer, USBBufferCount, DoUSBOut
'------- Enable INT here
return

Demon
- 18th August 2006, 19:09
I LOVE YOU mon maudit francais. :P

That was it, you can't mix the interrupt in there for some reason.

So now I disable the interrupt just before the GOSUB and ENABLE right after.

Robert
:)

EDIT: By the way, you forgot the USBSERVICE in DoUSBOut.

Demon
- 18th August 2006, 19:40
Hmmm, there is still something weird in the USBSERVICE interrupt routine.

- if I comment the gosubs for In and Out it is not recognized.
- if I replace them with a USBSERVICE it works.

Something is still not right with the interrupt, the correction worked because the manual USBSERVICE kept the connection active.

Robert
:(

mister_e
- 18th August 2006, 19:42
Ok sure but.. how about...


USBSERVICE
ProgramStart:
pause 100 ' or else usefull stuff
goto ProgramStart


Also be sure your Timer interupt is about every 10 ms... not much but not too fast... if it's too fast maybe USBSERVICE can't finished before another interupt. So you got nested USBSERVICE trying to do their job at the same time or close to.

Demon
- 18th August 2006, 19:53
Steve, I don't know how to check how often the USBSERVICE interrupt is occurring. The only settings I have are the oscillator and prescaler:

DEFINE OSC 48
T1CON = $11 ; Prescaler = 2, TMR1ON

I am using a 20MHz crystal with these configuration settings:

CONFIG PLLDIV = 5 ;Divide by 5 (20MHz input)
CONFIG CPUDIV = OSC1_PLL2 ;[OSC1/OSC2 Src: /1][96MHz PLL Src: /2]
CONFIG USBDIV = 2 ;Clock source from 96MHz PLL/2
CONFIG FOSC = HSPLL_HS ;HS oscillator, PLL enabled, HS used by USB

Robert
:)

EDIT: Interesting, I added a counter in the interrupt routine and displayed it on the LCD, it only gets executed once. I'm checking now if I disable it and never re-enable it after.

mister_e
- 18th August 2006, 20:07
your pre-scaller is way too low... so interupt ocure way too fast, USBSERVICE don't have time to finish correctly.

Demon
- 18th August 2006, 20:10
Do you have a suggestion?

Robert
:)

mister_e
- 18th August 2006, 20:12
Uh... my calculation were wrong... (1/12000000)*65536*2='round 10mSec. ARRGGH i don't have my stuff here to compare with mine... Darrel is on-line anyway :)

mister_e
- 18th August 2006, 20:19
NO.. let's look at that...


T1CON = $11 ; Prescaler = 2, TMR1ON

i remind that TiCON can be use in 16 bit or 8 bit.. i'm sure you use it in 8 bit mode now... or i missing something obvious about the 16/8 bit.. maybe just in read/write something... mmm something look weird in this line...clock source, mode or else.

Darrel Taylor
- 18th August 2006, 20:40
Well yeah, I'm online. But that's not going to help much since I don't have a Clue about using the USB stuff. Just never got around to trying it before.

I'm still hoping you guys can figure it out. So that when I do get around to trying it, I won't have to work as hard. :)
<br>
DT

mister_e
- 18th August 2006, 20:49
if i can finish the house-bench-lab-cleaning stuff soon, i'll have access to my stuff. I have this one working.. but i don't remind wich timer i used and how i used it... the T1CON line seems weird... clock source is still my most possible guess.

Demon
- 18th August 2006, 21:29
Ok, I disabled that code to disable/enable the USBSERVICE interrupt before the gosubs and now the interrupt is getting executed a LOT of times.

I can't say at what interval, but the counter is scrolling on the LCD pretty fast. The hundreds are going by just a bit faster than every second, but I still lose connection.

Darrel, how can I adjust the speed of the interrupt?

Robert
:)

Demon
- 18th August 2006, 21:33
I'm going to solder a wire to 1 pin, blink that pin in the interrupt and connect my scope on the wire.

I don't know much about scopes, but I might be able to figure out the frequency.

Robert
:)

Demon
- 19th August 2006, 04:24
Uh... my calculation were wrong... (1/12000000)*65536*2='round 10mSec. ARRGGH i don't have my stuff here to compare with mine... Darrel is on-line anyway :)

Steve, I'm trying to figure this out using math (gotta start sometime) and I'd like to know where you got the 12000000 from.

I read this link you posted in another thread:
http://ww1.microchip.com/downloads/en/DeviceDoc/41214a.pdf

And I got this formula from Tip #7:
Tosc x 4 x 65536 x prescaler

I am using a 48MHz crystal so I get this:
(1/48000000) x 4 x 65536 x 2 = 0.0109226 (repeating)

D'uh, ok, I see it now, 48 / 4 = 12, that's where you got your value. So, as you said, that interval rounds up to just over 10ms, that 'should' work.

I'm sure it has something to do with the interrupt occurring right in the middle of USB processing and interfering with the connection. I don't see what else it can be; the interrupt seems fine, the USB works.

Robert
:(

ozion
- 6th September 2006, 08:33
Hello guys,

I am a newbie to this forum and PIC/PBP.
I am very glad to have Darrel Taylor's DT_INTS-14 compiled and work great for me.
I tried to add small routine for receiving data from usart but something start to stop working.

I posted my code below with all details remaked. Please someone find what have i done wrong.
I am still in my learning process and am scrolling. Many thanks

Cheers,
ozion



'************************************************* ***************
'* Name : BringTogether_with_RX-USart.BAS *
'* Notice : Using DT_INTS-14 *
'* MCU : PIC16F877A *
'* Goal : A string of data from PC via usart will interrupt *
'' : the PIC from what it was doing to receive the data,*
'* : filter and store received data for processing. *
'* : After received the filtered data, an acknowledge *
'* : will be send back to PC then return to what it was*
'* : left off (and processing the received data) *
'* : *
'* Notes : This program was working without adding Usart RX *
'* : Now
'* : Clock works OK *
'* : LED1 won't work *
'* : LED2 won't work *
'* : Usart won't work as expected. *
'************************************************* ***************

clear

define LOADER_USED 1
define OSC 8

' Define LCD registers and bits
Define LCD_DREG PORTB ' LCD Data register on PORTB
Define LCD_DBIT 4 ' LCD data bits (4 bits)
Define LCD_RSREG PORTB ' LCD Reset register on PORTB
Define LCD_RSBIT 2 ' LCD Reset bit 2 (PORTB.2)
Define LCD_EREG PORTB ' LCD Enable register on PORTB
Define LCD_EBIT 3 ' LCD Enable bit 3 (PORTB.3)


ADCON1 = 7 ' Set portA outputs to Digital / No ADC
'CMCON = 7
LCDOUT $FE,1 ' Initialize LCD
PAUSE 200

dat_in var byte[10] ' Added for Usart receive data
ack var byte ' Added for Usart receive acknowledge
cntr var byte ' Added for Usart receive data storage
LED1 VAR PORTD.0
LED2 VAR PORTD.3

INCLUDE "DT_INTS-14.bas" ' Required
INCLUDE "ReEnterPBP.bas" ' Include if using PBP interrupts
INCLUDE "Elapsed_INT.bas" ' Elapsed Timer Routines

' Initialize USART ' Added for Usart receive process
TRISC = %10111111 ' Set PortC.6 to output, rest to input
DEFINE HSER_BAUD 9600 ' Hser baud rate
RCSTA = %10010000 ' Enable serial port and continuous receive
TXSTA = %00100000 ' Enable transmit and asynchronous mode


ASM
INT_LIST macro ; IntSource, Label, Type, ResetFlag?
INT_Handler INT_INT, _ToggleLED2, PBP, yes
INT_Handler TMR0_INT, _ToggleLED1, PBP, yes
INT_Handler TMR1_INT, _ClockCount, PBP, yes
INT_Handler RX_INT, _Read_USART, PBP, yes ; Added
endm
INT_CREATE ; Creates the interrupt processor

INT_ENABLE INT_INT ; enable external (INT) interrupts
INT_ENABLE TMR0_INT ; enable Timer 0 interrupts
INT_ENABLE TMR1_INT ; Enable Timer 1 Interrupts
INT_ENABLE RX_INT ; enable RX_Usart interrupts ; Added
ENDASM

OPTION_REG = OPTION_REG & $80 | 1 ; Set TMR0 Prescaler to 256, leave RBPU alone
Gosub ResetTime ' Reset Time to 0d-00:00:00.00
Gosub StartTimer ' Start the Elapsed Timer

Main:
if SecondsChanged = 1 then
SecondsChanged = 0
LCDout $FE,$C0, dec Days,"d-",dec2 Hours,":",dec2 Minutes,":",dec2 Seconds
endif
if Ack=1 then ' Added
gosub Receive_Ack ' Added
endif ' Added

GOTO Main

'---[INT - interrupt handler]---------------------------------------------------
ToggleLED1:
Toggle LED1
@ INT_RETURN

'---[TMR0 - interrupt handler]-------------------------------(Blinky Light)------
T0Count Var WORD
ToggleLED2:
T0Count = T0Count + 1
if T0Count = 512 then T0Count = 0 : Toggle LED2
@ INT_RETURN
'////////////////////////////////////////////////////////////////////////////////////
'Added to read Usart
Read_USART:
hserin[dat_in]
'================================================= ==========================
'The following 2 lines won't work
'hserin[wait("X"),str dat_in\5] ' Wait for X ;receive a string of characters
'hserin[wait("X"),dat_in] ' Wait for X
'================================================= ==========================
'Following lines send back string includes first dectect char "$"
'Example: PC sent: "12345$6789"
' PIC send back to PC "12345$"
ack=0 ' clear ack
cntr=0 ' reset counter
while cntr<10 ' looping
if (dat_in[cntr]= "$") then ' filter character "$"
HSEROUT[str dat_in,cntr] '
ack=1 ' Yes found "$"
cntr=10 ' get out of loop
endif '
cntr=cntr+1 ' increment counter
wend '
HSEROUT[str dat_in] ' send to PC
'gosub Receive_Ack ' This doesn't works it does not call Receive_Ack
@ INT_RETURN

Receive_Ack:
if ack=1 then
HSEROUT ["got it:"]
HSEROUT[str dat_in] ' Send dat_in received string
endif
ack=0
return
'//////////////////////////////////////////////////////////////////////////////

Darrel Taylor
- 7th September 2006, 06:47
Hi ozion,

First rule of interrupts, Never Wait for anything.

Interrupt handlers should execute as fast as possible, and exit as soon as possible.

With 18F's you can get away with using HSERIN/HSEROUT with Waits and Pauses, by putting them in a LOW priority interrupt handler. But with the 16F's, you don't have that option.

If you want to use interrupts to receive serial data on 16F's, then you should only grab 1 byte at a time then exit. You can keep track of how many bytes have been received and set a Flag when finished so that it can be dealt with in the Main loop. Then you can HSEROUT to your hearts content.

Otherwise, do all the serial stuff in the main loop, RX and TX. The main loop should run fast enough to catch everything. And the interrupts will continue on like they should.

HTH,
&nbsp; Darrel

ozion
- 8th September 2006, 09:04
Hi Darrel,

Thanks for reply, I will try that your suggestion.

Regards,
ozion

ra68gi
- 12th September 2006, 07:15
Hi Darrel,
I have just started to use the instant interrupts. Previously i had used 8051 and the bascom compiler. I wanted to set priority to the various interrupts similar to the 8051. in the 8051 the lower priority interrupts can be interrupted by the higher priority interrupts. I can see that we can set priority only in 18F series of pic and not in 16F.

Can we not have priority in 16F pics?

Again i think among the high priority interrupts, those interrupts we would like to service it immediately we place their interrupt handler at the top, but i dont think by doing that we can exit the current high priority interrupt service routine to go and attend another interrupt whose interrupt handler is placed before the current executing interrupt's handler. Meaning to say nesting of interrupts is not possible here. One has to wait until the current ISR is finished to enter into another ISR.
Am i right in saying that Darrel? If that is the case then for any time measuring program we must make sure that the ISR of each of the interrupts are so small that they dont cause a large error in measurement.

Please comment.

Raghunathan

Darrel Taylor
- 13th September 2006, 04:57
That's correct.

No priorities for 16F's. It's a limitation of the PIC's, not the Instant Interrupts.

>> then for any time measuring program we must make sure that the ISR of each of the interrupts are so small that they dont cause a large error in measurement.

Unless you use the capture mode of a CCP module, also true.

But if you switch to 18F's, the problem goes away.
<br>

willem
- 29th September 2006, 11:48
Dear readers,

Although DT_INTS-14 and Multi_SPWM working great if using seperate, I can't get them running combined ....
I included them together with ReEnterPBP.bas getting errors like

ERROR Line 10: Redefinition of VAR. (Multi_SPWM.pbp)
ERROR Line 13: Redefinition of VAR. (Multi_SPWM.pbp)
ERROR Line 14: Redefinition of VAR. (Multi_SPWM.pbp)
ERROR Line 18: Redefinition of VAR. (Multi_SPWM.pbp)
ERROR Line 20: Redefinition of VAR. (Multi_SPWM.pbp)

(if the order I included them is changed I got about same errors by DT_INTS-14)
I guess it's because same variables (psave, wsave etc) used in both of them but I don't have the ASM experience to solve the problem and would appreciate any advise/tips.
Also tips to use another way to interrupt (INT_INT on RB0) Multi_SPWM are welcome...

Thank you !

Willem

Darrel Taylor
- 30th September 2006, 09:52
Hi willem,

It's a little more than the duplicate variables. They also both want exclusive use of the interrupt vector, and they handle the interrupts in a different way too.

I've thought about writing a version for DT_INTS, but just haven't had the time. It's quite doable, but it definately takes some ASM.

Sorry for the bad news,

Darrel Taylor
- 2nd October 2006, 01:19
Ok Willem,

Well, I decided to forget about the things I should have done this weekend, and went ahead and re-wrote the SPWM program to work with the Instant Interrupt system.

I've added a few things, and it works a little different this time around. So, be sure to look close at the example.

It'll work with either the 18F or 14-bit versions, even though I only put it in the DT_INTS-14 section for now.

SPWM_INT
http://www.darreltaylor.com/DT_INTS-14/SPWM.html

Enjoy,

Baddzso
- 3rd October 2006, 00:13
hi all! hi Darrel!
I have a question: with these int handler routines can i use hserin with interrupt? because i think the on interrupt command too slow, i have to wait about 1 ms after first char to the pic jump to int routine and receive other chars with hserin.
many thanks!

pic: 16f690, intosc, ~7,3728MHz

(I don't have time to read everything, sorry if this question are answered...)

Darrel Taylor
- 3rd October 2006, 00:29
Well,

With the example given, Sure!

But with 16F's, if it gets more complicated, you might have problems. The problem is that when you have more than 1 interrupt source, the HSERIN will stop the others from happening while it waits for the data to come in. But if you only intend to use the one interrupt from the USART. No Problem.

If you were using an 18F with multiple INT sources, then the HSERIN could be in a Low Priority Interrupt without any problems at all.
<br>

willem
- 3rd October 2006, 08:29
Hi Darrel,

Great you decide to spent some weekend time on it! I'll hope you did enjoy your weekend anyway..
I will check out the new Multi_SPWM version ASAP and post the results.
Tnx a lot for your kind help.

Regards,
Willem

Baddzso
- 3rd October 2006, 11:01
Thank you for fast reply!
And YES, YES, YES!!!
It works! You are my rescuer!
Thank You!

willem
- 13th October 2006, 11:51
Dear Darrel,

I just would like to let you know the combined DT_INTS-14 and SPWM_INT working fine!!

I control 5 Hi power LED’s Using 5 PWM signals (100Herz, 200 step), LED selecting is done by 3 address lines and the actual control by a pulsed STEP and a UP/DOWN level input.

STEP is causing the INT external interrupt doing the actual PWM change (controlling DutyVar1 to DutyVar5)

Whenever I change a PWM value, it’s stored as the new default in EEprom (using WRITE command with DISABLE INTERRUPT before and ENABLE INTERRUPT after, working OK too).

If you like to have more info on both hardware and software, let me know.
Thank you for your help!

Regards,
Willem

Darrel Taylor
- 13th October 2006, 20:52
Excellent!

That's great Willem. I'd love to see what you've done with it. Maybe you could post it in the "Code Examples" forum. Better as a new thread. This thread is getting so big it would only get lost in the mess.

Or I can put it on the website, as an example for SPWM_INT if you'd like. Hopefully, with a picture of the project too?

shahidali55
- 5th November 2006, 17:52
Hello Darrel,
Is there any way i can implement you instant interrupt routines on PICs which do not have the TMR0 interrupt ( like the PIC16C54A) ???

Darrel Taylor
- 5th November 2006, 21:56
No,

The 16C54A doesn't have any interrupts.

They only have 512 words of program space, 25 bytes of RAM, and a 2-level hardware stack.

At 4 dollars each, I can't imagine why anyone would ever use them.
<br>

mister_e
- 6th November 2006, 00:10
Same observation for 16F84(a)

Darrel Taylor
- 6th November 2006, 03:45
Yeah, no kidding.

Everyone uses those F84's for examples, probably because there's nothing else to confuse you like, USARTs, CCP's, A/D's or SSP's. But man, who'd actually want to use one.

I've had 2 of them for a couple years. But they're still Virgins. Never been plugged into anything.
<br>

keithdoxey
- 6th November 2006, 09:23
Could it simply be that a lot of the information on the net for PIC newbies is for projects using the 16C84 and for simple programmers that program them.

I certainly started with the 16C84 but I wouldnt use one now. For small stuff I use the 16F628 on my existing projects and 16F88 on the new projects because of the bootloader.

Larger projects are using the 16F877 or 18F452 again with bootloaders.

Somewhere I have some 508's including a couple of JW's that were bought and never used along with a UV eraser that has never even ben plugged in and probably never will now !!!!

As far as I am concerned, Flash + Bootloader + PBP + MCS rules :)

dhouston
- 6th November 2006, 15:00
As far as I am concerned, Flash + Bootloader + PBP + MCS rules :)Flash + Bootloader + PBP + MCS + Instant Interrupts rules. <img src="images/smilies/smile.gif" alt="" title="smile" class="inlineimg" border="0">

keithdoxey
- 6th November 2006, 16:59
Flash + Bootloader + PBP + MCS + Instant Interrupts rules. <img src="images/smilies/smile.gif" alt="" title="smile" class="inlineimg" border="0">

I stand corrected :)

Darrel Taylor
- 29th December 2006, 06:15
To: Demon and mister_e,

Hey, did you guys ever figure out the USB with DT_INTs approach.

I was thinking about trying a USB project, and wondered if you 2 ever got it working?
<br>

savnik
- 29th December 2006, 23:55
So far I've shown one interrupt source being used at a time, but as I said in the first post, you can easily service Multiple Interrupt Sources. &nbsp; So what if we wanted to join the previous 3 examples into one program. &nbsp; NOT a problem!

To add more interrupt "Handlers", simply add them to the INT_LIST, and create a subroutine for them.

Since both the Blinky Light, and Elapsed Timer used TMR1, lets move the Blinky Light over to TMR0. Elapsed will still use TMR1.
<font color="#000000"><b>LED1 </b><font color="#008000"><b>VAR </b></font><b>PORTD</b>.<b>0
LED2 </b><font color="#008000"><b>VAR </b></font><b>PORTD</b>.<b>1

</b><font color="#008000"><b>INCLUDE </b></font><font color="#FF0000">&quot;DT_INTS-14.bas&quot; </font><font color="#0000FF"><b><i>' Base Interrupt System
</i></b></font><font color="#008000"><b>INCLUDE </b></font><font color="#FF0000">&quot;ReEnterPBP.bas&quot; </font><font color="#0000FF"><b><i>' Include if using PBP interrupts
</i></b></font><font color="#008000"><b>INCLUDE </b></font><font color="#FF0000">&quot;Elapsed_INT.bas&quot; </font><font color="#0000FF"><b><i>' Elapsed Timer Routines

</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 INT_INT, _ToggleLED1, PBP, yes
INT_Handler TMR0_INT, _ToggleLED2, PBP, yes
INT_Handler TMR1_INT, _ClockCount, PBP, yes
endm
INT_CREATE </font><font color="#0000FF"><b><i>; Creates the interrupt processor

</i></b></font><font color="#000080">INT_ENABLE INT_INT </font><font color="#0000FF"><b><i>; enable external (INT) interrupts
</i></b></font><font color="#000080">INT_ENABLE TMR0_INT </font><font color="#0000FF"><b><i>; enable Timer 0 interrupts
</i></b></font><font color="#000080">INT_ENABLE TMR1_INT </font><font color="#0000FF"><b><i>; Enable Timer 1 Interrupts
</i></b></font><font color="#008000"><b>ENDASM

</b></font><b>OPTION_REG </b>= <b>OPTION_REG </b>&amp; <b>$80 </b>| <b>1 </b><font color="#0000FF"><b><i>; Set TMR0 Prescaler to 256, leave RBPU alone
</i></b></font><font color="#008000"><b>GOSUB </b></font><b>ResetTime </b><font color="#0000FF"><b><i>' Reset Time to 0d-00:00:00.00
</i></b></font><font color="#008000"><b>GOSUB </b></font><b>StartTimer </b><font color="#0000FF"><b><i>' Start the Elapsed Timer

</i></b></font><b>Main</b>:
<font color="#008000"><b>IF </b></font><b>SecondsChanged </b>= <b>1 </b><font color="#008000"><b>THEN
</b></font><b>SecondsChanged </b>= <b>0
</b><font color="#008000"><b>LCDOUT </b></font><b>$FE</b>,<b>$C0</b>, <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
</b><font color="#008000"><b>ENDIF
GOTO </b></font><b>Main

</b><font color="#0000FF"><b><i>'---[INT - interrupt handler]---------------------------------------------------
</i></b></font><b>ToggleLED1</b>:
<font color="#008000"><b>TOGGLE </b></font><b>LED1
</b><font color="#000080">@ INT_RETURN

</font><font color="#0000FF"><b><i>'---[TMR0 - interrupt handler]-------------------------------(Blinky Light)------
</i></b></font><b>T0Count </b><font color="#008000"><b>VAR WORD
</b></font><b>ToggleLED2</b>:
<b>T0Count </b>= <b>T0Count </b>+ <b>1
</b><font color="#008000"><b>IF </b></font><b>T0Count </b>= <b>512 </b><font color="#008000"><b>THEN </b></font><b>T0Count </b>= <b>0 </b>: <font color="#008000"><b>TOGGLE </b></font><b>LED2
</b><font color="#000080">@ INT_RETURN
</font><font size=-2>Code Size = 711 Words</font>

Now we have all three interrupt sources working together in the same program.
LED1 responds to the external INT
LED2 flashes, timed by TMR0
and, the elapsed timer is maintained via TMR1And, all of this is happening behind the scenes of your normal PBP program.
I test for 16f877a and it's work.
But for the 18f88 i got the message : Symbol not previously defined (T0IF)
and not compile.Why;

skimask
- 30th December 2006, 00:27
I test for 16f877a and it's work.
But for the 18f88 i got the message : Symbol not previously defined (T0IF)
and not compile.Why;

That would be a good trick....compiling for an 18F88. I can't seem to find it on the Microchip website. :)

Try TMR0IF (a zero after TMR). Or you don't have an up-to-date version of PBP.

Previous Release: 2.45

* Adds support for PIC12F508, 509, 683, PIC16F505, 684, 688, 716, 737, 747, 767, 777, 87, 88, PIC18F2331, 2431, 2515, 2525, 2585, 2610, 2620, 2680, 4331, 4431, 4515, 4525, 4585, 4610, 4620, 4680, 6410, 6490, 8410 and 8490.

savnik
- 30th December 2006, 01:10
Previous Release: 2.45

* Adds support for PIC12F508, 509, 683, PIC16F505, 684, 688, 716, 737, 747, 767, 777, 87, 88, PIC18F2331, 2431, 2515, 2525, 2585, 2610, 2620, 2680, 4331, 4431, 4515, 4525, 4585, 4610, 4620, 4680, 6410, 6490, 8410 and 8490.
I have 2.46

skimask
- 30th December 2006, 01:19
I have 2.46

Well, if TMR0IF (or T0IF for that matter) doesn't work, then just change the code to access the interrupt flag bit directly from the applicable register.

Darrel Taylor
- 30th December 2006, 03:21
Microchip can't make up thier mind on what they want to call things. In most 16F's it's called T0IF, and in the 18F's it's TMR0IF, but for some reason, in a 16F88 it's also called TMR0IF. It's the same with the T0IE/TMR0IE.

Fortunately, we aren't stuck with whatever they decide to call things.

Just add the 2 highlighted lines, and you should be fine. (no spaces before them)
ASM
T0IF = TMR0IF
T0IE = TMR0IE
INT_LIST macro ; IntSource, Label, Type, ResetFlag?
INT_Handler INT_INT, _ToggleLED1, PBP, yes
INT_Handler TMR0_INT, _ToggleLED2, PBP, yes
INT_Handler TMR1_INT, _ClockCount, PBP, yes
endm
INT_CREATE ; Creates the interrupt processor

INT_ENABLE INT_INT ; enable external (INT) interrupts
INT_ENABLE TMR0_INT ; enable Timer 0 interrupts
INT_ENABLE TMR1_INT ; Enable Timer 1 Interrupts
ENDASM

savnik
- 30th December 2006, 10:48
Thank you.
Now it's work.

mister_e
- 30th December 2006, 14:13
To: Demon and mister_e,

Hey, did you guys ever figure out the USB with DT_INTs approach.

I was thinking about trying a USB project, and wondered if you 2 ever got it working?
<br>

Well, i hate to say that Darrel but something goes bad when using instant interrupt and USB. Maybe some PBP variable need to be saved or something like that.

Bellow is a short and sweet working example using ON INTERRUPT to do the USBSERVICE each 100uSec.

OK it doesn't do anything else than sitting there and spin but, it keeps the connection alive without any Windows Warning. Once this solve, it should fix USBOUT and USBIN... or help to ;)

It use a PIC18F4550 and a 4MHZ crystal OSC.


asm
__CONFIG _CONFIG1L, _PLLDIV_1_1L & _CPUDIV_OSC1_PLL2_1L & _USBDIV_2_1L
; ; ; USB clock source comes from the 96 MHz PLL divided by 2
; ; [OSC1/OSC2 Src: /1][96 MHz PLL Src: /2]
; No prescale (4 MHz oscillator input drives PLL directly)


__CONFIG _CONFIG1H, _FOSC_XTPLL_XT_1H & _FCMEN_OFF_1H & _IESO_OFF_1H
; ; ; Oscillator Switchover mode disabled
; ; Fail-Safe Clock Monitor disabled
; XT oscillator, PLL enabled, XT used by USB
__CONFIG _CONFIG2L, _PWRT_ON_2L & _BOR_ON_2L & _BORV_2_2L & _VREGEN_ON_2L
__CONFIG _CONFIG2H, _WDT_OFF_2H
__CONFIG _CONFIG3H, _MCLRE_ON_3H & _LPT1OSC_OFF_3H & _PBADEN_OFF_3H & _CCP2MX_ON_3H
__CONFIG _CONFIG4L, _STVREN_ON_4L & _LVP_OFF_4L & _ICPRT_OFF_4L & _XINST_OFF_4L & _DEBUG_OFF_4L
endasm
DEFINE OSC 48

PORTB = 0
TRISB.0 = 0

LED0 VAR PORTB.0
TMR0IF VAR INTCON.2
TMR0ON VAR T0CON.7

INTCON = %10100000 ' Enable global and TMR0 interrupts
T0CON = %10000000 ' TMR0, CLK internal, prescaler 1:2, T0ON

UCFG var byte EXT ' include UCFG register... Yeah Melabs didn't :o(

Reload con 65000 ' ~100 uSec
ucfg = %00010100 ' enable internal USB pull-up, Full speed USB

goto SkipMacro
asm
Reload_TMR0 macro
BCF _TMR0ON ; stop timer
MOVE?CW _Reload,TMR0L ; reload
BCF _TMR0IF ; clear overflow flag
BSF _TMR0ON ; start timer
ENDM
endasm

SkipMacro:
pause 500 ' Settle delay
usbinit ' initialise USB...
@ Reload_TMR0 ; Reload timer0
ON INTERRUPT GOTO DoUSBService

Start:
goto start ' Spin 'till you die!

DISABLE
DoUSBService:
toggle LED0 ' toggle LED each time
usbservice ' keep connection alive
@ Reload_TMR0 ; reload timer
RESUME ' getout of here
ENABLE

So nothing complicated... just spinning and keep USB connection alive.

NOW, if i use the DT interrupt, IT SHOULD looks like this


asm
__CONFIG _CONFIG1L, _PLLDIV_1_1L & _CPUDIV_OSC1_PLL2_1L & _USBDIV_2_1L
; ; ; USB clock source comes from the 96 MHz PLL divided by 2
; ; [OSC1/OSC2 Src: /1][96 MHz PLL Src: /2]
; No prescale (4 MHz oscillator input drives PLL directly)


__CONFIG _CONFIG1H, _FOSC_XTPLL_XT_1H & _FCMEN_OFF_1H & _IESO_OFF_1H
; ; ; Oscillator Switchover mode disabled
; ; Fail-Safe Clock Monitor disabled
; XT oscillator, PLL enabled, XT used by USB
__CONFIG _CONFIG2L, _PWRT_ON_2L & _BOR_ON_2L & _BORV_2_2L & _VREGEN_ON_2L
__CONFIG _CONFIG2H, _WDT_OFF_2H
__CONFIG _CONFIG3H, _MCLRE_ON_3H & _LPT1OSC_OFF_3H & _PBADEN_OFF_3H & _CCP2MX_ON_3H
__CONFIG _CONFIG4L, _STVREN_ON_4L & _LVP_OFF_4L & _ICPRT_OFF_4L & _XINST_OFF_4L & _DEBUG_OFF_4L
endasm
DEFINE OSC 48
PORTB = 0
TRISB.0 = 0

LED0 VAR PORTB.0
TMR0IF VAR INTCON.2
TMR0ON VAR T0CON.7

INTCON = %10100000 ' Enable global and TMR0 interrupts
T0CON = %10000000 ' TMR0, CLK internal, prescaler 1:2, T0ON

UCFG var byte EXT ' include UCFG register... Yeah Melabs didn't :o(

Reload con 65000 ' ~100 uSec
ucfg = %00010100 ' enable internal USB pull-up, Full speed USB

INCLUDE "DT_INTS-18.bas" ' Base Interrupt System
INCLUDE "ReEnterPBP-18.bas" ' Include if using PBP interrupts

goto skipmacro

ASM
INT_LIST macro ; IntSource, Label, Type, ResetFlag?
INT_Handler TMR0_INT, _DoUSBService, PBP, no
endm
INT_CREATE ; Creates the interrupt processor

Reload_TMR0 macro
BCF _TMR0ON ; stop timer
MOVE?CW _Reload,TMR0L ; reload
BCF _TMR0IF ; clear overflow flag
BSF _TMR0ON ; start timer
ENDM
endasm

SkipMacro:
pause 500
usbinit ' initialise USB...
@ Reload_TMR0
@ INT_ENABLE TMR0_INT

Start:
goto start

DoUSBService:
toggle led0
usbservice
@ Reload_TMR0
@ INT_RETURN


Right or i screw something? Anyways ON both, the LED work as expected (so i shouldn't be too wrong) but, the second lost the USB connection really soon... and yeah you have to reboot or it will reboot for you if you disconnect
the USB plug. It's getting boring :eek:

i attach everything i have in my C:\PBP_PROG\USBDemo folder, including a compiled VB utility to monitor if the device is Connected or Not when using EasyHID default VendorID and ProductID


<img SRC="http://www.picbasic.co.uk/forum/attachment.php?attachmentid=1300&stc=1&d=1167484091">


So for now, i still use the On Interrupt... Before i read and understand the whole Jan Axelson book, and build my own USB macros, i may need much spare time... oh yeah it's more than a RS-232 and there's a lot of improvements and adds to do with PBP.

Now the weird stuff... Melabs didn't include the 'interesting' registers like UCFG, UIR,UIE,UEIR,UEIE and probably others... bah xxx VAR BYTE EXT fix it for now and if needed.

To be honest, i didn't search really hard to find the problem source... getting lazy i guess :-)

Darrel Taylor
- 31st December 2006, 13:18
Wow, it seems like that should work?

That sure gives me a starting point, (good one)

And since you're also in such a good "moon" :)

I'll take a look at ...
http://www.picbasic.co.uk/forum/showthread.php?t=5418
Too
<br>

mister_e
- 31st December 2006, 13:26
http://www.mister-e.org/Pics/DOH.jpg

Well maybe i should say MOOD?
Your Canadian to English dictionnary is still good :D

Enjoy!

Darrel Taylor
- 31st December 2006, 13:39
Well, if I look at my girlfriend ... Moon's and Mood's have the same period, 27.3 days. :D

Don't know how that fit's in with you though :eek:
<br>

mister_e
- 31st December 2006, 13:45
Yeah, it remind me something... sometimes i'm glad to be 'single' :D

Darrel Taylor
- 7th January 2007, 06:17
Steve,

I got my parts in for USB (gotta love ebay), and I've built up a breadboard with a 4550 and LED's, switches etc.
I've looked at the example from post #143, the second one, with DT_INTS, and found two problems. The ...

INTCON = %10100000 ' Enable global and TMR0 interrupts

was causing the TMR0 interrupts to start servicing the USB before it was initialized. DT_INTS handles all the interrupt enable bits, so you don't need it anyway.

The other problem was ...

goto skipmacro

was skipping over the interrupt defintion. That section of code needs to execute so that it can handle the enable bits and setup a couple other variables.

Once I made those changes, the program works as expected, and never looses connection.
<hr>
But here's the good part, :cool:

After going through the USB18.ASM file and seeing how things worked, it soon became apparent that those routines are setup to use the USB interrupts(even though PBP doesn't use them that way). It just needs a "kick-start" to get it going. The "kick-start" is simply a tight loop servicing the USB until the driver gets to the "CONFIGURED_STATE". After that it takes off and handles itself.

But the best part is that it doesn't use ANY PBP system variables to service the USB. So the whole thing can be treated like ASM interrupts, and tied directly into the USB_INT interrupt.

This also seems to improve the response time since it can react immediately to each step of the USB protocol, instead of after each interval of the timer, or whenever ON INTERRUPT get's around to it, but I don't have any hard data to back that up yet.

Here's your PIC program from the [USBDemo, something to learn USB a little bit (http://www.picbasic.co.uk/forum/showthread.php?t=5418)]thread /.zip file.
Modified to use DT_INTS-18 and the USB interrupt.
All the other files are the same.

http://www.darreltaylor.com/files/USBDemo2_DT.txt

Works great with the "Mister E USBDemo" program.
<br>

mister_e
- 7th January 2007, 11:12
http://www.mister-e.org/Pics/HatsOff.gif

Yup it's working really well indeed. Interesting how it could be handled as ASM... Being said, it open a wide range of USB testpoints as well.

Oh... when i compiled your example i got an error message... Config fuses related... in this line

__CONFIG _CONFIG1H, _FOSC_XTPLL_XT_1H & _FCMEM_OFF_1H . . . . . .

Must be _FCMEN_OFF_1H

Thank you very much Darrel for your time on this one!

Now, i have to read the USB18.ASM file to understand WHY it's working like that now, AND to see what else we can do with :cool:


; Modified by Darrel Taylor, Don't blame Steve
http://www.mister-e.org/Pics/ROFL.gif

Darrel Taylor
- 7th January 2007, 11:33
Must be _FCMEN_OFF_1H

Interesting, I got the same error with your's. Except I had to change it to _FC_MEM

After further review I see the P18F4550.inc file in my "MPASM Suite" folder shows these configs for CONFIG1H
;----- CONFIG1H Options --------------------------------------------------
_FOSC_XT_XT_1H EQU H'F0' ; XT oscillator, XT used by USB
_FOSC_XTPLL_XT_1H EQU H'F2' ; XT oscillator, PLL enabled, XT used by USB
_FOSC_ECIO_EC_1H EQU H'F4' ; External clock, port function on RA6, EC used by USB
_FOSC_EC_EC_1H EQU H'F5' ; External clock, CLKOUT on RA6, EC used by USB
_FOSC_ECPLLIO_EC_1H EQU H'F6' ; External clock, PLL enabled, port function on RA6, EC used by USB
_FOSC_ECPLL_EC_1H EQU H'F7' ; External clock, PLL enabled, CLKOUT on RA6, EC used by USB
_FOSC_INTOSCIO_EC_1H EQU H'F8' ; Internal oscillator, port function on RA6, EC used by USB
_FOSC_INTOSC_EC_1H EQU H'F9' ; Internal oscillator, CLKOUT on RA6, EC used by USB
_FOSC_INTOSC_XT_1H EQU H'FA' ; Internal oscillator, XT used by USB
_FOSC_INTOSC_HS_1H EQU H'FB' ; Internal oscillator, HS used by USB
_FOSC_HS_1H EQU H'FC' ; HS oscillator, HS used by USB
_FOSC_HSPLL_HS_1H EQU H'FE' ; HS oscillator, PLL enabled, HS used by USB

_FCMEM_OFF_1H EQU H'BF' ; Fail-Safe Clock Monitor disabled
_FCMEM_ON_1H EQU H'FF' ; Fail-Safe Clock Monitor enabled

_IESO_OFF_1H EQU H'7F' ; Oscillator Switchover mode disabled
_IESO_ON_1H EQU H'FF' ; Oscillator Switchover mode enabledIs yours different?

If you want more info on the ASM handling of the USB_INT, I can elaborate some.
<br>

skimask
- 7th January 2007, 11:41
Interesting, I got the same error with your's. Except I had to change it to _FC_MEM

After further review I see the P18F4550.inc file in my "MPASM Suite" folder shows these configs for CONFIG1H

Is yours different?

If you want more info on the ASM handling of the USB_INT, I can elaborate some.
<br>

Just checked mine for grins...
I've got FCMEM in my 4550.INC file

Also checked the file straight from the .zip file from Microchip, it's the same.

mister_e
- 7th January 2007, 11:41
Yup! seems mine is different... looking on another forum thread (12 Bytes code one ;) ) i know we don't have the same MPLAB version... 7.50 Here, MPASM 5.06

Here's a .inc file quote]


_FOSC_HS_1H EQU H'FC' ; HS oscillator, HS used by USB
_FOSC_HSPLL_HS_1H EQU H'FE' ; HS oscillator, PLL enabled, HS used by USB

_FCMEN_OFF_1H EQU H'BF' ; Fail-Safe Clock Monitor disabled
_FCMEN_ON_1H EQU H'FF' ; Fail-Safe Clock Monitor enabled

_IESO_OFF_1H EQU H'7F' ; Oscillator Switchover mode disabled
_IESO_ON_1H EQU H'FF' ; Oscillator Switchover mode enabled

and above... with the new CONFIG plah plah...


; Fail-Safe Clock Monitor Enable bit:
; FCMEN = OFF Fail-Safe Clock Monitor disabled
; FCMEN = ON Fail-Safe Clock Monitor enabled

Anyways.. it's no surprise at all that Microchip change it from a version to another :D



If you want more info on the ASM handling of the USB_INT, I can elaborate some.

http://www.mister-e.org/Pics/YES.gif

EDIT: i'll download the new MPLAB version and see what's different or Still the same... interesting...

EDIT #2 : Just remove and re-install V7.50 (No i never download a interim version) and FCMEN is still good. Maybe they discover that Fail safe Clock Monitor Emable make no sense? Same as mixing Moon and Mood :-]

Darrel Taylor
- 7th January 2007, 12:25
Hmm, I think we have a Spock moment here... "Fascinating!".


http://www.mister-e.org/Pics/YES.gif

OK, 3AM here, sleep first. ASM Interrupts tomorrow.


EDIT #2 : Just remove and re-install V7.50 (No i never download a interim version) and FCMEN is still good. Maybe they discover that Fail safe Clock Monitor Emable make no sense? Same as mixing Moon and Mood :-]

Looks like it's time for an upgrade on my end. Arrrrgh!
But here, let me shoot the moon first.

<table width=200 height=150><tr><td bgcolor="White" align=center><b>Censored</b></td></tr></table>
Whew!, You're lucky that didn't go through.
<br>

xxdymhbh
- 30th January 2007, 10:06
What version of the compiler should be used? Thanks,

mister_e
- 30th January 2007, 16:50
2.46 or higher (2.47 here)

MPASM... just download the latest version of MPLAB 7.51 (maybe 7.52 now).

sougata
- 20th February 2007, 09:01
Hi,

I need to call a subroutine from within a low priority PBP instant interrupt on a PIC 18F452. I am using both High Priority and Low Priority Interrupts.

I need to know whether PBP uses a software stack for its gosub calls or use the PIC18 stack pointer. I am concerned if calling a nested gosub from within a PBP InstInt would cause stack overflow.

Darrel Taylor
- 20th February 2007, 14:34
PBP uses the hardware Stack. But with 31 levels on the 18F's, you have to be pretty sloppy to overflow it.

The PIC itself uses the Hardware Stack to handle an interrupt. But, DT_INTS does NOT use the Hardware Stack. It essentially uses a 2-level software stack. 1 for High Priority, and 1 for Low.

Once in an interrupt, it's OK to call a subroutine, as long as both HIGH and LOW priorities can never call the same routine at the same time.

HTH,

sougata
- 21st February 2007, 05:23
Dear Darrel,

Thank you for the reply. I am using ASM interrupts on your system for the the high priority and your system already uses the shadow register for HP (retfie fast).

My main routine has deep calls and in the low priority interrupts I am using PBP. I was actually overflowing the stack causing a MCU reset (configured for reset under STACK Over/underflow). I have re-structured my code to handle it already.

I must thank you once again for the great job you have done. It is not only about using PBP in Interrupts it is more manageable than asm.

Squibcakes
- 21st February 2007, 05:25
DT,

I'm trying to force an interrupt whenever the voltage on my analog input pin changes (connected to a 5k POT and RA:0, 16F88).

I was hopping that AD_INT handler would fire when ever the POT was adjusted but it doesn't.

I can read the POT voltage ok in my program, so I think all the analog stuff is set ok.

Is what I am trying to do gonna work or not?

Squib

sougata
- 21st February 2007, 05:49
Hi,

an interrupt whenever the voltage on my analog input pin changes

The ADC takes a finite time to complete its conversion. When the conversion is complete the AD_INT flag is set. This means that you should always start your conversion manually. However your PIC16F88 has a compare module. That can automatically setup periodic conversion of your AD module. So you would be getting interrupts from the AD_INT that a new value is available. Just read the AD results and compare it with the previous one to find out if your pot has been changed. Please note do not expect two consecutive conversions to be exactly equal even if you are not touching the pot. Supply, layout, noise, blah, blah...... . So compare it for a change of value within a range.

Darrel Taylor
- 21st February 2007, 05:50
sougata,

I'm glad it's working out for you. And yes, it is more managable. Kinda the whole idea behind it. :)

Squibcakes,

No, it doesn't work that way.

The AD_INT is fired on the completion of an A/D conversion. Not when the value changes.

So, in your AD_INT handler, you could test to see if the recent A/D reading differs from the previous A/D value. If it does, call a subroutine.

Then start another conversion before exiting the handler.

Added: Or like sougata said, have a timer periodicaly start a conversion, then do the same.

HTH,

Squibcakes
- 21st February 2007, 06:16
Hmm,

That kind of defeats the purpose of what I wanted to do....

All understood and thanks for the info.

Rgds,
Squib

sougata
- 21st February 2007, 08:20
Hi Squibcakes,

You can use your compare module to automatically fire your ADC at a given interval. So the ADC will automatically generate interrupts. In your interrupt routine compare the current value with the old value. Keep some margin as two consecutive results may be different even if your pot is unchanged. When a change is found set a flag and process it in your main loop.

Homerclese
- 2nd March 2007, 00:50
Hello,


I have been toying with Darrels' interrupts and the elapsed timer

programs. It's an amazing piece of work and just what I need at the

moment. Thanks!

Going on, I tried the "bring together" demo but that didn't go so

well. It won't compile using MPASM. The error messages are ;


FATAL ERROR too many errors
Error line 15: redefination of VAR. (DT_INTS-14.bas)
Error line 26: redefination of VAR. (DT_INTS-14.bas)
Error line 27: redefination of VAR. (DT_INTS-14.bas)


........Etc.


I am using the Pic 16f877 but that shouldnt matter at this point.

Any ideas?

Thanks John

mister_e
- 2nd March 2007, 01:07
mmm, weird, no problem here. so we talk about
http://darreltaylor.com/DT_INTS-14/combine.html

If so, did you add something special in the code or you're using EXACTLY the following...


LED1 VAR PORTD.0
LED2 VAR PORTD.1

INCLUDE "DT_INTS-14.bas" ' Base Interrupt System
INCLUDE "ReEnterPBP.bas" ' Include if using PBP interrupts
INCLUDE "Elapsed_INT.bas" ' Elapsed Timer Routines

ASM
INT_LIST macro ; IntSource, Label, Type, ResetFlag?
INT_Handler INT_INT, _ToggleLED1, PBP, yes
INT_Handler TMR0_INT, _ToggleLED2, PBP, yes
INT_Handler TMR1_INT, _ClockCount, PBP, yes
endm
INT_CREATE ; Creates the interrupt processor
ENDASM

OPTION_REG = OPTION_REG & $80 | 1 ; Set TMR0 Prescaler to 256, leave RBPU alone
@ INT_ENABLE INT_INT ; enable external (INT) interrupts
@ INT_ENABLE TMR0_INT ; enable Timer 0 interrupts
@ INT_ENABLE TMR1_INT ; Enable Timer 1 Interrupts

GOSUB ResetTime ' Reset Time to 0d-00:00:00.00
GOSUB StartTimer ' Start the Elapsed Timer

Main:
IF SecondsChanged = 1 THEN
SecondsChanged = 0
LCDOUT $FE,$C0, DEC Days,"d-",DEC2 Hours,":",DEC2 Minutes,":",DEC2 Seconds
ENDIF
GOTO Main

'---[INT - interrupt handler]---------------------------------------------------
ToggleLED1:
TOGGLE LED1
@ INT_RETURN

'---[TMR0 - interrupt handler]-------------------------------(Blinky Light)------
T0Count VAR WORD
ToggleLED2:
T0Count = T0Count + 1
IF T0Count = 512 THEN T0Count = 0 : TOGGLE LED2
@ INT_RETURN

which version of PBP and MPASM are you using?

Are all files located in the same folder?

Homerclese
- 2nd March 2007, 09:05
Hello,

I tried a cut and paste of your code and got a whole new set of errors. The only code differences I could find were the ones at the top for outputting to a LCD display. The include files all exist in my usual PBP folder. I'm using Microcode Studio version 2.2.1.1 with Pic Basic Pro 2.40.


Thanks John

mister_e
- 2nd March 2007, 16:21
did you get...

<img SRC="http://www.picbasic.co.uk/forum/attachment.php?attachmentid=1438&stc=1&d=1172848778">

If so, make sure you have selected MPASM in the View>> Compile And Program option >>> Assembler

EDIT

Pic Basic Pro 2.40.

:eek: I don't know if it could be the problem... The current version is now 2.47.

Homerclese
- 2nd March 2007, 22:59
Gettin' better!

MPASM box was not checked. I didn't know it existed. No errors on compile now, however it can not find the .HEX file for programming. I did a system search and there is no .HEX file generated after compile. There are .HXH and .HXL files.

Is your result box a screen capture?

Thanks again

mister_e
- 3rd March 2007, 01:32
It happen because you probably have selected INH8XS file format under the MPASM check box. use INHX8M instead.


Is your result box a screen capture?

Yes indeed, CTRL + PrintScr, then you paste it in Paint or whatever else to edit it.

Homerclese
- 3rd March 2007, 18:40
Good, That worked. However, when I add a line to the top of the program as simple as :
TRISA = %00000000
AlarmOUT VAR PORTA.0

I get

Error[113 c:pbp\pbpic14.lib 1588 : Symbol not previously defined (port A)
Error[113 c:pbp\pbpic14.lib 1612 : Symbol not previously defined (port A)
Error[113 c:pbp\pbpic14.lib 1619 : Symbol not previously defined (port A)

.........Etc.


Also, going back to the previously working "elapsed timer demo" and using the MPASM settings I get the same type of errors there if I try to add a port reference.

I can get the result box into Photoshop but can't get the edited image to paste into the forum.


Thanks

mister_e
- 3rd March 2007, 22:55
<table><td>http://www.mister-e.org/Pics/Angry_barbarian</td><td>It really drives me nuts when it work here but not elsewhere. Ok then just copy/paste your code here and place it between code bracket. you just need to type...



---paste your code here---


to edit your screen capture, use Windows paint. If you don't find it, click on Start> run then type mspaint. then save it to a .jpg file</td></table>

skimask
- 3rd March 2007, 23:27
Good, That worked. However, when I add a line to the top of the program as simple as :
TRISA = %00000000
AlarmOUT VAR PORTA.0

I get

Error[113 c:pbp\pbpic14.lib 1588 : Symbol not previously defined (port A)
Error[113 c:pbp\pbpic14.lib 1612 : Symbol not previously defined (port A)
Error[113 c:pbp\pbpic14.lib 1619 : Symbol not previously defined (port A)

.........Etc.


Also, going back to the previously working "elapsed timer demo" and using the MPASM settings I get the same type of errors there if I try to add a port reference.

I can get the result box into Photoshop but can't get the edited image to paste into the forum.


Thanks

You said you were using the 16F877. Are you sure it's not the 16F877A?
'cause if it is, you need to upgrade your PBP. You said you've got PBP 2.40. The 16F877A isn't supported until PBP 2.42

Homerclese
- 4th March 2007, 10:12
"Not previously defined" error was caused by having PortA instead of PORTA. It's 4AM and I think MPASM is the cause of some strange chip behavior. Only when I uncheck MPASM do I get back to a working 16F877 chip. I patched pic basic Pro to 2.40 but any attempts to go higher are met with "unknown version" errors. I'll hit it again tommorrooowww....

"Homer sleep now".

mister_e
- 4th March 2007, 19:05
somehow strange but you could still try to uncheck the Case Sensitive option in MCS.

arniepj
- 6th March 2007, 18:36
Darrel,
I recently replaced the On Interrupt code in an existing program with the RX_INT and it works great.The code was reduced by 127 words and I was able to eliminate a interrupt anomaly I sometimes experienced.Though compilation was successful,I would get a warning "Temp variables exceeding T4",which was generated in the ReEnterPBP.bas.I found what caused it in my code was this long comparison evaluation "if (fwd_cycle_comp = 1 and portb.4 = 1 and portb.2 = 1 and porta.0 = 1) or (datain1 > 1638) then".If I shortened the code the warning disappeared.Since everything was working fine I commented out the error routine for T4.I am using the latest Mplab and PBP.
Thanks & Good Job

Darrel Taylor
- 6th March 2007, 20:49
Since everything was working fine I commented out the error routine for T4.

As long as the long formula isn't in the Interrupt Handler, you should be OK.

There's no way for the program to tell if a complex formula is in the handler or somewhere else. So I err'd on the side of caution and had it give a warning no matter where it is.

Glad you like it. :)

mister_e
- 6th March 2007, 23:11
So I err'd on the side of caution and had it give a warning no matter where it is.


Maybe on POST 116 which is few time after the Green splat thingy ;)
http://www.picbasic.co.uk/forum/showpost.php?p=25297&postcount=116

leisryan
- 8th March 2007, 06:53
Good day to all!!!
I'm Ryan from the philippines i've been wanting to use my homebuilt icd2 but i'm having a hard time compiling my sourcecode with Darrel's instant interrupt in MPLAB has anyone tried and successfully compiled it in MPLAB?
To anyoneThanks in advance!!!

mister_e
- 8th March 2007, 06:57
is this happen to ANY PBP program or just when using DT-INT.

I don't know why it shouldn't. can you at least post some code OR the errors message + PIC#

leisryan
- 9th March 2007, 01:42
Yes indeed just when using dt_ints it fails to compile here are the following error message

"Executing: "C:\PBP\PBPW.EXE" -p16F877A -ampasm -oq -z "SMS_CONTROL1_MPLAB.bas"
Error[113] C:\PBP\PBPPIC14.LIB 2784 : Symbol not previously defined (PortD)
Error[113] C:\PBP\PBPPIC14.LIB 2785 : Symbol not previously defined (PortD)
Error[113] C:\PBP\PBPPIC14.LIB 2789 : Symbol not previously defined (PortD)
Error[113] C:\PBP\PBPPIC14.LIB 2790 : Symbol not previously defined (PortD)
Error[113] C:\PBP\PBPPIC14.LIB 2800 : Symbol not previously defined (PortD)
Error[113] C:\PBP\PBPPIC14.LIB 2871 : Symbol not previously defined (PortD)
Error[113] C:\PBP\PBPPIC14.LIB 2889 : Symbol not previously defined (PortD)
Error[113] C:\PBP\PBPPIC14.LIB 2913 : Symbol not previously defined (PortD)
Error[113] C:\PBP\PBPPIC14.LIB 2920 : Symbol not previously defined (PortD)
Error[113] C:\PBP\PBPPIC14.LIB 2928 : Symbol not previously defined (PortD)
Error[113] C:\PBP\PBPPIC14.LIB 2934 "

skimask
- 9th March 2007, 02:04
Yes indeed just when using dt_ints it fails to compile here are the following error message

"Executing: "C:\PBP\PBPW.EXE" -p16F877A -ampasm -oq -z "SMS_CONTROL1_MPLAB.bas"
Error[113] C:\PBP\PBPPIC14.LIB 2784 : Symbol not previously defined (PortD)
Error[113] C:\PBP\PBPPIC14.LIB 2785 : Symbol not previously defined (PortD)
Error[113] C:\PBP\PBPPIC14.LIB 2789 : Symbol not previously defined (PortD)
Error[113] C:\PBP\PBPPIC14.LIB 2790 : Symbol not previously defined (PortD)
Error[113] C:\PBP\PBPPIC14.LIB 2800 : Symbol not previously defined (PortD)
Error[113] C:\PBP\PBPPIC14.LIB 2871 : Symbol not previously defined (PortD)
Error[113] C:\PBP\PBPPIC14.LIB 2889 : Symbol not previously defined (PortD)
Error[113] C:\PBP\PBPPIC14.LIB 2913 : Symbol not previously defined (PortD)
Error[113] C:\PBP\PBPPIC14.LIB 2920 : Symbol not previously defined (PortD)
Error[113] C:\PBP\PBPPIC14.LIB 2928 : Symbol not previously defined (PortD)
Error[113] C:\PBP\PBPPIC14.LIB 2934 "

Which version of PBP?

mister_e
- 9th March 2007, 02:24
The problem is due to your LCD DEFINES

' LCD Display
' -----------
DEFINE LCD4X20
DEFINE LCD_DREG PortD ' Set LCD Data to PortD
DEFINE LCD_DBIT 0 ' Set starting Data to Bit0
DEFINE LCD_EREG PortD ' Set LCD Enable to PortC
DEFINE LCD_EBIT 5 ' Set LCD Enable line to PortC.1
DEFINE LCD_RSREG PortD ' Set LCD Register Select to PortB
DEFINE LCD_RSBIT 4 ' Set LCD RS line to PORTC.0
DEFINE LCD_BITS 4 ' Set for a 8 bit Bus


Always make sure that ALL DEFINEs are properly written. you MUST use PORTD in uppercase.

skimask
- 9th March 2007, 02:39
The problem is due to your LCD DEFINES

' LCD Display
' -----------
DEFINE LCD4X20
DEFINE LCD_DREG PortD ' Set LCD Data to PortD
DEFINE LCD_DBIT 0 ' Set starting Data to Bit0
DEFINE LCD_EREG PortD ' Set LCD Enable to PortC
DEFINE LCD_EBIT 5 ' Set LCD Enable line to PortC.1
DEFINE LCD_RSREG PortD ' Set LCD Register Select to PortB
DEFINE LCD_RSBIT 4 ' Set LCD RS line to PORTC.0
DEFINE LCD_BITS 4 ' Set for a 8 bit Bus


Always make sure that ALL DEFINEs are properly written. you MUST use PORTD in uppercase.

Of course! That's right! Just like it says in the PBP manual on page 30!

mister_e
- 9th March 2007, 05:10
and one suggestion, add

@ errorlevel -306

as MPLAB output list a $%$%^ load of those annoying...

Message[306] C:\PBP\PBPPIC14.LIB 624 : Crossing page boundary -- ensure page bits are set.

leisryan
- 10th March 2007, 04:15
thanks Mr. E!!! thanks skimask!!! next time i'll post my orcad and gerber file of my clone icd2 here so everybody can have a taste of it!!! trully wonderful debugger and fast programmer too!!!

sougata
- 13th March 2007, 19:07
Hi,

I hope this is the right place to grab your attention. I am using a 16F73 @ 20Mhz with Hardware USART @ 115Kbps. I am using RB0 external interrupt portb.0 (can't help it only it is available) . Initially it is set to fire interrupt on a Low2High edge. Now when inside the interrupt I want to toggle the INT edge bit in the option_reg to have an interrupt on High2Low edge. The simple idea is to reset a timer when a variable duty cycle pulse begin and read the timer value when it turns off. Can't sit in a tight loop to watch if portb.0 = 0 cause got other tasks to do. So I am using Darrel's INT in both ASM and PBP. Here is the code:



ASM
INT_LIST macro ; IntSource, Label, Type, ResetFlag?
INT_Handler INT_INT, INT_ASM, ASM, NO
INT_Handler INT_INT, _INT_PBP, PBP, YES
endm
INT_CREATE ; Creates the interrupt processor
ENDASM

; BELOW IS THE ASM INTERRUPT HANDLER
ASM
INT_ASM
BSF STATUS, RP0 ; SELECT BANK 1
BTFSS OPTION_REG, INTEDG ; CHECK THE INTERRUPT EDGE
GOTO EDGE_LOW

; IF HERE THEN EDGE IS HIGH2LOW AND INT OCCURED AND NEEDS TO BE ALTERED/////////
EDGE_HIGH
BCF OPTION_REG, INTEDG ; SET TO INTERRUPT ON LOW2HIGH TRANSITION
CLRF STATUS ; SELECT BANK0
CLRF TMR0 ; CLEAR TIMER0
BSF _HIGH_EDGE ; SET FLAG THAT THIS IS A LOW2HIGH_EDGE INT
INT_RETURN ; RETURN FROM THE ASM INTERRUPT
; IF HERE THEN EDGE IS LOW2HIGH AND INT OCCURED AND NEEDS TO BE ALTERED ////////
EDGE_LOW
; BANK1 IS ALREADY SELECTED
BSF OPTION_REG, INTEDG ; SET TO INTERRUPT ON LOW
CLRF STATUS ; SELECT BANK0
MOVF TMR0, 0 ; MOVE TIMER0 TO W
MOVWF _TIMER ; MOVE TO THE TIMER VARIABLE IN BANK 0
BCF _HIGH_EDGE ; SET FLAG THAT THIS IS HIGH2LOW_EDGE INT
INT_RETURN ; RETURN FROM THE ASM INTERRUPT
ENDASM

INT_PBP: ' PBP INTERRUPT HANDLER
IF HIGH_EDGE = 1 THEN '
HSEROUT [10,"L2H",10] '
@ INT_RETURN ; RETURN FROM INSTANT INTERRUPT
ELSE
HSEROUT [10,"H2L",#TIMER, 10]
ENDIF
@ INT_RETURN ; RETURN FROM INSTANT INTERRUPT


Now my questions are :

1. Will this work ? Chances of false interrupt should not be, cause anyway while changing the option_reg the INT0 flag is not cleared and taken care of in the next PBP slice. Am I right ?

2. Should I manually check the transmit buffert (TRMT) and do the transmission to make things faster or let it be handled by PBP (keeps my hairfall under control ;))

P.S. : Actually I am counting on the email notification and everybody working with Darrel's II :D. Lester/Darrel please move this thread if you think that this should go as a new thread.

Darrel Taylor
- 13th March 2007, 19:35
As far as the interrupt routines go, it looks like it should work.

But the limiting factor is the number of bytes you're sending the results with.
Even at 115200, sending a string of 10 characters will take over 800us. With trying to find both high and low transitions you double that (1600us). So you'd be limiting the frequency to around 600hz.

I don't think a buffer and TX handler would help speed it up, because it's just the total amount of data being sent that limits it. A buffer would just over-run if it couldn't keep up.

HTH,

emavil
- 13th March 2007, 23:56
Hi Darrel

I've seen lots sample codes of digital clock and elapsed timer demos in this forum and all of them are using LCD as an output device. I was wondering why is it that nobody post sample codes driving 7-segment displays in multiplex mode?

I've seen your code and it was amazing. I tried compiling it but i received errors. I'm using PIC16F628A, 4MHz xTAL and PICBasic Pro v2.33.

I'm planning to test your code using TMR0 interrupt handling the refreshing of the 7-segments and TMR1 handling the 1/100 timer tick.

Can you share to me sample approaches on how to handle the elapsed timer using 7-segment displays in multiplexed mode?


emavil

sougata
- 14th March 2007, 05:22
Hi,

It works. Your II rules. I am using it to 100Hz and thanks for your concern.

Normnet
- 18th March 2007, 16:02
Interrupt for 18F's works fine.
How to write assembly to set a variable instead of toggle led?

Norm



'---[TMR1_INT - interrupt handler]------------------------------------------
ASM
ToggleLED1
btg _LED1 ; toggle the pin
INT_RETURN
ENDASM

Darrel Taylor
- 18th March 2007, 18:20
That depends on the type of variable, and what you want to set it too.
<br>

Normnet
- 18th March 2007, 18:47
That depends on the type of variable, and what you want to set it too.

INTERRUPT_SET VAR BIT
set to 1

Norm

Darrel Taylor
- 18th March 2007, 18:59
'---[TMR1_INT - interrupt handler]------------------------------------------
ASM
ToggleLED1
MOVE?CT 1, _INTERRUPT_SET
INT_RETURN
ENDASM

Normnet
- 18th March 2007, 20:35
Works good. Thank you.

I would like to reload timer 1 on each interrupt from a variable.

Something like:


wTIMER1 var TMR1L ' access 16 bits of TMR1
wTimerPreload VAR WORD
wTimerPreload = 65211 'adjust in program


'---[TMR1_INT - interrupt handler]------------------------------------------
ASM
ToggleLED1
MOVE?CT 1, _INTERRUPT_SET ; SET FLAG
INT_RETURN

wTIMER1 = wTimerPreload ; in assembly

ENDASM


Norm

Darrel Taylor
- 18th March 2007, 20:46
See this page...
DT_INTS-14 (Timer Template)
http://darreltaylor.com/DT_INTS-14/TimerTemplate.html

It's in the 14-bit section, but it's pretty much the same for 18F's
<br>

Normnet
- 19th March 2007, 02:21
Interrupt now OK with one time adjustable Hz.

Is their a way to change a Hz variable before each interrupt on?
wFREQ_Hz var word

Something like:

;--- Change these to match the desired interrupt frequency -------------------
;--- See http://DarrelTaylor.com/DT_INTS-14/TimerTemplate.html for more Info.
;@Freq = 10 ; Frequency of Interrupts in Hz
@Freq = wFREQ_Hz ; in assembly

Darrel Taylor
- 19th March 2007, 18:54
I don't have anything ready-made for DT_INTs like that.

But this program has a routine to calculate the timer ticks required to produce a given frequency at a given dutycycle.

Slow speed Software PWM
http://www.pbpgroup.com/modules/wfsection/article.php?articleid=6

Just use the SetSPWM and CalcSPWM routines.
The interrupt portion isn't compatible with DT_INTS.

HTH,

emavil
- 22nd March 2007, 00:41
Hi darrel,

This is my follow up inquiry about your excellent code for multiple interrupts.

I've seen your code and it was amazing. After compiling, Microcode studio locked up. I'm using PIC16F628A, 4MHz xTAL and PICBasic Pro v2.33.

Your site states that MPASM is required. Does it have any relevance to the compilation?

Darrel Taylor
- 22nd March 2007, 00:59
Your site states that MPASM is required. Does it have any relevance to the compilation?

Besides the fact that it won't work without it. No.

Hmmm, PBP V2.33
There's been at least a hundred different things fixed with PBP since that version from Several years ago.
There's no telling what could be going wrong with such an ancient compiler.

Time to spend the 10 bucks for an upgrade.

emavil
- 22nd March 2007, 01:14
thanks a lot for that reply.

I have also this notion that its really the PBP Compiler that limits me from utilizing your code. thank you very much.

With regard to PBP 2.33. I managed to enable the feature of 16F628A coz if we look at the installation files, only 16F628 is present.

Now, my question is, what is really the minimum version of PBP just to compile your "multiple interrupt" codes?

You said 10 bucks, with all your respect, can you let me have that upgrade for that amount. I'm just a hobbyist and purchasing a new PBP compiler by far costly for me? What are the possible solutions can you suggest?

skimask
- 22nd March 2007, 01:16
You said 10 bucks, with all your respect, can you let me have that upgrade for that amount. I'm just a hobbyist and purchasing a new PBP compiler by far costly for me? What are the possible solutions can you suggest?

Hey PAL....Let me give you a little hint...

WE'RE ALL JUST HOBBYISTS!!!

What makes you so special? And it's 10 bucks. If you can't afford that, then you probably shouldn't be buying any more hardware until you can save up that amount.
Oh...but you're looking at buying the new PBP compiler...which means that you can't upgrade.
Why can't you upgrade? Is this because the version you have right now isn't exactly....oh nevermind...I give up...

Another one for the list...

Darrel Taylor
- 22nd March 2007, 01:39
Now, my question is, what is really the minimum version of PBP just to compile your "multiple interrupt" codes?

My first version of PBP was 2.40, and that had to be 6 or 7 years ago. I don't know of anything that would keep DT_INTS from working with that. But 2.33, geez how many years ago was that. There's just no way of knowing if anything would work with it.


You said 10 bucks, with all your respect, can you let me have that upgrade for that amount. I'm just a hobbyist and purchasing a new PBP compiler by far costly for me? What are the possible solutions can you suggest?

I'm not a PBP reseller, which are the only ones that can sell you an upgrade. And to do that, they would have to have sold PBP to you in the first place.

If you can't afford the price of the compiler, then you've chosen the wrong hobby. Because you'll be spending hundreds, if not thousands on the different parts, modules, processors, displays etc. The compiler itself is a relatively small cost, comparatively.

And you'll find that the people that did pay for the compiler, aren't willing to help someone that's pirated theirs. Sorry, but that includes ME.
<br>

emavil
- 22nd March 2007, 03:19
thanks for your advice Darrel, you're a man of character.

anyway, i would like to ask an apology to those guys who were not able to grasp what i meant.

I will consult MELabs about the technical details of this issue.

I was trying to ask for a reasonable price and location for PBP coz in my place (Philippines) there's no reseller or distributor for MELABs products. I have to order it abroad. That's what i meant for "COSTLY". I have to pay for extra charges. Unlike if it is available in my country, its easy for me order the right version without spending extra charges.

Right now i will just go back to the old drawing board and maximize my resources. I will find resources just save extra for an upgrade of the latest version of PBP.

thanks anyway, this forum is the best. I love people who always criticize for good.

with regard to my post about the digital clock that utilizes 6 7-segment displays for time display, Darrel do you something in mind to maintain the 1/100 tick accuracy while refreshing the 7-segments? Right now i can use only one interrupt (TMR1) for timer tick count. I do not know how to refresh the displays(7-segments). This is no problem for the LCD, right?

tiger_bel
- 22nd March 2007, 03:21
read the thread many times,

pic 18F4525
interupt on port B.0 works great with DT add-on using int0_int
but on falling edge of incoming pulse
the full program runs without any problem


i want to change it on rising edge using rbc_int
but - pic blocks - nothing works anymore ???
even de ledflash sub .....
what am i doing wrong - i don't see it.


code



'****************************
' as test for RBC_int
INTCON.0 = 0 ' RBIF
INTCON.3 = 1 ' RBIE
' INTCON2.0 = 1 ' RBIP
'****************************
' ok for int0_int on port B but falling edge ( unusable in this case)

INTCON2.6 = 1 ' rising edge ????
INTCON.1 = 0
INTCON.4 = 1 ' enable int0 interrupt RB0
'****************************
' include special interupts
INCLUDE "DT_INTS-18.bas" ; Base Interrupt System
INCLUDE "ReEnterPBP-18.bas" ; Include if using PBP interrupts
INCLUDE "Elapsed_INT-18.bas" ; Elapsed Timer Routines

ASM
INT_LIST macro ; IntSource, Label, Type, ResetFlag?
; INT_Handler INT0_INT, _triggertest, PBP, yes
INT_Handler RBC_INT, _triggertest, PBP, yes
INT_Handler TMR1_INT, _ClockCount, PBP, yes
endm
INT_CREATE ; Creates the interrupt processor
ENDASM
gosub initial ; all var to 0
gosub ledflash ; flash leds 10 times
T0CON = %10010010 ; T0 = 16-bit, Prescaler 8
;@ INT_ENABLE INT0_INT ; enable external (INT) interrupts
@ INT_ENABLE RBC_INT ; enable RB (INT) interrupts on change
@ INT_ENABLE TMR1_INT ; Enable Timer 1 Interrupts

GOSUB ResetTime ; Reset Time to 0d-00:00:00.00
GOSUB StartTimer ; Start the Elapsed Timer


'*******************************************
Main:
if trig_in =1 then
................
endif

trig_in = 0
goto main
'******************************************
';---[INT - interrupt handler]--------------------------
triggertest:
trig_in = 1 ' set flag interupt
@ INT_RETURN
end

Darrel Taylor
- 22nd March 2007, 04:20
tiger_bel,

RBC_INT's generate an interrupt on BOTH edges of RB4 thru RB7. You can't set it to just Rising or Falling.

Then once it interrupts, you have to read PORTB to "End the Mismatch".
A simple Dummy = PORTB in the handler will do it.

You also need to compare that read, with the value of PORTB the last time it interrupted to figure out which pin changed, and which state it changed to.
<br>

tiger_bel
- 22nd March 2007, 04:42
many thanks for the info,

i just figured out that using a simple sub to scan the port works fine...
and i use port B.0 not 4...7

rgds
tb

sougata
- 27th March 2007, 07:45
Hi,


many thanks for the info,

i use port B.0 not 4...7


Then why on earth you are enabling it :confused:

@ INT_ENABLE RBC_INT ; enable RB (INT) interrupts on change

IE Ray
- 4th May 2007, 11:29
I have used the 18FXXX interupts, great stuff, does what is says on the tin. Taking things a stage further, are there and routines for the CAN interface for the 18F258/18F2580 chips?

Thanks Ray

Squibcakes
- 14th May 2007, 00:47
This is gonna sound like a dumb question.

Where can I download the files for DT_INTS-18? I've been to Darrels website but cant find the link...

http://darreltaylor.com/DT_INTS-18/home.html

Can anyone help me out?

Cheers
Squib

mister_e
- 14th May 2007, 02:14
Nah, it's not a dumb question. Knowing what happened last week, it's probably normal than few things are missing on his website.

I've attach ALL files.


** Files removed **
They're back on the website again.

Thanks Steve!
DT

Darrel Taylor
- 14th May 2007, 05:59
Nope, not a dumb question.

But I got a dumb answer.

The site was recently hacked by some Turkish Hacker Group. (Dirty Rats)

The "dumb" part is that I haven't made a backup in over a year.
So that's what the site looks like now. Same as a year+ ago.

I'm so digusted at myself, I've not even been able to start the repairs.
Every time I look at it, I just go .... "Uughhh! I don't want to do that right now."

Thanks Steve, that ought to help out, for awhile.

Regards,

T.Jackson
- 14th May 2007, 06:35
These bloody ******* I tell you. I'd like to see them locked up. Weekly, sometimes even daily, I receive a dozen or so emails from fraudulent individuals either telling me that I've won the lottery (the motivation behind this is identity theft) - or requesting that I go and login into my bank account on their copied fraudulent web site.

The internet needs to be policed by people that have the power to shut an operation down with as little as two keystrokes and a couple of clicks of the mouse.

Darrel Taylor
- 15th May 2007, 01:56
Yeah, I can see doing it for a profit. (credit card/phishing scams)
No matter how much I hate the method. At least there's a reason.

But what can someone possibly gain by defacing a website? Other than pissing the webmaster off.
After a little searching, I found that it was only one of many thousands hacked by the same group.

I even found a cached page on google that showed pbpgroup que'd for defacement. The cached page was dated prior to the actual hack.
How nice of them to warn you. Sort of :mad:


The internet needs to be policed by people that have the power to shut an operation down with as little as two keystrokes and a couple of clicks of the mouse.
Yesterday 20:59

That would be nice. But I don't know anyone that I would entrust those powers too.
All govenments immediately exluded.
<br>

Squibcakes
- 15th May 2007, 03:57
Guys,
That would give you the ****s! Ok - so at least I'm not going blind unable to find the link on his website.

I better do a backup of my website today.

Cheers
Squib

T.Jackson
- 15th May 2007, 05:29
That would be nice. But I don't know anyone that I would entrust those powers too. All govenments immediately exluded.
<br>

It would be a paid job like any other. Plenty of people around fit to do it.

elevenscorpions
- 20th May 2007, 03:38
Darrel:

I'm trying to use your "Blinky Light" interrupt code (16F690) and I get an error

"ERROR: Variable wsave3 position request 416 beyond RAM_END 367."

when I compile. Any suggestions about what I am doing wrong? Thanks.

BrianB

Archangel
- 20th May 2007, 05:06
Yeah, I can see doing it for a profit. (credit card/phishing scams)
No matter how much I hate the method. At least there's a reason.

But what can someone possibly gain by defacing a website? Other than pissing the webmaster off.

<br>
Hi Darrel,
I can think of a reason, maybe to run scripts to install a trojan to your visitors.
or cgi redirects for that reason or other bad behavior. Oh and to piss you off too . . .
JS

Darrel Taylor
- 20th May 2007, 05:32
... I get an error ... "ERROR: Variable wsave3 position request 416 beyond RAM_END 367."

Hi Brian,

Open the DT_INTS-14.bas file. You should see this near the top ...
wsave var byte $20 SYSTEM ' location for W if in bank0
;wsave var byte $70 SYSTEM ' alternate save location for W
' if using $70, comment out wsave1-3

' --- IF any of these three lines cause an error ?? ----------------------------
' Comment them out to fix the problem ----
' -- It depends on which Chip you are using, as to which variables are needed --
wsave1 var byte $A0 SYSTEM ' location for W if in bank1
wsave2 var byte $120 SYSTEM ' location for W if in bank2
wsave3 var byte $1A0 SYSTEM ' location for W if in bank3
' ------------------------------------------------------------------------------

Darrel Taylor
- 20th May 2007, 07:02
I can think of a reason, maybe to run scripts to install a trojan to your visitors. or cgi redirects for that reason or other bad behavior. JS

And create another SPAM spewing Zombie.
I suppose that's a reason.
(rassa fracken ricken racken ... Hackers)


Oh and to piss you off too . . .
Mission Accomplished!
<br>

nacho7577
- 7th June 2007, 16:58
Hi, all. In my program i put all you are saying about fast interrupts, and with INT_INT, works fine, and so better than it use with on interrupt goto..... I´ve probed also with TIMR0 at same time and works again. But if i put RX_INT, others work but RX_INT subrutine nothing happens.

I delete all about INT_INT and TIMR0, and works. In RX_INT sub only have a sentence like HSERIN char, and in main program LCDOUT char to see the incoming char.

Any ideas? I copied the code of first page to make it, and it should be work.

Another question: If i want to save that char in a string to display it in the lcd, when carriage return income, how can i do it??? My head it´s warm....... sorry.

Also i´ve read the post about string of Darrel but i´m newby and i don´t undestand so much.

Thanks for all.

PD.- micro it´s 16F877A or 16F876, or 16F84

skimask
- 7th June 2007, 17:12
But if i put RX_INT, others work but RX_INT subrutine nothing happens.
Are you sure that you're receiving anything in the first place?
How about clearing RCIF?


In RX_INT sub only have a sentence like HSERIN char, and in main program LCDOUT char to see the incoming char.
Are you using HSERIN or the RX_INT?


Another question: If i want to save that char in a string to display it in the lcd, when carriage return income, how can i do it??? My head it´s warm....... sorry
Another thread subject...make an array, make a counter, keep adding 1 to the counter, store the character in the array with the index 'counter', if the incoming character is a CR, display it, otherwise, wait for more...again, should be a seperate thread.

nacho7577
- 8th June 2007, 10:35
' PROGRAMA QUE USA INTERRUPCIONES INSTANTÁNEAS '
' INT_INT -- INT External Interrupt
' RBC_INT -- RB Port Change Interrupt
' TMR0_INT -- TMR0 Overflow Interrupt 16F
' TMR1_INT -- TMR1 Overflow Interrupt
' TMR2_INT -- TMR2 to PR2 Match Interrupt
' TX_INT -- USART Transmit Interrupt
' RX_INT -- USART Receive Interrupt
' CMP_INT -- Comparator Interrupt
' EE_INT -- EEPROM/FLASH Write Operation Interrupt
' BUS_INT -- Bus Collision Interrupt
' PSP_INT -- Parallel Slave Port Read/Write Interrupt
' AD_INT -- A/D Converter Interrupt
' SSP_INT -- Master Synchronous Serial Port Interrupt
' CCP1_INT -- CCP1 Interrupt
' CCP2_INT -- CCP2 Interrupt

clear

define OSC 16

' Define LCD connections
DEFINE LCD_DREG PORTD ' LCD Data Port
DEFINE LCD_DBIT 4 ' Starting Data Bit
DEFINE LCD_RSREG PORTD ' Register Select Port
DEFINE LCD_RSBIT 2 ' Register Select Bit
DEFINE LCD_EREG PORTD ' Enable Port
DEFINE LCD_EBIT 3 ' Enable Bit
DEFINE LCD_BITS 4 ' Data Bus Size
DEFINE LCD_LINES 2 ' Number of Lines on LCD

' Define RS232 line
DEFINE HSER_BAUD 19200 'Hser baud rate
DEFINE HSER_CLROERR 1 'Hser clear overflow automatically
DEFINE HSER_SPBRG 51 'Hser spbrg init
DEFINE HSER_RCSTA 90h 'Hser receive status init
DEFINE HSER_TXSTA 24h 'Hser transmit status init

ADCON1 = 7 'Set portA outputs to Digital / No ADC
LCDOUT $FE,1 ' Initialize LCD
PAUSE 200

fase_a var portb.0
subir var portb.1
bajar var portb.2
prog var portb.3

salida var porta.0
'sentido var porta.1
'prueba var porta.2

aux_subir var ppp.0
aux_bajar var ppp.1
aux var ppp.2
escribir_inicio var ppp.3
escribir_pulso var ppp.4

ppp var byte
cuenta var word
pulso var word
inicio var word
que_escribir var word
aux_aux var byte
tmp var byte
direccion var byte
char var byte
cadena var byte[20]
i var byte

INCLUDE "DT_INTS-14.bas" ' Required
INCLUDE "ReEnterPBP.bas" ' Include if using PBP interrupts
INCLUDE "Elapsed_INT.bas" ' Elapsed Timer Routines

TRISA = 0
PORTA = 0
TRISB = $FF
TRISC = %10000000
TRISD = 0
PORTD = 0
PORTC = 0

ASM
INT_LIST macro ; IntSource, Label, Type, ResetFlag?
INT_Handler INT_INT, _Int_RB0, PBP, yes
INT_Handler RX_INT, _Int_RX, PBP, yes
endm
INT_CREATE ; Creates the interrupt processor

INT_ENABLE INT_INT ; enable external (INT) interrupts
INT_ENABLE RX_INT ;

ENDASM

OPTION_REG = OPTION_REG & $80 | 1 ; Set TMR0 Prescaler to 256, leave RBPU alone

Main:
i = 0
cuenta = 0
aux_aux = 0
inicio = 300
pulso = 300
'Reinicializar variables
if subir and bajar then
escribir_inicio = 1
gosub escribir
escribir_inicio = 0
escribir_pulso = 1
gosub escribir
escribir_pulso = 0
endif

'Si no hay nada en eeprom graba variables
read $0,tmp
if tmp = $FF then
escribir_inicio = 1
gosub escribir
escribir_inicio = 0
escribir_pulso = 1
gosub escribir
escribir_pulso = 0
endif

'Se releen las variables
gosub leer

prog_: 'lazo principal

if subir and prog and not aux_subir then
gosub mod_inicio_subir
endif

if bajar and prog and not aux_bajar then
gosub mod_inicio_bajar
endif

if subir and not prog and not aux_subir then
gosub mod_pulso_subir
endif

if bajar and not prog and not aux_bajar then
gosub mod_pulso_bajar
endif

if not subir then
aux_subir = 0
endif

if not bajar then
aux_bajar = 0
endif
'salida por LCD
lcdout $fe,2
lcdout "Posicion ",dec4(cuenta)
lcdout $fe,$C0
lcdout "Inicio ",dec4(inicio)
lcdout $fe,$94
lcdout "Pulso ",dec4(pulso)
lcdout $fe,$d4
cadena[I] = char
LCDOUT STR cadena,20 'no aparece nada (nothing appears in lcd
' lcdout "Salida ",bin salida
goto prog_

'Subrutinas
leer:
INTCON = $00
read $0,inicio.byte1
Read $1,inicio.byte0
read $2,pulso.byte1
Read $3,pulso.byte0
INTCON = $90
RETURN

escribir:
if escribir_inicio = 1 then
que_escribir = inicio
direccion = $0
endif

if escribir_pulso = 1 then
que_escribir = pulso
direccion = $2
endif

' porta.2 = 1 'chequeo para saber que ha escrito en eeprom
Write direccion,(que_escribir.byte1)
write direccion+1,(que_escribir.byte0)
porta.2 = 0
return

mod_inicio_subir:
inicio = inicio + 15
aux_subir = 1
if inicio >= 3000 then
inicio = 3000
endif
escribir_inicio = 1
gosub escribir
escribir_inicio = 0
return

mod_inicio_bajar:
inicio = inicio - 15
aux_bajar = 1
if inicio <= 50 then
inicio = 50
endif
escribir_inicio = 1
gosub escribir
escribir_inicio = 0
return

mod_pulso_subir:
pulso = pulso + 15
aux_subir = 1
if pulso >= 3000 then
pulso = 3000
endif
escribir_pulso = 1
gosub escribir
escribir_pulso = 0
return

mod_pulso_bajar:
pulso = pulso - 15
aux_bajar = 1
if pulso <= 50 then
pulso = 50
endif
escribir_pulso = 1
gosub escribir
escribir_pulso = 0
return

'---[INT - interrupt handler]---------------------------------------------------
Int_RB0:
cuenta = cuenta + 1

if cuenta >= inicio then
salida = 1
endif

if cuenta >= (pulso + inicio) then
salida = 0
cuenta = 0
endif
@ INT_RETURN

'---[TMR0 - interrupt handler]-------------------------------(Blinky Light)-----
'T0Count Var WORD
'ToggleLED2: 'aprox 1 segundo
' T0Count = T0Count + 1
' if T0Count = 512 then T0Count = 0 : Toggle LED2
'@ INT_RETURN

'---[RX - inmterrupt handler]--------------------------------------------------
Int_RX:
PORTA.1 = 1 'to check RX int has come
i = i +1
hserin [char]
@ INT_RETURN

------------------------
questions:

Why LCD doesn´t display cadena?
Why when i entry many chars by rs232 (fast) variables inicio and pulso corrupts and display an abnormal value?? This check was made without int_int interrupts (fase_a it´s an output from a incremental encoder, and this one was stopped).

Thanx, and sorry if i´m 'heavy'.

Darrel Taylor
- 8th June 2007, 11:15
I don't understand your language, so it's hard to tell what's going on.
But here's a couple problems I can see...

LCDOUT STR cadena,20 'no aparece nada (nothing appears in lcd

should be...

LCDOUT STR cadena\20

And the reason you're missing characters, is probably because the data is received by the interrupt handler, but it's being put into the "buffer" array in the main loop. That should be done in the handler too.
<br>

nacho7577
- 8th June 2007, 12:30
Thanx for your answer.

I understand you about the understanding the code.... me too sometimes....

OK lcdout cadena\20

>And the reason you're missing characters, is probably because the data is >received by the interrupt handler, but it's being put into the "buffer" array in >the main loop. That should be done in the handler too.
¿? Something like this?:

'---[RX - inmterrupt handler]----------------------------------------------
Int_RX:
PORTA.1 = 1 'to check RX int has come
hserin [char]
cadena[i] )= char
i = i +1
@ INT_RETURN

but lcd displays rare....

Don´t worry i´ll figth with it.

Thanx for all.

Darrel Taylor
- 8th June 2007, 21:51
Better, but it still needs a way to limit it to the "bounds" of the array. Or, it will overwrite all your other variables. Maybe like this.
'---[RX - inmterrupt handler]----------------------------------------------
Int_RX:
PORTA.1 = 1 'to check RX int has come
hserin [cadena(i)]
i = i +1
if i >= 20 then i = 0
@ INT_RETURN

Of course this still has the problems of not knowing how many bytes were received, if the buffer overflows, if USART errored etc.

You might want to take a look at this program from Joe S.

LCD serial backpacks
http://www.picbasic.co.uk/forum/showthread.php?p=28336

It has a complete "Circular Buffer" using DT_INTS.
<br>

kutsi
- 14th June 2007, 19:34
hi all,
Using 18f4550....
I tried it on INT_INT -- INT External Interrupt and RBC_INT -- RB Port Change Interrupt. It works wonderfully.

At this point, I want to use TX_INT -- USART Transmit Interrupt.But I could
not manage it out.My code is

ADCON1 = %00001111
TRISC = %10000000
DEFINE HSER_RCSTA 90h
DEFINE HSER_TXSTA 20h
DEFINE HSER_BAUD 9600
DEFINE HSER_CLROERR 1
RCIF VAR PIR1.5
TXIF VAR PIR1.4
DATA var Byte
Pause 5
Main:
If RCIF then hserin[data]
goto Main


which definitions do I need ?Many thanks

Regards

mister_e
- 14th June 2007, 20:00
TX or RX? Not sure why you want to monitor TX event so far, RX would be more valuable.

kutsi
- 14th June 2007, 20:23
define LOADER_USED 1
define OSC 20
DEFINE RESET_ORG 800H

data var byte


ADCON1 = %00001111
TRISC = %10000000
DEFINE HSER_RCSTA 90h
DEFINE HSER_BAUD 9600
DEFINE HSER_CLROERR 1

INCLUDE "DT_INTS-18.bas" ' Base Interrupt System
INCLUDE "ReEnterPBP-18.bas" ' Include if using PBP interrupts

ASM
INT_LIST macro ; IntSource, Label, Type, ResetFlag?
INT_Handler RX_INT, _recieve, PBP, yes
endm
INT_CREATE ; Creates the interrupt processor
ENDASM

@ INT_ENABLE RX_INT ; enable Timer 1 interrupts


RCIF VAR PIR1.5

Main:

PAUSE 10
GOTO Main

DISABLE DEBUG
'---[RC- interrupt handler]--------------------------------------------------
recieve:
hserin [data]

@ INT_RETURN
ENABLE DEBUG




ok, I removed the definitions related to TX. can I get rid of other definitions?

nomada
- 3rd July 2007, 01:06
Hi all of you,

For the first time I've used the famous Darrel Taylor's interrupt routine, no words to describe it, marvellous job.

Thanks Darrel for the explendid job

nomada

precision
- 25th July 2007, 09:48
Sir Darrel Taylor.
my counter code is working well.
I want to counts the rising edge on INT0 and falling edge on INT1 of the pulse trains from encoder.
How i configure interrupt on the INT1 as Falling edge and INT0 as rising edge.
I short both pin but dont'know how to config. edge bit.

code.


' chip PIC18F4550
DEFINE OSC 48
INCLUDE "MODEDEFS.BAS"
include "MYLCD.BAS"
CMCON = 7
ADCON1 = 15
CVRCON = %00000000 'CVref turned off

TRISB = %11111111
w0 var word
pause 500

'-------------------------[ INT0 Interrpt setting ] -----------------------------
INCLUDE "DT_INTS-18.bas" ; Base Interrupt System
INCLUDE "ReEnterPBP-18.bas" ; Include if using PBP interrupts
ASM
INT_LIST macro ; IntSource, Label, Type, ResetFlag?
INT_Handler INT0_INT, _ToggleLED1, PBP, yes
INT_Handler INT1_INT, _ToggleLED2, PBP, yes
endm
INT_CREATE ; Creates the interrupt processor
ENDASM

@ INT_ENABLE INT0_INT
@ INT_ENABLE INT1_INT
'_________________________________________________ _________________________________


start: lcdout $fe,1
lcdout "count = ",dec5 w0
pause 200
goto start



ToggleLED1:
w0 = w0+1
@ INT_RETURN

ToggleLED2:
w0 = w0+1
@ INT_RETURN

Darrel Taylor
- 25th July 2007, 09:59
The Edge Select bits are located in the INTCON2 register of the 4550.

They are Rising edge by default, so for INT1 Falling edge...
INCON2.5 = 0 ; External INT1 on Falling edge
<br>

precision
- 25th July 2007, 12:57
I set INTCON bit but not working on falling edge.




' chip PIC18F4550
DEFINE OSC 48
INCLUDE "MODEDEFS.BAS"
include "MYLCD.BAS"
CMCON = 7
ADCON1 = 15
CVRCON = %00000000 'CVref turned off

TRISB = %11111111
w0 var word
pause 500

'-------------------------[ INT0 Interrpt setting ] -----------------------------
INCLUDE "DT_INTS-18.bas" ; Base Interrupt System
INCLUDE "ReEnterPBP-18.bas" ; Include if using PBP interrupts
ASM
INT_LIST macro ; IntSource, Label, Type, ResetFlag?
INT_Handler INT0_INT, _ToggleLED1, PBP, yes
INT_Handler INT1_INT, _ToggleLED2, PBP, yes
endm
INT_CREATE ; Creates the interrupt processor
INCON2.5 = 0 ; External INT1 on Falling edge
ENDASM

@ INT_ENABLE INT0_INT
@ INT_ENABLE INT1_INT
'_________________________________________________ _________________________________


start: lcdout $fe,1
lcdout "count = ",dec5 w0
pause 200
goto start



ToggleLED1:
w0 = w0+1
@ INT_RETURN

ToggleLED2:
w0 = w0+1
@ INT_RETURN

Darrel Taylor
- 25th July 2007, 13:08
It's a regular PBP statement, but it's in an ASM block.

Move it outside the block and it should work better.
<br>

precision
- 25th July 2007, 13:16
Syntex error

Ohh. Sory sir, I cut yout code and paste, I don't see there are INCON

Thanks sir, It's Working

Darrel Taylor
- 26th July 2007, 14:24
Oops! :o
<br>

srspinho
- 31st July 2007, 15:05
Hi Darrel,

some days ago, I was trying to measure the "ON time" of my car´s gasoline injectors (one of the 4)

I´m using a 16F877 @ 10 Mhz, and I´m using the Timer0 as a 250 ms counter and Timer1 as a pulse counter, I ran out of possibilities of new measurements.

Bruce told me that I should use a new device with more timers available, like the 18F4431 (or similar).
The problem is : This device (or similar) is not available here in Brazil, and Microchip do not send samples to Brazil.

I was reading this post about the interrupts and decided to ask :

Is that possible to read the pulses on Timer1 on a fixed time interval (so, I would have the car´s speed and the mileage) and measure the injector on-time (so I would have the consumption) with the instat interrupts running on a 16f877 ?

Thanks !

Sergio

Darrel Taylor
- 31st July 2007, 15:38
Sure you can.

I'd use the Capture mode of the CCP modules using Timer1, for the ON time.

Timer 2 can be the timebase used to count the speedometer pulses on the INT (external interrupt) pin.

And the same signal from the Injector can be fed to T0CKI, so Timer 0 can count the RPM's too.

Speed, Distance, Consumption and Tachometer.
<br>

srspinho
- 31st July 2007, 16:01
Wow !

thank you !

I´ll try it this weekend and post the results here !

Bye !

Bayliner
- 31st July 2007, 21:24
Hi,

how i use the instant interrupt (very nice pice of code) and the write or eeprom comand. In the manual they say to turn off all interrupts. Or is there no problem to use them together?

Many Thx for reply

Darrel Taylor
- 1st August 2007, 00:19
If an interrupt happens at just the right time, or actually just the Wrong time, it can cause the EEPROM write operation to fail.

But it's not always necessary to turn off the interrupts.

What I do, is write the value to EEPROM, then read it back and compare it to what it was writing. If they're not the same, go back and try to write it again.

After a certain number of tries (I use 10, but it never takes that much), if it still hasn't written it properly, then turn off the interrupts and write it one last time.

It takes a little extra code, and some extra time, but it doesn't mess with the interrupts.

HTH,

Acetronics2
- 13th August 2007, 16:25
Hi, Darrel

I'm playing with PbP Interrupts ( a Lawn tractor computer: Total run Time, Split time, RPM, max RPM, Air and Oil Temp and Oil press ... AND a maintenance reminder)

... AND ...

I did not see an INT_DISABLE GLOBAL and INT_ENABLE GLOBAL Macros ... just for the compatibility with the others "interrupt control" macros ...

Of course just to set "THE" INTCON.7 bit ... ( case is i.e.... using the asm "sleep" instruction !!! )

No, no thats not to be called lazyness ...

Nice playing ground ... Thank you once more !!!

Alain

Darrel Taylor
- 13th August 2007, 16:43
Hi Alain,

You are absolutely correct.
To keep everything consistant, there should be a GLOBAL for the INT_ENABLE/DISABLE.

I will include that in the next version, which should be available very soon.

Thanks for the idea's.
Wish I received more of them. :)
<br>

Acetronics2
- 13th August 2007, 16:55
Thank you Darrel,

That's nice from you.

By the way ... I also modified "a bit" your Elapsed Timer to get only HHHH:MM:SS, using The Timer 1 Clock with a 32.768 Khz Xtal.

That gives more computing time for other tasks ... especially other interrupts.

Alain

DJEE
- 20th August 2007, 23:01
Darrel,

I downloaded your Instant Interrupts files and I am having trouble compiling them. I am using MPASM assembler with PBP. I take your 3 files and try to compiler them straight from what I downloaded.

On the DT_INTS-14.bas I get the following:

Error [113] c:\pbp\pbppic14.lib 1141: Symbol not previously defined (INT_ENTRY)

On the ReEnterPBP.bas I get the following:

Warning [207] c:\pbp\reenterpbp.asm 217: Found label after column 1 (INT_RETURN)

Warning [207] c:\pbp\reenterpbp.asm 313: Found label after column 1 (INT_RETURN)

Error [116] c:\pbp\reenterpbp.asm 313 : Address label duplicated or different in second pass (INT_RETURN)

The Elapsed_INT.bas compiles without any errors but gives me the following warning:

Warning [207] c:\pbp\elapsed_INT.asm 237: Found Label after column 1 INT_RETURN


Do you have any ideas what might be wrong?

Darrel Taylor
- 21st August 2007, 00:15
What do you have in the main program?

Error [113] c:\pbp\pbppic14.lib 1141: Symbol not previously defined (INT_ENTRY)
Usually means there isn't an INT_LIST macro.

The files won't compile without it.

DJEE
- 21st August 2007, 15:16
As of yet I have not put your code into my main program. I was just trying to compile each on their own. If I understand you correctly, your code needs to be put of another program or it will not compile. Is that correct?

Darrel Taylor
- 21st August 2007, 22:19
That's correct!

Darrel Taylor
- 31st August 2007, 01:00
Alain,

Well, you may have noticed I didn't get the "GLOBAL" for INT_ENABLE/DISABLE put in the last version of DT_INTS-18.
It turns out that GLOBAL is a reserved word for MPASM. It's used with relocatable code.

I could have used GLBL or GLBAL I suppose, but somehow

@ INT_DISABLE GLBL

Seems even more cryptic than

GIE = 0

I still think it should be in there, as should PERIPHERAL, HIPRIORITY and LOWPRIORITY.

But I'm not sure what the best way is, AKA less confusing.

Any thoughts?
<br>

Acetronics2
- 31st August 2007, 11:17
Alain,

Well, you may have noticed I didn't get the "GLOBAL" for INT_ENABLE/DISABLE put in the last version of DT_INTS-18.
It turns out that GLOBAL is a reserved word for MPASM. It's used with relocatable code.

I could have used GLBL or GLBAL I suppose, but somehow

@ INT_DISABLE GLBL

Seems even more cryptic than

GIE = 0

I still think it should be in there, as should PERIPHERAL, HIPRIORITY and LOWPRIORITY.

But I'm not sure what the best way is, AKA less confusing.

Any thoughts?
<br>


Hi, Darrel

What about

@ G_INT_DISABLE and @ G_INT_ENABLE ??? ... would be simple enough. ... and it's just "ordinary" macros !!!

Remember the goal was only to use something simple to remind ( in other words: to use for datasheet non-lovers !!! )

To me, GIE = 0 is also the simpler ... But, as you've seen, nowadays nobody dares to read the datasheets !!!




The Tractor computer soft is just finished (!)... I had some precedence headaches ( particularly with // !!! ), and it was really difficult to see what was wrong ...

despite result was good for setting a flag, operation was wrong !!! ... and was no way to cancel that flag ...

Now, I must translate my comments to English ...

Regards
Alain

srspinho
- 4th September 2007, 04:03
Hello Darrel !

I´m using your Instat interrupts to work with TIMER1, TIMER2 and CCP1 with a 16F877 @ 4Mhz, like this :

ASM
;T0IF = TMR0IF
;T0IE = TMR0IE
INT_LIST macro ; IntSource, Label, Type, ResetFlag?
INT_Handler CCP1_INT, _Capture, PBP, yes
INT_Handler TMR1_INT, _Timer1, PBP, yes
INT_Handler TMR2_INT, _tick, PBP, yes
endm
INT_CREATE ; Cria a interrupção
ENDASM

Everything is working very, very well.

I´m doing a On-board computer for my small Opel Corsa, and this interrupts are just great !
Me and Sirvo (remember him ?) are doing almost the same on-board computer.

But now, I would like to implement 4 Buttons to my application (Start, Stop, Pause, Funcition Keys).

I´m trying to do that with the button statement without success / good results.

I read your sample (hello word for instant interrupts) but the INT_INT read just the RB0/INT right ?

Is that possible to use the Instant Interrupts to create/read, let´s say, 4 different buttons on PORTC ?

Tahank You very much !

bye


Sérgio Pinheiro