PDA

View Full Version : Instant Interrupts - Revisited



Pages : 1 [2] 3 4

Darrel Taylor
- 4th September 2007, 06:59
Is that possible to use the Instant Interrupts to create/read, let´s say, 4 different buttons on PORTC ?

Yes, that's possible. But it would be a lot easier if you used RBC_INT "Port B change interrupts". It uses PORTB.4 thru PORTB.7

But if those pins aren't available, you could do something like this, which uses only 1 interrupt (INT_INT on Falling Edge), then the interrupt handler can read PORTC to figure out which one was pressed.

http://www.pbpgroup.com/files/4Button_1INT.gif
<br>

srspinho
- 4th September 2007, 13:45
Hi Darrel

Thank you very Much !

I think this could help me a Lot !

I´m already using some portb pins and this solution will help a lot !

Thank you again !

Sérgio

duncan303
- 29th November 2007, 16:22
Hi Darrel,

I have been using your wonderful instant interrupts routine, i have experienced a hiccup and cannot work out what I am doing wrong.

I wonder anybody may be able to help direct me to a solution.

I am using a 18F4520 with 2.5 and masm401. I have checked that I have your latest version which I beleive to be 3.2 (dated 28/8/07).

when I compile the following code:

define OSC 16
INCLUDE "DT_INTS-18.bas"
INCLUDE "ReEnterPBP-18.bas" ; Include if using PBP interrupts
ASM
INT_LIST macro ; IntSource, Label, Type, ResetFlag?
INT_Handler CMP1_INT, _HopOut, PBP, yes
endm
INT_CREATE ; Creates the interrupt processor
ENDASM

TRISA = %00111111'
TRISD = %00000000
Z var bit
x var byte
CMCON = %00000010
@ INT_ENABLE CMP1_INT
Start:
PORTD.4 = 0
z = 0
Waiting:
if z = 0 then waiting

for x = 1 to 20
pause 50
toggle PORTD.4
next x
goto start

HopOut:
z = 1
@ INT_RETURN

end


I recieve the following complie errors



Error[128]........: Missing argument(s)
Error[113]........: Symbol not previously defined(IntFlagReg)
Error[113]........: Symbol not previously defined(IntFlagBit)
Error[113]........: Symbol not previously defined(IntFlagReg)
Error[113]........: Symbol not previously defined(IntFlagBit)
Error[101]........: ERROR:(Interrupt Source(IntFlagReg,IntFlagBit)not found)
Error[128]........: Missing argument(s)
Error[101]........: ERROR:(INT_ENABLE -Interupt Source not Found!)


If I change the CMP1 to CMP2 I receive errors

If I change the CMP1 to CMP then it compiles okay.

Any thoughts... should I be looking to set the registers manually maybe? I was planning to use both comparators independantly.

Thanks

Acetronics2
- 29th November 2007, 17:16
Hi,

No surprise if you read the interrupt sources list

#define INT_INT INTCON,INT0IF ;-- INT External Interrupt, 16F compatible
#define INT0_INT INTCON,INT0IF ;-- INT0 External Interrupt
#define INT1_INT INTCON3,INT1IF ;-- INT1 External Interrupt
#define INT2_INT INTCON3,INT2IF ;-- INT2 External Interrupt
#define INT3_INT INTCON3,INT3IF ;-- INT3 External Interrupt
#define RBC_INT INTCON,RBIF ;-- RB Port Change Interrupt
#define TMR0_INT INTCON,TMR0IF ;-- TMR0 Overflow Interrupt 18F
#define TMR1_INT PIR1,TMR1IF ;-- TMR1 Overflow Interrupt
#define TMR2_INT PIR1,TMR2IF ;-- TMR2 to PR2 Match Interrupt
#define TMR3_INT PIR2,TMR3IF ;-- TMR3 Overflow Interrupt
#define TMR4_INT PIR3,TMR4IF ;-- TMR4 Overflow Interrupt
#define TX_INT PIR1,TXIF ;-- USART Transmit Interrupt
#define TX1_INT PIR1,TX1IF ;-- USART1 Transmit Interrupt
#define TX2_INT PIR3,TX2IF ;-- USART2 Transmit Interrupt
#define RX_INT PIR1,RCIF ;-- USART Receive Interrupt
#define RX1_INT PIR1,RC1IF ;-- USART1 Receive Interrupt
#define RX2_INT PIR3,RC2IF ;-- USART2 Receive Interrupt
#define CMP_INT PIR2,CMIF ;-- Comparator Interrupt
#define EE_INT PIR2,EEIF ;-- EEPROM/FLASH Write Operation Interrupt
#define BUS_INT PIR2,BCLIF ;-- Bus Collision Interrupt
#define LVD_INT PIR2,LVDIF ;-- Low Voltage Detect Interrupt
#define HLVD_INT PIR2,HLVDIF ;-- High/Low Voltage Detect Interrupt
#define PSP_INT PIR1, PSPIF ;-- Parallel Slave Port Read/Write Interrupt
#define AD_INT PIR1, ADIF ;-- A/D Converter Interrupt
#define SSP_INT PIR1, SSPIF ;-- Master Synchronous Serial Port Interrupt
#define CCP1_INT PIR1, CCP1IF ;-- CCP1 Interrupt
#define CCP2_INT PIR2, CCP2IF ;-- CCP2 Interrupt
#define CCP3_INT PIR3, CCP3IF ;-- CCP3 Interrupt
#define CCP4_INT PIR3, CCP4IF ;-- CCP4 Interrupt
#define CCP5_INT PIR3, CCP5IF ;-- CCP5 Interrupt
#define USB_INT PIR2, USBIF ;-- USB Interrupt
#define OSC_INT PIR2, OSCFIF ;-- Oscillator Fail Interrupt



... only this :

#define CMP_INT PIR2,CMIF ;-- Comparator Interrupt

I think you have Yourself to look from which comparator the interrupt comes ...

Alain

duncan303
- 29th November 2007, 18:05
Hi Alain

Thankyou Alain for taking the trouble to read my post and make a suggestion, may I draw your attention to the defines further down Darrel's wonderful coding.

;_____ Comparators __________________________________________________ ________
#define CMP0_INT PIR1, CMP0IF ;-- Comparator 0 - 1230/1330 only

CMPIFREG = PIR2 ;-- Comparator 1
CMPIEREG = PIE2
CMPIPREG = IPR2
ifdef C1IF ; 18F24K20 18F25K20 18F26K20
CM1IFBIT = C1IF ; 18F44K20 18F45K20 18F46K20
endif
ifdef CM1IF
CM1IFBIT = CM1IF ; several J PICs
endif
ifdef CMP1IF
CMPIFREG = PIR1 ; 1230/1330 only
CM1IFBIT = CMP1IF
CMPIEREG = PIE1
CMPIPREG = IPR1
endif

ifdef CM1IFBIT
#define CMP1_INT CMPIFREG, CM1IFBIT
endif

ifdef C2IF ;-- Comparator 2
CM2IFBIT = C2IF ; 18F24K20 18F25K20 18F26K20
endif ; 18F44K20 18F45K20 18F46K20
ifdef CM2IF
CM2IFBIT = CM2IF ; several J PICs
endif
ifdef CMP2IF
CM2IFBIT = CMP2IF ; 1230/1330 only
endif

ifdef CM2IFBIT
#define CMP2_INT CMPIFREG, CM2IFBIT
endif
'-----------------------------------------------------------------------------

I think we are all waiting for the "K" series, perhaps this will compile to the K. I shall try it.

I did wonder wether I should set the ADCON for this device particularily the LATA register. But I am also aware that <6> of the PIR2 PIE2 and IPR2 only refers to one CMI, I presume I shall have to be careful to make sure that any interrupt on either comparator does not interfere with the other. ie if one comparator is set then the other is disabled.

Thanks again for your help.

Duncan

Darrel Taylor
- 29th November 2007, 18:39
The difference is that on the 4520, there is only 1 interrupt source for the Comparator module. A change in either comparator will cause an interrupt to the same handler.

There are other chips that have individual interrupt flags for each comparator, but not the 4520.

So you need to use the CMP_INT, on that chip.
<br>

duncan303
- 29th November 2007, 19:20
Hi Darrel,

Thanks for reply, I had slowly worked my way towrds that.

for th 18F45K20 Migration
The comparator is no longer controlled by the
CMCON register and each comparator now has it’s
own control register, CM1CON and CM2CON. The
functionality of the bits has also changed.

there is a section that confirms the observations made about the registers, so it really does always boil down to RTFD, but reading is sometimes not enough if you suffer from word blindness, anyway it gave me the opportunity to say thankyou for your routines which I intend to use.

Duncan.

Furthermore if everybody read and fully "understood" the datasheets this forum would die.

Darrel Taylor
- 29th November 2007, 22:33
... thankyou for your routines which I intend to use ...

Grrreat! Hope the rest works out OK.
If not, let me know.


Furthermore if everybody read and fully "understood" the datasheets this forum would die.

Or, then we could actually talk about the real purpose of this forum.
Programming with PicBasic Pro. :D
<br>

Wirecut
- 1st December 2007, 20:30
Hi Darrel,

this is my first post on this comunity. First of all I would thanks for the fantastic DT_INTS-14.bas background PWM routine.

I have uset your SW on a 16F628 in order to drive some LED with different brightness an WORK PEFECTLY. Darrel YOU ARE GREAT!!!!!

Now I need to use a potentiometer so set at run time the brightnes value for the LEDs, and after reading tons of html page and googled for hours, I have the founded suspect that the PBP instruction POT and RCTIME do not work with DT_INTS-14.bas.

Can you please confirm?

Ciao

Leo

tenaja
- 1st December 2007, 21:30
Leo,
Any time you have a routine or command that counts time, an interrupt will cause the timing to be off. Since the POT command times the discharge time of a cap, an interrupt in the middle of it will cause the command to give you a faulty reading when it is resumed.

There are several options;
--turn off the interrupts just before your POT command (and any other timing-specific command), and restore them just after.
--write yourself a home-made "pot" command, and use it inside the interrupts (but this only works if your interrupts are high frequency.)
--use a "real" a/d converter, either one in the PIC or off the chip.

Wirecut
- 2nd December 2007, 07:56
Many thanks tenaja for your prompt reply.
Ciao
Leo

Darrel Taylor
- 2nd December 2007, 09:17
Many thanks tenaja for your prompt reply.

My sentiments, exactly. :)
<br>

tenaja
- 2nd December 2007, 22:20
Darrel, does your interrupt routine selectively choose which system variables to save, based on which ones are used, to save time? Or, does it save them all, regardless?

Darrel Taylor
- 2nd December 2007, 22:40
Saves them all, no matter what.

Without an external program like VBIS for Proton, there's no way to know which system variables are being used by a particular Handler.

But from what I've seen, while optimizing out what isn't used does increase the maximum interrupt frequency available, it only really helps if you're pushing the limits. For normal everyday interrupts (with Basic Language) the extra saves don't have that much effect, and helps provide stability.

And as always, if you really need the speed ?
The interrupts should be in ASM anyways. (no PBP system variables saved at all)

Which is one of the best parts of DT_INTs.
You can have both ASM and Basic Language interrupts in the same program.
<br>

mister_e
- 2nd December 2007, 22:43
And all this with a minimum of efforts ;)

Pic_User
- 24th January 2008, 01:04
For the record (partial pasted from other thread):

Hi all, I've been trying to get Darrel Taylor's Instant interrupts to work with a 12f675 with no luck. Will they work with a 12f675?

I just get the following error message when I try to compile it:

ERROR: Variable wsave3 position request 416 beyond RAM_END 95.
ERROR: Variable wsave2 position request 288 beyond RAM_END 95.
ERROR: Variable wsave1 position request 160 beyond RAM_END 95.
ERROR: Unable to fit variable RS2_Save
<..snip...>
Thanks for any help.

Bill

See Darrel’s solution:
“To get Instant interrupts with Basic Language working on a 12F675 ...”
Open the DT_INTS-14.bas file and comment out the wsave lines. The 675 doesn't have any usable RAM in banks 1,2 or 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
' ------------------------------------------------------------------------------
Then in the ReEnterPBP.bas file comment the T?_save variables.

; T1_Save VAR WORD
; T2_Save VAR WORD
; T3_Save VAR WORD
; T4_Save VAR WORD
Just remember that if you use Instant Interrupts on a different chip later, you will need to un-comment those lines.
HTH,
__________________
DT
http://www.picbasic.co.uk/forum/showthread.php?p=49510#post49510

debutpic
- 2nd March 2008, 18:43
Hello all

Today I play with " Instant Interrupts" thank's Darrel

For to begin I use blinky program
I want to augment the speed of blink light by loading a value
in TMR1H and TMR1L but the speed does not change

Rq:
I want not to change the value of the prescaler


code:

'********************
TMR1H = %11111111
TMR1L = %11111110
'********************

1CON = %110001 ; Prescaler = 8, TMR1ON

what is wrong please?

Darrel Taylor
- 2nd March 2008, 20:58
I want to augment the speed of blink light by loading a value
in TMR1H and TMR1L but the speed does not change

code:

'********************
TMR1H = %11111111
TMR1L = %11111110
'********************

Loading that value %1111111111111110 = $FFFE = 65534
Means the timer will overflow after only 2 ticks.
A smaller number would help.

Also, it has to be loaded after every interrupt, not just at the beginning of the program.
<br>

debutpic
- 9th March 2008, 15:38
thank's Darrel

Remark:

In my next code if I load TMR1H with a high value code work fine

Main:

TMR1H = %11111111
pause 1

----------------------------

but if I reduce the value in TMR1H code don't work
display is OFF

Main:

TMR1H = %10111111
pause 1

-------------------------------
if I want use this value "TMR1H = %10111111"
I must write "pause 20" and not "pause 1"

an idea ???????

Darrel Taylor
- 9th March 2008, 20:26
No, I have no idea what you are doing.
If you're using a timer, why do you need pauses?

What frequency are you trying to run the timer at?
What frequency is your primary oscillator?
What PIC are you using?
<br>

debutpic
- 10th March 2008, 18:45
I use one 16F877 MCU to 20 Mhz

TMR1 produce an interrupt every 0,4 µSec
for to drive four 7 segment displays (prescaler:1)

My board developpement is EasyPic4

If I write not a Pause after TMR1H %11111111
then the displays don't work

skimask
- 10th March 2008, 19:02
I use one 16F877 MCU to 20 Mhz
TMR1 produce an interrupt every 0,4 µSec

At 4Mhz, each instruction takes 1 uSec to execute.
At 20Mhz, each instruciton takes .2 uSec to execute.
When you take in to account the fact that each jump/return to/from the interrupt handler takes at minimum 4 instructions cycles (2 for the jump into the int handler, 2 for the RETFIE after the handler), which happens to be .8uSec, you have less than ZERO time to do anything.
Even at 40Mhz, you're still at ZERO time left over.
At 48Mhz, you might get one instruction in here and there...
And even at 64Mhz, you probably won't get more than one or two instructions done between interrupts.

Ioannis
- 10th March 2008, 19:57
I think it is better to post the details of your project so that you could get a decent help. And the .4usec to drive a LED display, to me seems too little time.

Ioannis

skimask
- 10th March 2008, 20:28
And the .4usec to drive a LED display, to me seems too little time.

Maybe it's .4uSec for each update and not so much to display...
but like you said, can only help as much as you know in the first place...

debutpic
- 10th March 2008, 20:31
Thank's for your explanation it's clear now
I reduced the value preloaded in TMR1
and he works fine without "pause"

jrt4fun
- 27th March 2008, 14:11
Hello,

I've been reading through the posts regardings the Instant interrupts.
I'm still a little confused on the usage or setting of the ResetFlag.
Maybe I overlooked it in the posts but I did not find any info on this.
In some cases it is set to 'yes' but what is the influence.
--> ; IntSource, Label, Type, ResetFlag?

Can someone give me a little explanation on this?

Thank you.

Best regards,

mister_e
- 27th March 2008, 14:15
If you set it to YES, you don't need to clear the interrupt flags manually, DT's INT will do it for you.

If you set it to NO, the program won't reset the interrupt flag, so you'll have to do it yourself. In case you don't, your program will always turn in round in your ISR.

jrt4fun
- 27th March 2008, 15:03
Thank you for the fast response!

Regards

hvacrtech
- 31st March 2008, 02:15
After reviewing all posts on INT14.



Added

RBIF = RABIF
RBIE = RABIE to after ASM and just before INT_LIST.

@ INT_ENABLE RBC_INT

I can't get simple blinky to work and the errors are as listed.

I get few errors as shown

Error testin~1.ASM 985:[224] local directive only for use in macros
:[225] undefined symbol 'iflagreg'
:[226] numeric constant or symbol name expected
Fatal TESTIN~1.ASM 895:[300] too many errors.



Any idea?

Darrel Taylor
- 31st March 2008, 03:07
You have to be using MPASM as the assembler.
The default PM assembler will not work.
<br>

tenaja
- 31st March 2008, 03:15
Darrel,
How about a little tutorial on how to tell which assembler is in use, and how to switch to the mpasm?

Darrel Taylor
- 31st March 2008, 07:37
OK, how bout this for detection ...
ASM
ifdef PM_USED
"Dude, you have to use MPASM with DT_INTS"
endif
ENDASM

If you put that in your program, and try to assemble it with PM.exe, It will automatically pop-up a window in MicroCode Studio like this ...

<img src="http://www.picbasic.co.uk/forum/attachment.php?attachmentid=2450&stc=1&d=1206944939" />

Then you can just click on "Compile Using MPASM", and it will set the MPASM option and compile it.

If it still fails to compile, you should try this ...
http://www.picbasic.co.uk/forum/showpost.php?p=52195&postcount=11

I should add that to DT_INTS-14. :)

hth,
<br>

sayzer
- 1st April 2008, 14:39
Hi DT,

I wanted to post a "thank you" (also as an informative post).

For the first time ever, I used your 18F routine (with RX_INT) about a minute ago.

I saved 3100 bytes!!!

Really very interesting for me.

Thanks a lot for your amazing work.

Darrel Taylor
- 3rd April 2008, 04:36
Hi sayzer,

2 years and 3 months since you joined.
What took you so long? :eek:

WOW! Saved 3100 bytes. That's pretty impressive. http://www.picbasic.co.uk/forum/images/icons/icon14.gif

Can I ask what the difference was? or maybe where the savings came from?
<br>

sayzer
- 3rd April 2008, 08:35
Hi sayzer,

2 years and 3 months since you joined.
What took you so long? :eek:

WOW! Saved 3100 bytes. That's pretty impressive. http://www.picbasic.co.uk/forum/images/icons/icon14.gif

Can I ask what the difference was? or maybe where the savings came from?
<br>

The interesting part is that I did not change anything other the "int" part.

That is why it was surprising and "Really very interesting for me".

Ioannis
- 3rd April 2008, 08:42
You mean that comparing to On-Interrupt of PBP you did a reduction of 3100?

Ioannis

sayzer
- 3rd April 2008, 14:29
You mean that comparing to On-Interrupt of PBP you did a reduction of 3100?

Ioannis

Hi Ioannis,

Actually I tried different codes after this experiment and came up with these simple results.

1. In a relatively large code, DT's 18F int routine saves a lot of code space compared to On-Interrupt of PBP as you said.
Ex: I saved 3100 bytes for the same code (code size : approx. 18,000 bytes).

2. In a small code, DT's 18F routine becomes code hungry.
Ex: PBP On-Interrupt produces 318 bytes for a sample code I just tried, but
DT's 18F int routine produces 762 bytes. More then twice larger!


As the code gets longer, DT's int routine gets handier I suppose.

Ioannis
- 4th April 2008, 08:29
Since On Interrupts of PBP puts a check every assembly instructions is obvious why is that code explosion!

Sure Darrels routines are fixed in length, so either your code is short or long, these routines are known in length. And in my humbble opinion, comparing Darrels interrupts with PBP interrupts is like comparing apples and oranges. Two different things.

Ioannis

tur_bot
- 5th April 2008, 00:26
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.
<table border=0 cellpadding=5><tr><td valign=top>
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
&nbsp; 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. &nbsp; Reducing those RTFM sessions to a minimum. &nbsp; The table to the right lists the Named Interrupts.



</td><td ><table border=1 cellpadding=5><tr><td valign=top nowrap> <center><b>Available Interrupt Sources</b> &nbsp; 14-bit</center><pre> INT_INT -- INT External Interrupt<br> RBC_INT -- RB Port Change Interrupt<br> TMR0_INT -- TMR0 Overflow Interrupt 16F<br> TMR1_INT -- TMR1 Overflow Interrupt<br> TMR2_INT -- TMR2 to PR2 Match Interrupt<br> TX_INT -- USART Transmit Interrupt<br> RX_INT -- USART Receive Interrupt<br> CMP_INT -- Comparator Interrupt<br> EE_INT -- EEPROM/FLASH Write Operation Interrupt<br> BUS_INT -- Bus Collision Interrupt<br> PSP_INT -- Parallel Slave Port Read/Write Interrupt<br> AD_INT -- A/D Converter Interrupt<br> SSP_INT -- Master Synchronous Serial Port Interrupt<br> CCP1_INT -- CCP1 Interrupt<br> CCP2_INT -- CCP2 Interrupt</pre></td></tr></table></td></tr></table>Here's a simple example of toggling an LED using the external interrupt (INT). (Hello World)
<font color="#000000"><b>LED1 </b><font color="#008000"><b>VAR </b></font><b>PORTB</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>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
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="#008000"><b>ENDASM

</b></font><b>Main</b>:
<font color="#008000"><b>PAUSE </b></font><b>1
</b><font color="#008000"><b>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 size=-2>Code Size = 234 words</font>
<script language="javascript" src="http://www.darreltaylor.com/files/forum_ii.js"></script>

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

<br>

hello,
i just tested the program with the 16f88 but it s not working , there are some error messages.

dont know exactly what to do next
can u give me some advices please??
thanx

mister_e
- 5th April 2008, 00:35
NO.. ;) at least give more details... error message, code etc etc

Make sure you're using MPASM to compile :o

skimask
- 5th April 2008, 06:36
NO.. ;) at least give more details... error message, code etc etc
Make sure you're using MPASM to compile :o

Judging from the:
@ DEVICE INTRC_OSC, LVP_OFF, WDT_OFF, MCLR_OFF
in the rest of the posts...hmmmmmmmmmmm........

flipper_md
- 24th April 2008, 01:42
WoW!

those routines works like magic for a noobie like me :)

I've found out that most of my code must be done inside the interrupt part, otherwise if it's in the Main loop it can get trashed by the interrupt(like SEROUT to a serial LCD), but it got my
latest project running very quickly.



tnx Darrel

Andre_Pretorius
- 30th April 2008, 17:42
First of all thanx for the code my interups now gets handeled fast enoug so i dont loose any serial data, one problem for some reason my program do not return from the interupt.
Any ideas
i use a 16f913



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

DEFINE OSC 20 ' Define crystal as 20Mhz

'*Serial port Setup 9600 8N1*
DEFINE HSER_BAUD 9600 ; 9600 Baud
DEFINE HSER_RCSTA 90h ' Enable serial port & continuous receive
DEFINE HSER_TXSTA 24h ' Enable transmit, BRGH = 1
DEFINE HSER_CLROERR 1 ; Clear overflow automatically

'*ADC setup*
DEFINE ADC_BITS 10 'SETS NUMBER OF BITS IN RESULTS 8,10,12
DEFINE ADC_CLOCK 3 'SETS CLOCK SOURCE (RC = 3)
DEFINE ADC_SAMPLEUS 50 'SETS SAMPLING TIME IN MICROSECONDS

'This Part set PORTA 0-5 an analog inputs
ADCON1 = %01110000 'FRC (clock derived from a dedicated internal oscillator = 500 kHz max)
ANSEL = %00011111 'The ANSEL (91h) and CMCON0 (9Ch)registers must be initialized to configure an
CMCON0 = %00000111 'analog channel as a digital input. Pins configured as analog inputs will read ‘0’.
TRISA = %00011111 'set PORTA 0-5 as inputs
ADCON0.7 = 1 'Right justify output of ADC datasheet P145 of 16F913

TRISC = %10000000 'Set PORTC for serial coms and pins as output
TRISB = %00000000 'Sert PORTb as outputs and for use with the ICD2

V1 var WORD
ID var byte[28]
CELL1 VAR BYTE[11]
I VAR BYTE

PORTC = 0

ASM
INT_LIST macro ; IntSource, Label, Type, ResetFlag?
INT_Handler RX_INT, _IntLoop, ASM, yes
endm
INT_CREATE ; Creates the interrupt processor
INT_ENABLE RX_INT ; enable external (RX) interrupts

ENDASM


Main:
PORTC.5=1
PAUSE 200
PORTC.5=0
PAUSE 200
PORTC.5=1
PAUSE 200
PORTC.5=0
goto Main

IntLoop:
HSERIN [WAIT("^SMGL:"),SKIP 1 ,str ID\28]
HSEROUT ["CELL NO:",_
ID[17],iD[18],ID[19],ID[20],ID[21],ID[22],_
ID[23],ID[24],ID[25],ID[26],ID[27],10,13]
@ INT_RETURN

END

mister_e
- 30th April 2008, 18:54
As you're using HSERIN/HSEROUT, shouldn't RX_INT be PBP type instead?

Don't forget to add ReEnterPBP.bas in your INCLUDE list.

sougata
- 30th April 2008, 19:44
Hi,

I thought I could point this out. This forum is fortunate that there are less people like me. Late and lazy.
BTW Steve everytime I see the avatar banging head on the keyboard I feel concerned. Please stop banging your head. Its costly. I mean the keyboard that is...

mister_e
- 30th April 2008, 20:12
LMAO! well this avatar is really me... if you feel concern... i'm sorry :D

I see some other potential problem in the above anyways.

From one of his previous post he says that
^SMGL: 1,"REC UNREAD","+27829554322",,"08/04/20,17:12:09+08"
could be the incoming string... so obviously, using his HSERIN line, it may return to the INT routine and spining around and around. my 2nd suggestion add a little timeout like this...

IntLoop:
HSERIN 10, GETOUT,[WAIT("^SMGL:"),SKIP 1 ,str ID\28]
HSEROUT ["CELL NO:",_
ID[17],iD[18],ID[19],ID[20],ID[21],ID[22],_
ID[23],ID[24],ID[25],ID[26],ID[27],10,13]
GETOUT:
@ INT_RETURN

this way + PBP type it should solve most, see all problems.

HTH

Andre_Pretorius
- 30th April 2008, 20:48
Thanks mister-e the second suggestion with the time out did the trick, still not hundred present sure why it works like that but shore are glad it works
Thanks again

mister_e
- 30th April 2008, 21:28
look post 296... if i was right, your PIC will wait 'till the next time it receive ^SMGL: when the timeout is not used.

bcd
- 1st May 2008, 08:52
I have been playing with the code shown below on a 16f737 as I was trying to get different prescaler values into the int routinues. As part of the testing I stripped the code right back to just be a simple interrupt with a value loaded into the pre-load registrer, but I seem to end up with an interrupt time of 204uS. According to the Timer Calc in Mister E's PicMulti Calc I should get an interrupt every 5.019mS. (see attached image for capture of the output waveform - I love my PICkit 2!)

This code is lifted straight from Darells example with the blinky led (1-2-3 version), and all I have done is add the pre-load. I have also removed the pre-load and still get the same time for the interrupt.



DEFINE OSC 20

rs_led var portb.7 ' rs232 led
led var portc.4 ' was Data_Out line

'''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''''''

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 TMR0_INT, _doBAM, PBP, yes
endm
INT_CREATE ; Creates the interrupt processor
ENDASM

OPTION_REG = OPTION_REG & $80 | 1 'Set TMR0 Prescaler to 256, leave RBPU alone

TMR0 = 158 ' preload with 158 to give 21uS interrupts (at 1:1)
' this should then give Interrupt every 5.019mS at 1:256

@ INT_ENABLE TMR0_INT ; enable Timer 1 interrupts
'~~~~~~~~~~~~~~~~~~

goto main ' jump over ISR

'---[TMR0 - interrupt handler]--------------------------------------------------
doBAM:
toggle rs_led
@ INT_RETURN

'~~~~~~~~~~~~~~~~~~~~~~~~~~~
high rs_led
main:

'''''''''''''''''''''''
' do some flashing led stuff
'''''''''''''''''''''''
high led
pause 500
low led
pause 500
goto main


There has got to be something really simple I am missing...
bill.

Darrel Taylor
- 1st May 2008, 10:57
Use OPTION_REG = %11010111

And load the timer on every interrupt.
<br>

bcd
- 1st May 2008, 13:39
Thanks,

See told you it would be something really simple I missed..



doBAM:
toggle rs_led
TMR0 = 158 ' reload the pre-load
@ INT_RETURN


(Hey Darrel - how do you get your code blocks so colourful and properly indented ?)

bill.

skimask
- 1st May 2008, 13:43
(Hey Darrel - how do you get your code blocks so colourful and properly indented ?)
bill.

http://www.picbasic.co.uk/forum/showthread.php?t=6221

The page may take awhile to load.....

leisryan
- 29th May 2008, 07:38
Hello;
I'm Ryan form the Philippines I must admit DTS-14 ints rules!!! i'd like to know how can i turn the interrupt on and off for USART continues recepton I'm using PIC16f877a toggling register PIE.5 doesn't seem to work

Thanks

PS.

Part of my project i'm paying my tuition continue college again OSY for sometime now hehe (",)

Archangel
- 29th May 2008, 08:36
Check out this post, esp. post 5, http://www.picbasic.co.uk/forum/showthread.php?t=3251

mister_e
- 29th May 2008, 18:09
you can use
@ INT_ENABLE RX_INT

and

@ INT_DISABLE RX_INT

leisryan
- 30th May 2008, 03:42
ahhh thanks guys

fixed it toggling both
' CREN = 0
' SPEN = 0

I didn't bother with the interrupts just disabled the Port input thanks I appreciate it!!!

Norbac
- 30th May 2008, 19:04
Hi Darrell, I tried to use your great rutines without any luck. I'm using a 18F248 sending CAN messages and I want to use a timer interrupt to send it.
Just to test the rutines I tried to compile the example you post for timer interrupt and DT_INTS-18.bas rutines. But I got some errors on the compilation. Attached you will find a screen shot of what i'm talking about. If anybody can tell me what I'm doing wrong, it will be a great help for me.

Thanks in advance for all yor help

Alfredo

Darrel Taylor
- 30th May 2008, 22:48
Hi Alfredo,

Well apparently, not all CAN modules are the same.
There are 2 types, CAN and ECAN.

I didn't consider the plain CAN module when I wrote it. :o

I'll have to make a way for it to detect which module is available and only use the interrupts for it. Then I'll post an update.

But for now, you can just comment out the interrupt Sources that aren't available.
In the DT_INTS-18.bas file, comment out the following lines in the CAN Module section ...
asm ; -- CAN Module --
ifdef WAKIF
;----{ CAN bus Error }------------------------[PIR3, ERRIF]---
INT_Source CAN_ERR_INT, PIE3,ERRIE, IPR3,ERRIP

;----{ Invalid Received Message }-------------[PIR3, IRXIF]---
INT_Source CAN_IRX_INT, PIE3,IRXIE, IPR3,IRXIP

;----{ Receive Buffer 0 }------Mode 0--------[PIR3, RXB0IF]---
INT_Source CAN_RXB0_INT, PIE3,RXB0IE, IPR3,RXB0IP
;----{ FIFO Watermark }--------Mode 1, 2---[PIR3, FIFOWMIF]---
; INT_Source CAN_FIFOWM_INT, PIE3,FIFOWMIE, IPR3,FIFOWMIP

;----{ Receive Buffer 1 }------Mode 0--------[PIR3, RXB1IF]---
INT_Source CAN_RXB1_INT, PIE3,RXB1IE, IPR3,RXB1IP
;----{ Any Receive Buffer }----Mode 1, 2-----[PIR3, RXBnIF]---
; INT_Source CAN_RXBn_INT, PIE3,RXBnIE, IPR3,RXBnIP

;----{ Transmit Buffer 0 }-------------------[PIR3, TXB0IF]---
INT_Source CAN_TXB0_INT, PIE3,TXB0IE, IPR3,TXB0IP

;----{ Transmit Buffer 1 }-------------------[PIR3, TXB1IF]---
INT_Source CAN_TXB1_INT, PIE3,TXB1IE, IPR3,TXB1IP

;----{ Transmit Buffer 2 }-----Mode 0=-------[PIR3, TXB2IF]---
INT_Source CAN_TXB2_INT, PIE3,TXB2IE, IPR3,TXB2IP
;----{ Any Transmit Buffer }---Mode 1, 2-----[PIR3, TXBnIF]---
; INT_Source CAN_TXBn_INT, PIE3,TXBnIE, IPR3,TXBnIP

;----{ CAN bus Activity Wake-up }-------------[PIR3, WAKIF]---
INT_Source CAN_WAKE_INT, PIE3,WAKIE, IPR3,WAKIP
endif

list
endm
list
ENDASM


Thanks for the info!

Norbac
- 30th May 2008, 22:59
WOOOOW!
Thank you very much for the info, now I can use your rutines!!! Your info fix my problem

Thanks again!!!

Alfredo

mister_e
- 30th May 2008, 23:10
.Damn.. way to slow this time :D

my solution was..



asm
RXBnIF=RXB1IF
TXBnIF=TXB2IF
FIFOWMIF=RXB0IF
INT_LIST MACRO
INT_Handler TMR1_INT, _ToggleLED1, PBP, yes
endm
INT_CREATE
endasm

From p18f8680.inc file...


;----- PIR3 Bits -----------------------------------------------------
RXB0IF EQU H'0000'
RXB1IF EQU H'0001'
TXB0IF EQU H'0002'
TXB1IF EQU H'0003'
TXB2IF EQU H'0004'
ERRIF EQU H'0005'
WAKIF EQU H'0006'
IRXIF EQU H'0007'

FIFOWMIF EQU H'0000'
RXBnIF EQU H'0001'
TXBnIF EQU H'0004'

On another hand... seems odd...

Darrel Taylor
- 30th May 2008, 23:42
Good one Steve. That would have worked too. http://www.picbasic.co.uk/forum/images/icons/icon14.gif

Since they're actually the same bit's, but with different Names depending on the mode, that might be an easy way for me to fix it. Maybe.
<br>

mister_e
- 30th May 2008, 23:51
But yeah... we know how Microchip work... hard to tell if it will always work... on all PIC :D

Worth a try!

Squibcakes
- 5th June 2008, 01:25
Steve,

Do you know if the there is any difference in accuracy between using a xtal osc and the internal RC osc esp. in relation to timer interrupts?

Squib

Darrel Taylor
- 6th June 2008, 04:13
Must be Steve's day off. :)

Hi Squib,

Well it depends on the internal oscillator type, and how you're using the interrupts.

The typical general purpose crystal will have a tolerance of +/- 50 PPM (Parts per million) Although there are other crystals with tighter tolerances, some down to less than 1 PPM. But they come at a higher cost.

If you're using one of the older 4mhz internal oscillators, depending on temperature and proper calibration numbers, they can vary up to +/-10% (100,000 PPM). A HUGE difference.

The newer 8mhz oscillators will vary a modest +/- 2.5% over the temperature range, but that's still 25,000 PPM.

If the interrupts are being used for "Long Term" timing like a clock, a difference of 1 PPM translates to an error of +/- 31.5 seconds per year. At 50 PPM it's 26.3 minutes/yr

But with the 8mhz INT_OSC, you're looking at a whopping 9.1 Days/Yr.. And with the old 4mhz osc you're off by +/-36.5 days. Yikes!

Of course these are "Worst case" numbers with maximum temperature extremes, actual results may vary.

hth,

tenaja
- 6th June 2008, 06:58
For reference, I recently tried to see what kind of baud I could get out of my pic serial port, using the internal 8MHz osc. I used an FTDI232R on the PC side, which accepts +/- 3% on the baud rate. The lower baud rates locked in fine, but at 125Kbaud, I had to slow the PIC baud rate down to 118k to 124k. (I did not try any fractions to get more precise failure speeds.) Apparently at the temperature of that particular pic at that particular time, the oscillator was running about 3% fast. That's 30,000 parts per million... way off, I would say.

Squibcakes
- 6th June 2008, 07:09
Thanks DT for the info, those are some pretty scarey numbers you pulled up!

The reason I asked was I have a three minute timer using DT_14 interrupts and I also used Steves Pic timer calc but I'm consistantly getting the timer out by about -10 secs using the int_osc at 8MHz.

I'll try an ext_xtal and see if I get the same error, but comparing my error to the numbers you pulled up, mines probabaly due to a coding error. :-)

If I find a difference I'll let you know.

Cheers

Darrel Taylor
- 6th June 2008, 21:24
but I'm consistantly getting the timer out by about -10 secs using the int_osc at 8MHz.

10 seconds in 3 minutes ....
That's around a 5.5% error, and the OSC would be 7,555,556 Mhz.
http://spreadsheets.google.com/pub?key=pthtFkHw5uiCKE-EFrRLaZA

I think you're right about it not being the OSC :eek:

Are you using the Timer Template, or the Elapsed Timer?

RussMartin
- 17th June 2008, 05:47
Apropos of nothing in particular . . .

I finally had a project where I needed a simple background "heartbeat" indicator while doing other things with a 16F627A, so I used Darrel's "overkill" blinky.

It works like a charm.

I'll tell everyone this:

It took a few tries, but solutions for each problem and error message I encountered were found on this site. I just had to Do A Search.

. . . well, except one instance--I was getting a message that the file path to the source code was too long (something like in excess of 62 characters). So I moved the file set to a different location with a shorter path. Duh!

I suppose the point I'm making, though, is that beyond RTFM and RTFDS, it doesn't hurt to DAFS.

The search tool Darrel posted works really well, sometimes with as little as a few words from the error message.

Kudos to Darrel Taylor!

menta
- 22nd June 2008, 21:35
I'm having problems with my LCD (BPI-216) when using these intterupts.
When using the code for the clock interrupt and button interrupt the LCD display junk.
If using only one of the intterupts the junk is less, but still.
It is mostly happen if pressing then button very often.
Can someone advice?

Ioannis
- 22nd June 2008, 22:08
As Steve noted on many post before:


NO.. ;) at least give more details... error message, code etc etc

Make sure you're using MPASM to compile :o

We are not fortune tellers here. More input as Johnny 5 said once!

Ioannis

menta
- 22nd June 2008, 22:30
Well,
First I was asking if someone has problems with INT when using the BPI-216 LCD.
Anyway,
When using this code on my 16F887, The LCD gets freaked.
I will just display junk. I tried to eliminate some of the timers, and as said before, When having only INT for button or for clock it reduce the junk.

Other code which implemets clock without INT but just timer, (http://www.picbasic.co.uk/forum/showthread.php?t=2129) works perfect with this LCD.
Here is the code that makes it go crazy:


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
IF Hours>9 THEN
SEROUT PORTB.1,6,[254,128,#Hours,58]
pause 300
ELSE
SEROUT PORTB.1,6,[254,128,48,#Hours,58]
pause 30
ENDIF
IF Minutes>9 THEN
SEROUT PORTB.1,6,[254,131,#Minutes,58]
pause 300
ELSE
SEROUT PORTB.1,6,[254,131,48,#Minutes,58]
pause 300
ENDIF
IF Seconds>9 THEN
SEROUT PORTB.1,6,[254,134,#Seconds]
pause 300
ELSE
SEROUT PORTB.1,6,[254,134,48,#Seconds]
pause 300
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

menta
- 22nd June 2008, 22:35
btw,
If I disable INT (INTCON=0) the LCD shows correctly, but of ocurse interrupts are not working.

ronjodu
- 23rd June 2008, 03:43
What I do is turn off interrupts before serial and back on after serial completes. Like this:


sendudp:
INTCON.7 = 0
SerOut2 PORTC.6, 84, [$50] 'ask siteplayer to send udp
INTCON.7 = 1
udpcount = 0
gosub delay
return


Somewhere in here there is a list of the commands affected by Instant interrupts. I just turn the interrupts off, execute the command and turn the interrupts back on.
I'm not sure if this is the best way to handle things but it's worked well for me so far.
Hope this helps.

menta
- 23rd June 2008, 17:13
Well,
What if the interrupts are for the clock ?
Disabling it will cause the clock not to keep going.

skimask
- 23rd June 2008, 21:04
Well,
What if the interrupts are for the clock ?
Disabling it will cause the clock not to keep going.

Then add an RTC chip.

Darrel Taylor
- 23rd June 2008, 22:32
Hi menta,

Any type of software timed commands like SERIN/OUT, OWIN/OUT, PAUSE, PULSIN/OUT etc, will be disturbed by these types of Interrupts.

That's why there's an ON INTERRUPT GOTO statement. It reverses the situation, so that the PAUSE, SERIN/OUT etc trash the Interrupts instead, which seems more tolerable to people new to PBP, but just drove me crazy. And is why I ended up with DT_INTS.

With Interrupts, you need to use HARDWARE solutions instead of the SOFTWARE timed commands, and in your case the 16F887 has a USART on-board that is NOT affected by interrupts.

So just switch over to HSEROUT, and your problems will vanish.

DT

menta
- 24th June 2008, 14:15
Great, will try this.

sayzer
- 7th July 2008, 14:30
Hi DT,

This question is not related to the current ongoing subject but is about your int routine.

Is it safe (or how safe) to call a subroutine inside your interrupt handler?

Or inside PBP int handler?


Thanks.

Ioannis
- 7th July 2008, 16:19
I am not DT, but for sure it is not recommended in any way to do a call inside the int routine. Think of the delays to go forth and back plus whatever you are going to do inside the sub. Can you make it absolutely sure that the call will be a zap?

I am sure there is another wayto implement your project.

Ioannis

Darrel Taylor
- 7th July 2008, 18:41
I agree with Ioannis.
It's not really recommended, but it is possible.

The worst case scenario is with a 16F PIC.
They only have 8 stack levels, and some of PBP's commands can use 4 of them. Which is why you can only nest gosubs 4 levels deep in any 16F program.

In your main program, it may already be 3-4 levels deep when an interrupt triggers. If you then ReEnter PBP, do a GOSUB and try to run a 4-level PBP command, the stack will definitely overflow.

Using the Software Stack (http://www.picbasic.co.uk/forum/showthread.php?t=151) can eliminate that problem.

With an 18F there are several more stack levels, so it's not as much of a problem. And of course, if you write the handlers and subroutines in ASM, it's even less of a problem.
<br>

sayzer
- 8th July 2008, 08:49
Thanks IO.
I already knew about delay issues but it takes approx. 30 seconds for my code to complete int routine. So my code is not time sensitive.

What I needed to know was DT's warnings about deep levels.

Thanks DT, that is what I now need to consider.

---------------------

alanmcf
- 25th July 2008, 02:16
Hi--

I'm having a problem with Instant Interrupts that I can't figure out... I'm using Darrell's Elapsed Timer with V3.2 of DT_INTS-18 and Reenter-PBP-18. The chip is an 18F4520 running at 16MHz. The interrupt-driven elapsed timer system works beautifully, but then I can no longer use the second PWM output, CCP2, which I have set up to output on portc.1. CCP1 works perfectly. This is true whether I use the HPWM command and PBP defines or set up the PWM registers directly as described in the data sheet.

What happens is that portc.1 goes low and stays that way. If I disable the DT includes and the interrupt handler, the PWM CCP2 port functions normally. I have checked and double checked things like the portb/c multiplexing and the tris output settings, etc. What I think is happening is something in Darrrell's code is clearing CCP2CON, but I haven't been able to find it.

Does anybody have any ideas to try?

Thanks--

--Alan

sougata
- 25th July 2008, 06:55
Hi,

It is very unlikely that DT's int handler mess with your CCP2CON register. Do you have a LCD / Serial / Debug out then try dumping the CCP2COn values periodically to know whats going on.

A look at the code may be helpful. I have 18F4520 ready with me and would like to duplicate the problem for my own interest.

alanmcf
- 25th July 2008, 07:29
Hi sougata--

The code is massive, with a dozen include files... it would be a real mess to upload it. PWM on channel 1 always works. I have discovered since I posted that message that if I start Timer1 (T1CON.0 = 1, the timer that is used by Darrell's Elapsed Timer code), then the PWM on channel 2 works. Stop timer 1, and channel 2 PWM stops working. But if I comment out all of Darrell's code and recompile, both PWM ports work perfectly.

PWM only uses Timer 2, so I am baffled. I do have an LCD attached, I will try reading the CCP2CON register and see what its thinking.

Thanks--

--Alan

Bruce
- 25th July 2008, 19:10
I think the default for channel 2 is Timer1 unless you use the DEFINE HPWM2_TIMER 2 option.
Channel 1 defaults to Timer2 so you would still see this channel working when disabling Timer1.

See if adding DEFINE HPWM2_TIMER 2 doesn't cure the problem.

Edit: Scratch that one. This is apparantly only for 17C7xx device types.

Darrel Taylor
- 25th July 2008, 21:42
Well, without the code, we're reduced to playing 20 questions.

Please post at least the Interrupt Definitions, handlers (other than Elapsed), and ANY and ALL lines that modify the following registers.

T1CON
INTCON
INTCON2
INTCON3

PIE1
PIE2
IPR1
IPR2

<br>

sougata
- 26th July 2008, 01:33
Hi,

DT's Elapsed Timer takes care of setting T1CON right in the "StartTimer" . If by any means T1CON oscillator is turned on then PORTC.1 becomes an input regardless of the TRIS settings. Still it does not explain why and how the PWM starts when Timer1 is started.

What happens when your PWM stops the pin in set low/high ?
I hope you are quite aware that if duty cycle is higher than period then the pin never gets cleared.

Mr.E where is your crystal ball ??!!??

Darrel Taylor
- 26th July 2008, 07:56
If by any means T1CON oscillator is turned on then PORTC.1 becomes an input regardless of the TRIS settings.

That's a good possibility.


Still it does not explain why and how the PWM starts when Timer1 is started.

So True!

> Mr.E where is your crystal ball ??!!??
Ummm, being that he hasn't logged in since 15th June 2008
I'd say he's in Jail. :eek:

Can't imagine mister-e not checking in, if he could.
<br>

alanmcf
- 28th July 2008, 23:17
Hmmm... Sougata's point about starting timer1 sounds like it might be the culprit, at least as far as RC1 going to input. PWM2 drives a fan via a MOSFET, so if RC1 goes to input, the pullup I have on the MOSFET would drive the fan to full speed, which is exactly what's happening. I haven't yet found in the data sheet why turning timer1 on does that to RC1.

I have attached the code relevant to Darrel's question. The INCLUDE files that aren't attached don't modify the registers Darrel was talking about. I have very little experience with using the timers or using interrupts-- is it possible to just modify the Elapsed Timer routine to use timer 0 or timer3?

Thanks--

--Alan

Darrel Taylor
- 29th July 2008, 01:11
Hmmm... Sougata's point about starting timer1 sounds like it might be the culprit,

It is!

The line T1CON = %00001101 '<-- settings for 16 MHz turns on the Timer1 Oscillator, which disables RC1's digital I/O functions.

Since you are using the Elapsed Timer, there's no need to set T1CON. The Include file does that for you.
<br>

Ioannis
- 29th July 2008, 09:10
Can't imagine mister-e not checking in, if he could.
<br>

In fact, I had some tel. discussion 1 and 1/2 month ago with Steve, but when I tried to find him again, he disappeared. No telephones (only tel. answering machine) no e-mails. If anyone knows about Steve please inform. He had some misfortunes in the past as we can recall, just hope all is OK now, lying in some beach.

Ioannis

alanmcf
- 29th July 2008, 18:31
Hi Darrel--

Are you saying that your elapsed timer routine uses Timer1 without actually turning it on, thereby avoiding the portc.1 problem? I will try this immediately!

Thanks--

--Alan

Darrel Taylor
- 29th July 2008, 19:16
Yes, It uses Timer1. But it doesn't turn on the External Oscillator.

Timer1 has a feature that lets you hook up a 32768hz crystal on the T1OSO(RC0) and T1OSI(RC1) pins. This oscillator will continue running in sleep mode, so it can be used to keep time like a clock.

But the way you are using the Timer, it's using the signal from the main System Oscillator, so there's no need to turn the ext. osc on.

For the Elapsed timer, you can use the StartTimer and StopTimer subroutines.

hth,

sougata
- 29th July 2008, 19:23
Skimask pointed this out

http://www.picbasic.co.uk/forum/showthread.php?p=60058#post60058


BTW I would encourage everybody to have a look at DT's codes and try to figure out the amount of hard work and pure AI (I beleive he is an android built by microchip using surplus production :eek: ) he has put in.

Meant to make our life easy and enlighten us, the mere mortals on PIC and PBP.

alanmcf
- 29th July 2008, 21:57
Sougata is right, and yes, Darrel, I am not worthy. Arthur C. Clarke said that any sufficiently advanced technology would be indistinguishable from magic; Instant Interrupts is magic, and Darrel is the resident magician.

Thanks so much for creating it!

Darrel Taylor
- 29th July 2008, 22:20
And Helen Keller said ...

"Life is a succession of lessons which must be lived to be understood."

Until you've had the problem, you won't know about them.

Keep having problems. :)

alegazzi
- 31st July 2008, 14:54
Hi Darrel, sorry my english.

I need help for this message:

Message[301] c:\..........asm 3074:MESSAGE:(Temp variables exceeding T7)

Tks.

Darrel Taylor
- 31st July 2008, 22:07
When you have Complex formulas, or very Long IF/THEN comparisons, the PBP compiler generates additional (T)emporary System variables to keep track of the intermediate results.

If those formulas are in the Interrupt Handler, it can cause big problems. But, if they are ONLY in the main program, they will NOT be a problem.

There's no way for DT_INTS to know if they are in the Handler or the Main program, so it gives a Warning (message) to let you know to look and verify that they are NOT in the handlers.

After you have VERIFIED that the formulas are NOT in the handlers. You can add this define to stop the Warning.
DEFINE NO_T7_WARNING 1

hth,

mpanetta
- 27th August 2008, 17:57
Is this true? I can believe it to be. If so, is there any way I can replace this functionality using the interrupt driven counters or something? A hardware counter is not an option unfortunately, as the board is already in units in the field.

The reason I need to add interrupts is because I need to add background hardware UART character reception using UART2 because the program spends too much time doing other things in the foreground to service the port soon enough.

Is there a list of what PBP functions are affected by DT_INTS? If so where can I find it?

Does anyone have examples of interrupt driven serial IO using DT_INTS? How about pulse counting routines?

Thanks,
Mike

b1arrk5
- 1st September 2008, 01:57
Hi Mike,
Here is my serial interrupt handler using Darrel's Instant Interrupts;

SerialInt:
Hserin [STR buffer\45\$8e] 'read up to 45 bytes into array, end if value is hex 8e.
@ Int_Return

That's all there is to it. If you do a search for frequency measurement, you will find some code that Bruce put together using Instant Interrupts to measure pulse width, and I think you could make it work for you.

Good Luck,

Jerry

mpanetta
- 2nd September 2008, 15:30
Thanks for the code snippet! It looks easier then I thought it would be to implement the serial stuff. I was worried I would have to code something in ASM and use buffers etc...

As for the frequency measurement stuff, I did a search and I can't seem to find what your referring to. Do you happen to have a link handy? Is it on this board, or somewhere else?

Thanks,
Mike

itelmex
- 2nd September 2008, 17:25
I was testing with darrel Taylor Instant interrups. The colaboration is fantastic. Great.

I mount four 7 seg, 4 inches each, with common anode, and the 16f877A. The input for data is the serial input, across portc.7. I probe fist without darrel tool, using on interrupts and I see that the serial input line stop de scan for the 7 segs, because the multiplexing loss the times in this waiting for the data. Each display is activate with portd.4 to portd.7

The circuit work fine, so, the program need tuning up.

When I used the Darrel tool, the time for the 7 segs scan don't change with the data wait in the serian in line, including this part in the main loop. The scan for the multiplexing is in instant interrup routine. My dude, in this case, is with time multiplexing scan. I not Know what is the lines for the scan, and in this moment, i only see the scan very slow.

I need help for to put the timer a time for correct and fast scan.

Thanks.

Luis Elizarraraz

Darrel Taylor
- 2nd September 2008, 21:34
If you are using an interrupt handler to receive the serial data, then nothing else can happen until the handler is finished.

If other things must continue operating at the same time, you either have to read the serial data 1 byte per interrupt, or have the HSERIN statement in the main loop so that it can be interrupted like everthing else.

Sitting in the handler WAITing for the data, will not work.
<br>

itelmex
- 3rd September 2008, 00:02
Thanks for answer me Darrel.

The code for my application is the follow:


'-------------------------------------------------------------------------------------
'
'Start

INCLUDE "MODEDEFS.BAS"

define loader_used 1
DEFINE OSC 20 ' Define crystal as 4Mhz

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

' ** Declare the Variables **
LEDS Var Byte ' The amount of LEDs in the display
O_C Var Byte ' Used by the interrupt for time sharing
Counter Var byte ' General purpose counter
Del Var Word ' General purpose delay loop variable
del1 var word
D_Number Var word ' The number to display on the LEDS
DP Var Byte ' Position of the decimal point
Disp_Patt Var Byte ' Pattern to output to PortC
Num Var Byte[4] ' Array to hold each digits value
Digit1 var Portd.4 ' 1ro
Digit0 Var Portd.5 ' 2do
Digit3 Var Portd.6 ' 3ro
Digit2 Var Portd.7 ' 4to

' ** THE MAIN PROGRAM STARTS HERE **

trisd=%00001111 'portd.4 a portd.7 like output
TrisB=0 ' Make PortB and PortC outputs
PortC=0:PortB=0 ' Clear PortB and PortC
O_C=0 ' Clear the time share variable

TRISB=0

x var byte
y var byte
duty var byte
canal var byte
d var word

v1 VAR word
V2 VAR word
ciclo var word
indi var bit
conta var byte

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

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


d=0
ciclo=0
indi=0

high portd.7
high portd.6
high portd.5
high portd.4



Main:
serout2 portc.6,84,[13,"C>"]
serin2 portc.7,84,3000,main,[dec4 D_Number]
serout2 portc.6,84,["L"]
Gosub Display ' Display the value
goto main

Display:
For LEDS=3 to 0 step -1 ' Loop for 4 digits (0-65535) ' Disable the interrupt while we calculate
Num[LEDS]=D_Number dig LEDS ' Extract the seperate digits into the array
If D_Number<10 and LEDS=1 then Num[LEDS]=10 ' Zero Suppression for the second digit
If D_Number<100 and LEDS=2 then Num[LEDS]=10 ' Zero Suppression for the Third digit
If D_Number<1000 and LEDS=3 then Num[LEDS]=10 ' Zero Suppression for the Third digit ' Re-enable the interrupt
Next
return
' INTERRUPT HANDLER
' Multiplexes the 3-digits
'
Disable ' Disable all interupts during the interrupt handler

Multi:
'sigue: ' 0 1 2 3 4 5 6 7 8 9 A B C E F G H I J L N 0 U b c d e f g h i n p q s o u
lookup Num[O_C],[63,6,91,79,102,109,125,39,127,111,119,127,57,121,1 13,125,118,6,30,56,55,63,62,124,88,94,123,113,111, 116,4,84,115,103,109,92,28],Disp_Patt
' Lookup Num[O_C],[192,249,164,176,153,146,130,248,128,144,255],Disp_Patt ' Decode the segments for the LED
' Process the first display (farthest right)
If O_C=0 then ' If it is our turn then
Digit3=1 ' Turn OFF the 3er LED
PortB=Disp_Patt ' Place the digit pattern on portC
If DP=1 then PortB.7=0 ' Check the value of DP and Turn ON the decimal point
Digit0=0 ' Turn ON the first LED
Endif
' Process the second display
If O_C=1 then ' If it is our turn then
Digit0=1 ' Turn OFF the first LED
PortB=Disp_Patt ' Place the digit pattern on portC
If DP=2 then PortB.7=0 ' Check the value of DP and Turn ON the decimal point
Digit1=0 ' Turn ON the second LED
Endif
' Process the third display
If O_C=2 then ' If it is our turn then
Digit1=1 ' Turn OFF the second LED
PortB=Disp_Patt ' Place the digit pattern on portC
If DP=3 then PortB.7=0 ' Check the value of DP and Turn ON the decimal point
Digit2=0 ' Turn ON the third LED
Endif

' Process the 4th display
If O_C=3 then ' If it is our turn then
Digit2=1 ' Turn OFF the second LED
PortB=Disp_Patt ' Place the digit pattern on portC
If DP=4 then PortB.7=0 ' Check the value of DP and Turn ON the decimal point
Digit3=0 ' Turn ON the third LED
Endif

O_C=O_C+1 ' Increment the time share counter
If O_C>=4 then O_C=0 ' If it reaches 3 or over then clear it

@ INT_RETURN ' Allow more interrupts

Darrel Taylor
- 3rd September 2008, 00:39
Yup, that's pretty slow.

At 20mhz with 1:1 prescaler, you'll get an interrupt every 13.1ms.
That's 52.4ms for all 4 digits, which is a 20hz refresh rate. Way too slow.

If you want to make it go faster, you have to load something in the Timer. As it is, it's just free-running.

Also, you'll never get those SERIN/OUT2's to work. They are timed by software, which gets continuously interrupted. You need to use the USART with HSERIN/OUT.

And, ENABLE/DISABLE are for ON INTERRUPT. They have no effect with Instant Interrupts.
<br>

itelmex
- 3rd September 2008, 00:57
Darrel, thanks. before your instant interrups tools never I was experimenting interrupts.

I have clear idea the hserin/hserout sustitution, but I ignored what's the procedure (concretly) for incress the speed.

I havew the display working now, but I need to find de solution for the slow scan.

The question is How incress the speed with the preescaler 1:1 now?

what's the value for load?

Thanks and regards

Luis Elizarraraz

Darrel Taylor
- 3rd September 2008, 01:33
The question is How incress the speed with the preescaler 1:1 now?

what's the value for load?
You should have at least 100hz refresh rate, or 400hz interrupts (4 digits).


DEFINE Freq 400
DEFINE Prescaler 1
Timer1 VAR WORD EXT
TmrLoad CON EXT
@Timer1 = TMR1L
@TmrLoad = 65536 - (OSC*1000000/4/Prescaler/Freq)

Then, first thing in the handler...
T1CON.0 = 0
Timer1 = Timer1 + TmrLoad
T1CON.0 = 1

itelmex
- 3rd September 2008, 02:41
Darrel:

Thanks for the solution!

For finish this project, I'm going to show the final version for the code.

Recapitulation:

Hardware:

Four 7 segments modules conected to the portb, like driver using uln2803.

Each module is conected to the anode with 2 transistors: bc337 directed to portd (portd.4 to portd.7 for each module) and from the bc337 colector to the irf640 gate.

For the communication, max232 connected to the pc (data inputs) and the ttl side, to the portc.6 and portc.7 (tx and rx).

I send to the pc the characters "C>" like invitation for to introduce the data.

The data follow the format: "CXXXX" where XXXX is any number from 0000 to 9999.
When the circuit receive the data in the correct format, this send to the pc the character "L" (Listen).

The problems with the slow scan was solutioned with the Darrel Taylor instant interrups tools. I finded relative easy the first project using interrups..!Thanks and more thanks Darrel ¡

Finally, the code:


'-----------------------------------program picbasic pro /Darrel support-------------------
'
INCLUDE "MODEDEFS.BAS"

define loader_used 1
DEFINE OSC 20

DEFINE HSER_RCSTA 90h
DEFINE HSER_TXSTA 20h
DEFINE HSER_BAUD 9600
'DEFINE HSER_SPBRG 25

DEFINE Freq 400
DEFINE Prescaler 1
Timer1 VAR WORD EXT
TmrLoad CON EXT
@Timer1 = TMR1L
@TmrLoad = 65536 - (OSC*1000000/4/Prescaler/Freq)


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


' ** Declare the Variables **
LEDS Var Byte ' The amount of LEDs in the display
O_C Var Byte ' Used by the interrupt for time sharing
Counter Var byte ' General purpose counter
Del Var Word ' General purpose delay loop variable
del1 var word
D_Number Var word ' The number to display on the LEDS
DP Var Byte ' Position of the decimal point
Disp_Patt Var Byte ' Pattern to output to PortC
Num Var Byte[4] ' Array to hold each digits value

TRISD=%00001111 'portd.4 a portd.7 como salidas
TrisB=0 ' Make PortB and PortC outputs
PortC=0:PortB=0 ' Clear PortB and PortC
O_C=0 ' Clear the time share variable

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

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

PORTD=%11110000

Main:
hserout [13,"C>"]
hserin [dec4 D_Number]
SIGUE:
hserout ["L"]
Gosub Display ' Display the value
goto main

Display:
For LEDS=3 to 0 step -1 ' Loop for 4 digits (0-65535) ' Disable the interrupt while we calculate
Num[LEDS]=D_Number dig LEDS ' Extract the seperate digits into the array
If D_Number<10 and LEDS=1 then Num[LEDS]=10 ' Zero Suppression for the second digit
If D_Number<100 and LEDS=2 then Num[LEDS]=10 ' Zero Suppression for the Third digit
If D_Number<1000 and LEDS=3 then Num[LEDS]=10 ' Zero Suppression for the Third digit ' Re-enable the interrupt
Next
return
' INTERRUPT HANDLER
' Multiplexes the 4-digits
'
Multi:
T1CON.0 = 0
Timer1 = Timer1 + TmrLoad
T1CON.0 = 1

'sigue: ' 0 1 2 3 4 5 6 7 8 9 A B C E F G H I J L N 0 U b c d e f g h i n p q s o u Z
lookup Num[O_C],[63,6,91,79,102,109,125,39,127,111,119,127,57,121,1 13,125,118,6,30,56,55,63,62,124,88,94,123,113,111, 116,4,84,115,103,109,92,28,255],Disp_Patt
' Lookup Num[O_C],[192,249,164,176,153,146,130,248,128,144,255],Disp_Patt ' Decode the segments for the LED
' Process the first display (farthest right)
If O_C=0 then portd=%11011111
If O_C=1 then portd=%11101111
If O_C=2 then portd=%01111111
If O_C=3 then portd=%10111111
PortB=Disp_Patt ' Place the digit pattern on portC
O_C=O_C+1 ' Increment the time share counter
If O_C>=4 then O_C=0 ' If it reaches 3 or over then clear it
@ INT_RETURN ' Allow more interrupts
'-----------------------end --------------------------------------------------------

The display is working very good.

Regards.

Darrel Taylor
- 4th September 2008, 03:26
That looks much better.

It's nice to have someone that can take a little guidance, and make it work.

Thanks for the Code Example! http://www.picbasic.co.uk/forum/images/icons/icon14.gif

ozion
- 28th October 2008, 23:50
<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>

Thank you very much Darrel. Your excellent works have saved me lots of headache.

RYTECH
- 24th November 2008, 06:17
I realize i'm likely behind about 2 years on this one.. i've been trying to modify Mister E / Darrel's USBDEMO code so that it works with my existing setup (a vb app that aquires 8 bit a/d result from the chip over usb cdc com port and also relays it to a serially connected 16F767.

Can anyone make comment or point me to the appropriate thread discussing the DT INTS & Microchip bootloader on an 18F4550. I can't seem to get it going.. i'm doing a cdc device that otherwise works fine with the standard "usbservice" everywhere method.. so I know I don't have a hardware issue... basically what occurs with the new program is nothing. and stuff freezes too (Hyperterminal, my application) without getting any data (or so it seems).

The device i'm building (i'm not showing you it's a total hackjob - that works) is "self powered" (i think) It runs off either a Max756 or a 7805C output or USB power, which on my hackjob of a board, is selected with jumpers. I've been attempting to detect the state of the usb connection, with limited success.. which currently involves 1x 100k and 1x 10k resistors to ground and USBV+ (5v from the usb cable) meeting in the middle at PORTB.0 which i've named "USBCONNECTED".

Do I need the INTERRUPT_ORG defines, something else? I'd also like to implement a "SLEEP" command when the cable isnt connected, if anyone can tell me how to properly detect the cable and connection as this is a self powered device which will run off battery / solar power. I've done some research and have a working device but I think my newbish methods for doing things is limiting the speed and using more power than it needs to (logic draws about 60-120mA running full tilt while not connected to USB (no sleep)


Basically I suppose my question is what should I do in addition to this code in order to use Darrels Interrupt system and use the Microchip Bootloader.


The Instant Interrupts modified code, sorry for the long post:

RYTECH
- 24th November 2008, 06:18
'
' RCUSB ; Edited 'USBDEMO' from Steve and Darrel
' =======
'
' File name : RCUSBCOMM_INT.pbp
' Company : Rytech Computing
' Programmer : Steve Monfette, Darrel Taylor, Ryan Barrett
' Date : November 23, 2008
' Device : PIC18F4550 & 20MHZ crystal
'
'
' USB I/O
'
' Hardware:
' ---------
' ACTLED PORTB.1
' INTERNAL DEBUG LEDS PORTD.0-3
' 5v Logic A/D Monitor AN0 USB/Max756/7805 output
' Max756v AA/AAA input A/D Monitor AN1 5v max
' 12v voltage/4 divider A/D Monitor AN2 20v max 7805C input
' Max4172 LOAD A/D Monitor AN3 5A max
' Max4172 CHARGE A/D Monitor AN4 2A max
' USB Sense PORTB.0 USB Active High
' 20 MHZ crystal & all the usual USB stuff
' Internal button PORTB.4
'
'
'
' Pic Configuration
' =================
asm
__CONFIG _CONFIG1L, _PLLDIV_5_1L & _CPUDIV_OSC1_PLL2_1L & _USBDIV_2_1L
__CONFIG _CONFIG1H, _FOSC_HSPLL_HS_1H & _FCMEN_OFF_1H & _IESO_OFF_1H
__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
DEFINE LOADER_USED 1
DEFINE RESET_ORG 800h
Define ADC_BITS 8
Define ADC_CLOCK 3
Define ADC_SAMPLEUS 100

DEFINE CCP1_REG PORTC
DEFINE CCP1_BIT 2
DEFINE CCP2_REG PORTC
DEFINE CCP2_BIT 1
'
' Hardware configuration
' ======================
'
' I/O and PORTs
' -------------
PORTB = 0
PORTC = 0
PORTD = 0
PORTE = 0
TRISB = %00010001
TRISC = 0
TRISA = %11111111
TRISD = %00000000
TRISE = 0
'
' A/D converter
' -------------
ADCON0 = %00000001
ADCON1 = %00001000
ADCON2 = %00000111
'
' CCP/PWM
' -------
' CCP1CON = %00001100 ' CCP1, PWM mode
' CCP2CON = %00001100 ' CCP2, PWM mode
' PR2 = 249 ' 12khz PWM Freq
' T2CON = %00000101 ' TMR2 on, prescaler 1:4
'
' USB module
' ----------
' UCFG var byte EXT ' include UCFG register... Yeah Melabs didn't :o(
ucfg = %00010100 ' enable internal USB pull-up, Full speed USB

'
' Interrupt definition
' ====================
' USB interrupt used to keep USB connection alive
INCLUDE "DT_INTS-18.bas" ' Base Interrupt System

ASM
INT_LIST macro ; IntSource, Label, Type, ResetFlag?
INT_Handler USB_INT, _DoUSBService, ASM, yes
endm
INT_CREATE ; Creates the interrupt processor
endasm


'
' Variables & constants definition
' ================================
USBBufferSizeTX con 16 ' input
USBBufferSizeRX con 16 ' output
USBBufferCount Var Byte '
USBBufferIn var byte[16] ' store incomming USB data
USBBufferOut Var Byte[16] ' store outgoing USB data
DataToSend var byte[16] ' store ADCs & pushButton data to send to USB
usb_device_state var byte EXT
CONFIGURED_STATE CON EXT
String1 var byte[16] ' hold 'USB DEMO' string
string1[0]="R"
string1[1]="C"
string1[2]="U"
string1[3]="S"
string1[4]="B"
string1[5]="C"
string1[6]="O"
string1[7]="M"
String1[8]="M"
String1[9]="_"
String1[10]="V"
String1[11]="1"
string1[12]="a"
string1[13]=" "
string1[14]=" "
string1[15]=" "
adval Var Byte[8]
pwmduty var BYTE[4]
PKTSUM var byte
QUAL con 229
ACTLED var PORTB.1
spout var PORTB.7
DLED1 VAR PORTD.0
DLED2 VAR PORTD.1
DLED3 VAR PORTD.2
DLED4 VAR PORTD.3
USBCONNECTED var PORTB.0


' Constants definition
' ====================
GoDone var ADCON0.1 ' ADC conversion

'
' Macro(s) definition
' ===================
asm

SendUSB macro array
; Use to Copy an specific array to USBBufferOut AND send it
; to USB bus
variable i=0
while i<16
MOVE?BB (array+i),(_USBBufferOut+i)
i+=1
endw
L?CALL _DoUSBOut
endm
endasm

'
' Software/Hardware initialisation
' ================================
SwHwInit:
HIGH DLED1
Pause 490
LOW DLED1
Pause 500
HIGH DLED1
Pause 500
LOW DLED1
Pause 500
HIGH DLED1
Pause 500
LOW DLED1
Pause 500
HIGH DLED1
adval[0]= 0
adval[1]= 0
adval[2]= 0
adval[3]= 0
adval[4]= 0
adval[5]= 0
adval[6]= 0
adval[7]= 0
pwmduty[0]= 0
pwmduty[1]= 0
pwmduty[2]= 0
pwmduty[3]= 0
gosub DoUSBinit:
'
' Main program start
' ==================
Start:
'
' ------------------------------------------------------------
if (PORTB.4)!=0 then
@ SendUSB _String1
TOGGLE DLED2
endif
toggle actled
'GOSUB GetAD:
'GOSUB toLCD:
datatosend[0] = "A"
DataToSend[1] = "V"
DataToSend[2] = "B"
Datatosend[3] = adval[0]
Datatosend[4] = "C"
Datatosend[5] = adval[2]
Datatosend[6] = "D"
Datatosend[7] = adval[3]
Datatosend[8] = "E"
Datatosend[9] = adval[4]
DataToSend[10]= "F"
Datatosend[11]= "Z"
Datatosend[12]= "G"
Datatosend[13]= "Y"
Datatosend[14]= "Z"
Datatosend[15]= "Z"
@ SendUSB _DataToSend
gosub dousbin:
GOTO START:

'
' Subroutines area
' ================
'
'
DoUSBIn:
'
' Check and receive data from the USB bus
' =======================================
@ INT_DISABLE USB_INT
USBBufferCount = USBBufferSizeRX ' RX buffer size
USBService ' keep connection alive
USBIn 1, USBBufferin, USBBufferCount, Timeout ' read data, if available
Timeout: '
@ INT_ENABLE USB_INT
pwmduty[0] = USBBUFFERIN[0] ' output to PORTB
pwmduty[1] = USBBufferin[1]
pwmduty[2] = USBBufferIn[2]
pwmduty[3] = USBBufferIn[3]
return
'
'
'
DoUSBOut:
'
' Send data to the USB bus & Wait for USB interface to attach
' ================================================== =========
@ INT_DISABLE USB_INT
WaitPC: '
USBBufferCount = USBBufferSizeTX ' TX buffer size
USBService ' keep connection alive
USBOut 1, USBBufferOut, USBBufferCount, Waitpc ' if bus available, transmit data
@ INT_ENABLE USB_INT
return

;_________________________________________________ ____________________________

;_________________________________________________ __________________________________________________ ____
DoUSBinit:
pause 500
usbinit ' initialise USB...
repeat ' kick-start it
usbservice
until usb_device_state = CONFIGURED_STATE
@ INT_ENABLE USB_INT
return
;_________________________________________________ __________________________________________________ ____
DoUSBService:
usbservice
@ INT_RETURN
;_________________________________________________ __________________________________________________ ____
GetAD:
ADCON0=%00000001:Gosub GetSample:adval[0]=ADRESH 'get AN0 into adval[0] (7805 5v source voltage)
toggle actled
'ADCON0=%00001001:Gosub GetSample:adval[2]=ADRESH '12v Voltage -skip over AN1 (max756) get AN2 (12v battery source voltage divider output) into adval[2]
'toggle actled
'ADCON0=%00001101:Gosub GetSample:adval[3]=ADRESH ' 12v Current -AN3 into adval[3] (max4172 12v battery current out)
'toggle actled
'ADCON0=%00010001:Gosub GetSample:adval[4]=ADRESH 'AN4 into adval[4] (12v Input current)
RETURN
;_________________________________________________ __________________________________________________ ____
GetSample:
PAUSEUS 100
GoDone=1
While GoDone=1:Wend
Return
;_________________________________________________ __________________________________________________ ____
ToLCD:
SerOut2 spout,16468,[DEC3 QUAL,DEC3 adval[0],dec3 adval[2],Dec3 adval[3],dec3 pwmduty[0],dec3 pwmduty[1],dec3 pwmduty[2],DEC3 pwmduty[3],13,10]
RETURN

RYTECH
- 24th November 2008, 08:26
thought i'd post my setup:

MPASM 5.20
PBP 2.50b
MCS 3.0.0.5

Darrel Taylor
- 24th November 2008, 08:58
What!
You're trying to use a HID program with CDC?

Well, you can start by using endpoint 3.

Wouldn't be surprised if there are more problems though.
<br>

RYTECH
- 24th November 2008, 22:46
I wasnt aware that the interrupt system was specifically for HID devices... anyways i'm back to trying to make my code work... it's really annoying.. the device works as expected, until i try and aquire a/d and send a serout2 in my main loop.. then it's device not recognized.. i think my brain might explode soon.

RYTECH
- 24th November 2008, 22:47
ahh i see what ur saying darrel.. i' used your code which points to endpoint 1.. i'm going to try it changing it to 3

RYTECH
- 24th November 2008, 22:53
k i think your hint has moved the situation forward.. i'm now getting some output... :) thanks ... I know I know im a big noob

RYTECH
- 24th November 2008, 23:22
Just gotta figure out now why my adc is all over the place

Darrel Taylor
- 25th November 2008, 03:04
Are the A/D values all over the place? Or is it the received data at the VB program?

The way it was shown, you'll be sending and receiving a bunch of extra data by transferring the entire buffer, instead of just the data that needs to be used.

HID is packet based, CDC is more like standard serial.
You'll need to consider how many bytes were received, and look for "header" bytes or some other mechanism to sync up the data.

Everything won't just be at byte[x] in the buffer anymore.
<br>

RYTECH
- 25th November 2008, 08:40
Hi,

I have some mostly working code now using your interrupts thanks to your "hint" about the endpoints earlier...

I was reading another thread that was about "If plugged" - The solution works great monitoring SOFIF and IDLEIF registers - the main loop now does run when the cable is unplugged.

The only case that is still at issue for me is that the device doesnt go passed the "DoUSBinit" subroutine if it's powered on while not connected - which for me is a big deal because the device i'm building is going to be powered up at times with just the LCD i have connected. This LCD is managed by a 16F767 in another device which has some fans too and a light. it's all connected via cat5e cable for one way serial transmission from the 18F4550 via serout2 commands, and i give it 12v and GND each via 3 wires respectively which feed a 7805 and a couple transistors for pulsing the fan speed and light intensity, that all appears to work nicely)

So I guess the last thing to do before I glue everything together (lol) is to get the device to go to the main loop if usb cable is not plugged at initialization time (and have the usb still work after if its eventually plugged in while the device is running).

Anyone else have this "self-powered device" / usbinit kind of issues?

RYTECH
- 25th November 2008, 08:43
Darrel the "extra" data is for parsing strings that come in after my oncomm event in visual basic. I get the stuff in between the letters :) - I haven't successfully used "binarymode" in vb .. always stuck with text mode.

I use whats come in between "A" and "B" to fork the other data over to certain variables... there's probobly a much better way to do it... I've already seen instances where manipulating the strings in higher speed timers cause lockups and weird things happening.

But that's not really the right forum for that.. but i'm interested to resolve the issue with the "cable not in during usbinit on device initialization" issue.

RYTECH
- 25th November 2008, 08:50
Should i wire up an input to the USB V+ and monitor that in addition to the IDLEIF SOFIF registers? USB ---4.7k ----pic input --100k---GND?

Darrel Taylor
- 25th November 2008, 09:28
The only case that is still at issue for me is that the device doesnt go passed the "DoUSBinit" subroutine if it's powered on while not connectedYeah, when it's not connected, it'll never make it to the CONFIGURED_STATE.

Change the Init routine to this.
DoUSBinit:
pause 500
usbinit ; initialise USB...
USBSERVICE ; service it once
UIE = $7F ; enable USB interrupts
UEIE = $9F ; enable USB Error interrupts
@ INT_ENABLE USB_INT
return

RYTECH
- 25th November 2008, 10:08
Thanks Darrel that did it for me!

RYTECH
- 27th November 2008, 17:11
Does the USB operation of the 18F4550 have a direct effect on the A/D channels..? Let me explain why i ask....

Case a) when i power up my circuit the A/D values float - not 200 or 300 millivolts - which for my inexperience, hackjob craftsmanship, and source voltage reference would be acceptable, but sometimes, usually when i power up without the usb cable connected, the values float sometimes as much as 800 millivolts on my 12v line, i've metered the several points, there's no floating, so it's something to do with the IC's operation. I can usually correct the issue by plugging in the device and unplugging it. I'm stumped as to what exactly is going on... i'm wondering if this 800 millivolt swing has something to do with the pic enabling or disabling its internal pullups on the usb data lines. it seems to revolve around the state of the usb connectivity... when the problem is not present my readings are mostly acceptable, the caps and aquisition times seem to work ok.

wonder whats going on... i think i chose the wrong IC for my solar powered charge controller... I really like the usb connectivity, but the IC with only 1 power led and 1 led that flashes every so often (about 1/16 cycles through main) the circuit draws about 120 mA... is that around normal for not having any sleep cycle in main? I tried to activate the WDT to implement a sleep but it seems the USB bootloader (or something) doesnt like it, cause when i reset the chip after the WDT enable change the USB reports the device is not recognized....

RYTECH
- 27th November 2008, 17:13
so i guess i actually have 2 issues still, i cant sleep (neither can my device) and the A/D sometimes acts "wonky" depending on the state of the usb pluggedness.

Darrel Taylor
- 28th November 2008, 04:22
I've never tried to put a USB PIC to sleep.
But the datasheet has some warnings about putting the USB module in "Suspend" mode before going to sleep, and using the Resume bit to "wake-up" on USB activity.
See section 17.2

Could be tricky.

120ma sounds pretty high.
Try disabling the USB module and VUSB regulator and see if that's where it's comming from. The datasheet doesn't seem to list the current for the USB module.
<br>

ralfmayr
- 28th November 2008, 11:10
I tried to compile my application with Darrels interrups, i get the compiler errors:
Error[113] c:\pbp\pbppic18.lib 1200 : Symbol not previously defined(INT_ENTRY_H)
Error[113] c:\pbp\pbppic18.lib 1214 : Symbol not previously defined(INT_ENTRY_L)
Message[301] d:\embedded\......... test.asm : MESSAGE: (Temp variables exceeding T7)

Can someone help ???

Pic is a 18F6722

Darrel Taylor
- 28th November 2008, 13:34
For the first two, you probably haven't defined the interrupt sources or handlers.

See this page for an example.
http://darreltaylor.com/DT_INTS-18/hello.html

For the T7 warning, read this ...
http://www.picbasic.co.uk/forum/showpost.php?p=60190&postcount=348
<br>

ralfmayr
- 28th November 2008, 17:25
Hello Darrel,
thanks, it works now, but there are coming up some more problems:

When the timer makes 1 second tick, i call a subroutine which has several
serin2 and serout2 commands to read and set data from some other modules.
It seems to come to write and read errors (time out comes in the serin2 and serout2 commands).
Also reading and writing to the 12c bus with I2CREAD and I2CWRITE to
a display doesn't work any more correct.

I enabled tmr0, tmr1, rx1 and rx2

Regards,
Ralf

Darrel Taylor
- 28th November 2008, 18:25
If you've enable RX1_INT and RX2_INT, then what is the SERIN/OUT for?

Aren't you using the USARTS?
<br>

ralfmayr
- 29th November 2008, 10:27
Sure, i am using both uarts of the Pic, but i have one more serial port accessing
via serin/serout some more serial devices also (a eight devices bus). The status
and some controls of these eight modules accessed via serin/serout are
controlled by the two uarts to a rs232 and a ethernet board.

Darrel Taylor
- 29th November 2008, 11:31
Any type of software timed commands like SERIN/OUT, OWIN/OUT, PAUSE, PULSIN/OUT etc, will be disturbed by these types of Interrupts.

Since you have 4 different things interrupting, the software timing is getting messed up pretty bad.

If you only needed the transmit side, you could use ...

Tmr_tx-18
http://www.picbasic.co.uk/forum/showpost.php?p=53931&postcount=28

But it sounds like you need the RX side too.

With a need for 3 USART's, You may be out of luck.

ralfmayr
- 17th December 2008, 12:32
Hi Darrel,
it works now, but is very critical in timing.
I think about using 12c, but i did not find a good i2c slave routine.
I tested one in the past, but without success.... :-(
Did you test your interrupts as an i2c slave? Can you help on this?
Regards,
Ralf

Darrel Taylor
- 17th December 2008, 18:47
> Did you test your interrupts as an i2c slave?

I haven't, but Robert Soubie did.
http://www.astrosurf.com/soubie/pic_as_an_i2c_slave.htm
<br>

ralfmayr
- 17th December 2008, 18:53
I have his routine, writing seems to work but reading not... :-(

boroko
- 4th January 2009, 23:31
I'm trying to understand how to return to a specific place when coming out of a INT.

Specifically, when I receive a command serially and trip the RX_INT, I need to abort the current operation in the main body of the program and restart with the newly commanded mode.
I have looked at DT_INTS and other advise on interrupts, and still don't understand what I would need to change to get this to happen.
The code works otherwise and gathers the command from the serial line, its just that I have to wait for the current operation to complete for it to be recognized and acted upon.

The main code is driving patterns on 8 LEDS with SPWM_INT and it takes 10 or 20 seconds for it to get around to the place where it looks at the new mode. This also applies when I change the mode with a switch input. I have to wait until the operation is finished to get to the part where I look for the input.

I don't believe that I can just mess with the RetAddr variable in DT_INTS and have that work without other steps. If I have a GOTO in the ISR, then I would likely corrupt the RETURN. I could just sprinkle switch and comm checks all over the place looking for flags, but that seems mediocre. Any advise?

Thanks
Mark

Darrel Taylor
- 4th January 2009, 23:46
We were just talking about that last month.

This might help.
http://www.picbasic.co.uk/forum/showthread.php?t=10263
<br>

boroko
- 5th January 2009, 01:18
Thanks for the pointer.

I find myself trying to be more careful about how I name threads.

It seems that if you miss something when it comes by, it can be spotty when you try to find it again.
I have been putting effort into a systematic method to catalog the threads that I get the most from.

There is a wealth of info if I can get better at mining it.

Mark

sayzer
- 25th April 2009, 14:09
Hi DT,

When @ INT_DISABLE TMR0_INT command is used @4Mhz 16F628A, can you estimate how long does it take to process it and eventually disable it?

uS?


Thanks.

Darrel Taylor
- 25th April 2009, 16:14
Hi Sayzer,

For 14-bit chips,
It takes 1 instruction cycle to disable the interrupt and depending on what bank it's in at the time, it may take 1 or 2 instructions to change to the correct bank before disabling.

So @ 4mhz, it could take from 1 to 3 uS.

On 18F's, it's always just 1 instruction.
<br>

sayzer
- 27th April 2009, 07:30
Hi Sayzer,

For 14-bit chips,
It takes 1 instruction cycle to disable the interrupt and depending on what bank it's in at the time, it may take 1 or 2 instructions to change to the correct bank before disabling.

So @ 4mhz, it could take from 1 to 3 uS.

On 18F's, it's always just 1 instruction.
<br>



I assume your answer would be the same for other sources of interrupt (other then TMR0).
In any case, 3 uS is more then good enough for my case.

Thanks very much DT.

mister_e
- 4th May 2009, 20:34
Not sure if this have been covered, but however. I'm actually working with a PIC16F616, there's no interrupt on PORTB change on this one, but Interrupt on PORTA change, great Microchip ;)

From what i see, it is not included in DT_INTS-14, so here's one method to do so...

Open DT_INTS-14, and add the sections in Red


ASM
#define INT_INT INTCON,INTF ;-- INT External Interrupt
#define RBC_INT INTCON,RBIF ;-- RB Port Change Interrupt
#define RAC_INT INTCON,RAIF ;-- RA Port Change Interrupt
#define TMR0_INT INTCON,T0IF ;-- TMR0 Overflow Interrupt 16F
#define TMR1_INT PIR1,TMR1IF ;-- TMR1 Overflow Interrupt
#define TMR2_INT PIR1,TMR2IF ;-- TMR2 to PR2 Match Interrupt
#define TX_INT PIR1,TXIF ;-- USART Transmit Interrupt
#define RX_INT PIR1,RCIF ;-- USART Receive Interrupt
#define CMP_INT PIR2,CMIF ;-- Comparator Interrupt
#define EE_INT PIR2,EEIF ;-- EEPROM/FLASH Write Operation Interrupt
#define BUS_INT PIR2,BCLIF ;-- Bus Collision Interrupt
#define PSP_INT PIR1,PSPIF ;-- Parallel Slave Port Read/Write Interrupt
#define AD_INT PIR1,ADIF ;-- A/D Converter Interrupt
#define SSP_INT PIR1,SSPIF ;-- Master Synchronous Serial Port Interrupt
#define CCP1_INT PIR1,CCP1IF ;-- CCP1 Interrupt
#define CCP2_INT PIR2,CCP2IF ;-- CCP2 Interrupt

ENDASM

asm
INT_Source macro IFR, IFB, IER, IEB
if ((IflagReg == IFR) && (IflagBit == IFB))
list
INT_Flag_Reg = IFR
INT_Flag_Bit = IFB
INT_Enable_Reg = IER
INT_Enable_Bit = IEB
Found = YES
endif
; nolist
endm
endasm


asm
;-------------------------------------------------------------------------------
GetIntInfo macro IflagReg, IflagBit

Found = NO
; nolist
ifdef INTF ;----{ INT External Interrupt }----------------[INTCON, INTF]---
INT_Source INTCON, INTF, INTCON, INTE
endif
ifdef RBIF ;----{ RB Port Change Interrupt }--------------[INTCON, RBIF]---
INT_Source INTCON, RBIF, INTCON, RBIE
endif
ifdef RAIF ;----{ RA Port Change Interrupt }--------------[INTCON, RAIF]---
INT_Source INTCON, RAIF, INTCON, RAIE
endif
ifdef T0IF ;----{ TMR0 Overflow Interrupt }-------------[INTCON, TMR0IF]---
INT_Source INTCON, T0IF, INTCON, T0IE
endif
ifdef TMR1IF ;----{ TMR1 Overflow Interrupt }---------------[PIR1, TMR1IF]---
INT_Source PIR1, TMR1IF, PIE1, TMR1IE
endif
ifdef TMR2IF ;----{ TMR2 to PR2 Match Interrupt }-----------[PIR1, TMR2IF]---
INT_Source PIR1, TMR2IF, PIE1, TMR2IE
endif
ifdef TXIF ;----{ USART Transmit Interrupt }----------------[PIR1, TXIF]---
INT_Source PIR1, TXIF, PIE1, TXIE
endif
ifdef RCIF ;----{ USART Receive Interrupt }------------------[PIR1 RCIF]---
INT_Source PIR1, RCIF, PIE1, RCIE
endif
ifdef CMIF ;----{ Comparator Interrupt }--------------------[PIR2, CMIF]---
ifdef PIR2
INT_Source PIR2, CMIF, PIE2, CMIE
else
INT_Source PIR1, CMIF, PIE1, CMIE
endif
endif
ifdef EEIF ;---{ EEPROM/FLASH Write Operation Interrupt }---[PIR2, EEIF]---
ifdef PIR2
INT_Source PIR2, EEIF, PIE2, EEIE
else
INT_Source PIR1, EEIF, PIE1, EEIE
endif
endif
ifdef BCLIF ;----{ Bus Collision Interrupt }----------------[PIR2, BCLIF]---
INT_Source PIR2, BCLIF, PIE2, BCLIE
endif
ifdef PSPIF ;--{ Parallel Slave Port Read/Write Interrupt }--[PIR1, PSPIF]--
INT_Source PIR1, PSPIF, PIE1, PSPIE
endif
ifdef ADIF ;----{ A/D Converter Interrupt }------------------[PIR1, ADIF]---
INT_Source PIR1, ADIF, PIE1, ADIE
endif
ifdef SSPIF ;----{ Master Synchronous Serial Port Interrupt }--[PIR1, SSPIF]-
INT_Source PIR1, SSPIF, PIE1, SSPIE
endif
ifdef CCP1IF ;----{ CCP1 Interrupt }-------------------------[PIR1, CCP1IF]---
INT_Source PIR1, CCP1IF, PIE1, CCP1IE
endif
ifdef CCP2IF ;----{ CCP2 Interrupt Flag }--------------------[PIR2, CCP2IF]---
INT_Source PIR2, CCP2IF, PIE2, CCP2IE
endif

list
endm
list
ENDASM

Sure enough there's some other PIC with interrupt on PORTA change, I just never came across one... or maybe... but never used that feature yet ;)

HankMcSpank
- 19th May 2009, 13:01
Oops - double post....removed.

HankMcSpank
- 19th May 2009, 13:04
mister_e.... I'd like to get interupts working on my 16F690 ....I visited Darrel's website & on the very first example "Hello World", he shows the code along with a short schematic - the interupt is showing as being presented on port RBO (actually called RBO/INT on the diagram).

I have some (newbie!) questions...

Are Darrel's interput routines for a specific PIC?

I ask because my PIC 16F690 doesn't even have an RB0(!), therefore to my next question....

Is there a particular PIC pin I should be using for his routines to work.

My end goal is quite simple...I have an encoder wheel with 48 black stripes that I'm having one helluva job getting the polling right....I'd simply like to be able to use a PIC interupt for when each black stripe passes the photo transistor 'pickup' (to increment a PIC counter)

That said, for testing puproses I do need one more interupt ...this being for a magnetic switch (I've glued a magnet to the edge of the disc so I know when the wheel has turned once) to interupt once per rev, I can then make sure that the PIC 'saw' all the stripes for the past rev....so to my other question - is there normally just one INT pin that's useable for externally triggered interupts on a PIC (specifically a 16F690)

i'd dearly love to be able to use Darrel's simple routines...but I'm a little clueless wrt ensuring I'm connecting my incoming 'pulses' to the correct PIC 16F690 pins!

edit: Darrel has kindly replied to the earlier PM I sent him, telling me that I need to look for the pin marked 'INT'...which on my PIC 16F690 is apparently pin RA2 - tks Darrel!

Jumper
- 19th May 2009, 13:57
Hi,

If you have a T?CKI pin on your pic you can use that pin to check for black stripes. This is the pin for the external clock signal connected to the internal timer/counter. This way you can get an interupt every black stripe or every 2:nd or once per wheel rotation (or anything else more or less). This is all depending of what you preload the counter with. If you have a 8-bit counter and load FF into it, next clock pulse will overflow the counter and you will get an interupt. If you preload it with FF-(dec 48) it will overflow once every full rotation of the wheel.

If you just want to count the stripes preload it with 0 and off you go....

This way your PIC will do most of the counting by itself and giving you more instruction time for something more useful.

If you use the RA2/INT for the magnetic switch you can use RA5/T1CKI the external clock input for the stripes phototransistor

/me

HankMcSpank
- 19th May 2009, 15:34
Hi,

If you have a T?CKI pin on your pic you can use that pin to check for black stripes. This is the pin for the external clock signal connected to the internal timer/counter. This way you can get an interupt every black stripe or every 2:nd or once per wheel rotation (or anything else more or less). This is all depending of what you preload the counter with. If you have a 8-bit counter and load FF into it, next clock pulse will overflow the counter and you will get an interupt. If you preload it with FF-(dec 48) it will overflow once every full rotation of the wheel.

If you just want to count the stripes preload it with 0 and off you go....

This way your PIC will do most of the counting by itself and giving you more instruction time for something more useful.

If you use the RA2/INT for the magnetic switch you can use RA5/T1CKI the external clock input for the stripes phototransistor

/me

Thanks...there's some top tips there.

Just a thought here - is it even possible to get reliable results with mechanical switches & interupts?

By this I mean, a mechanical switch normally needs a debounce, else you'd get more than one interupt for every time the switch 'settled'? In my situation, it's importnat that there's just one 'trigger' for every revolution of the encoder wheel (so I can establish how many interupts/black stripes the PIC has counted over one rev)...if I used an interupt for the magnetic switch, there'd be a possibility of not just one interupt...but several in quick succession...which will cause a bit of 'fog' whilst trying to confirm that my wheel, circuit & PIC are all in sync & counting 48 stripes per turn!

By the way...I've now dabbled with Darrel's "Hello World" which will suit my encoder wheel needs perfectly....after wrestling with 'pin' polling for weeks with my encoder wheel & getting very erratic results, I'm one very happy McSpank here today! October 05, 2002 maybe was a good day...but I can say without any shadow of a doubt, for me the 19 May 2009 was a lot better :D !!

Just a couple of small suggestions for Darrel's website (to save avoid a lot of newbie-esque puzzlement) - on Darrel's very first hello world code page, it might be worth saying that a user will need to establish their own PIC variant's 'INT' pin, along with perhaps a couple of PIC specific examples. (it might be ovbious to you old hands, but looking at the plethora of pins PICs have, it wasn't obvious to me!)

Also, for what it's worth...the 16F690 is perhaps the most common chip that newbies come into contact with at the moment (on account it's bundled with Microchip's very popular PikKit2 starter kit)...I had a problem with Darrel's "Hello World" code when I first compiled ...."error: variable wsave3 position request 416 beyond ram_end 367.", ultimately meaning a line in Darrel's DT_INTS-14.bas file needed commenting out - that might also be worth a mention too? (or at least some mention on a FAQ page?)

Anyway, a hearty thanks to Darrel... without his effort towards making interupts easy with PICBasic , I'm sure I would have left interupts for another day (ie sometime in 2023!)

jchandir
- 31st May 2009, 00:37
I am using a 16f866 with your instant interrupt but I cannot get it to wake up from sleep using a USART RX int.. If i use a Pause 1 in the main loop it works fine but I would really like for it to go to sleep and just wait. Please let me know what I am doing wrong.. here is the code.. Thank you Darrel for the awesome instant interrupt routines.



Define OSC 8

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

' Set receive register to receiver enabled
DEFINE HSER_RCSTA 90h

' Set transmit register to transmitter enabled
DEFINE HSER_TXSTA 20h

' Set baud rate
DEFINE HSER_BAUD 2400

x var byte
OSCCON=%01111000

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

@ INT_ENABLE RX_INT

Main:
@sleep
@nop
GOTO Main

'---[RX-Int - interrupt handler]--------------------------------------------------
ToggleLED1:
hserin [x]
hserout ["Hello"]
@ INT_RETURN

Darrel Taylor
- 31st May 2009, 02:43
I assume you meant 16F886?

From the datasheet...
During Sleep mode, all clocks to the EUSART are
suspended. Because of this, the Baud Rate Generator
is inactive and a proper character reception cannot be
performed.

You can use the AUTO-WAKE-UP ON BREAK feature of the EUSART, but there are several things to consider.

Take a look at section 12.3.2 AUTO-WAKE-UP ON BREAK (http://ww1.microchip.com/downloads/en/DeviceDoc/41291F.pdf)
<br>

jchandir
- 31st May 2009, 18:24
shoot.. i meant 16f688... sorry about my careless mistake.

jchandir
- 31st May 2009, 19:27
ok so i solved the problem. thanks Darrel. I just had to set the BAUDCTL.1 (WUE) bit.

Darrel Taylor
- 31st May 2009, 22:55
I'm not sure if you read the whole 3 pages worth of information on Auto-wake-up on break, but it'll take a little more than flipping a bit.

The transmit side needs to send the right character (0), or a Break sequence, to wake-up the PIC or you will loose at least the first character and get a framing err (FERR), and possibly a buffer overflow (OERR).

The second character can also be lost if time is not allowed for the oscillator to stabilize.
<br>

wbubel
- 31st July 2009, 18:19
where can I get a copy of ReEnterPBP.bas so I can test interupts?

Darrel Taylor
- 31st July 2009, 19:10
It takes more than ReEnterPBP.bas to do Instant Interrupts.

The first post in this thread tells where to get ALL the files.
<br>

wbubel
- 31st July 2009, 20:03
Hello dave
Ok, I found all my files I need however I am using PicBasic Pro Compiler Ver. 2.46. (I'm one of those poor saps that lost his receipt and cannot upgrade.)
When I compile it works but trying to build using MPLAB I get a masive amount of errors. Here is the code.

************************************************** **************
'* Name : UNTITLED.BAS *
'* Author : Bill Bubel *
' *
'* Date : 7/31/2009 *
'* Version : 1.0 *
'* Notes : *
'* : *
'************************************************* ***************
; Initialize your hardware first.

INCLUDE "DT_INTS-18.bas" ' Base Interrupt System
INCLUDE "ReEnterPBP-18.bas" ' Include if using PBP interrupts
DEFINE OSC 4 'Define the Osc to 4 MHz

asm
bsf OSCCON, SCS1 ; 1x = Internal Block
bcf OSCCON, SCS0 ; 00 = Primary Oscillator (20Mhz?)
bsf OSCCON, IRCF2 ; 111=8000 110=4000 101=2000
bsf OSCCON, IRCF1 ; 100=1000 011=0500 010=0250
bcf OSCCON, IRCF0 ; 001=0125 000=0032
MSTABLE010 btfss OSCCON, IOFS
bra MSTABLE010 ; wait until Oscillator is stable
endasm
LED1 VAR PORTB.2
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 > 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
- 31st July 2009, 20:19
Hello dave
The name's Darrel.


however I am using PicBasic Pro Compiler Ver. 2.46. (I'm one of those poor saps that lost his receipt and cannot upgrade.)
It works fine with PBP 2.46


When I compile it works but trying to build using MPLAB I get a masive amount of errors.
Then don't use MPLAB if it works when you compile.
<br>

wbubel
- 31st July 2009, 20:30
The name's Darrel.


It works fine with PBP 2.46


Then don't use MPLAB if it works when you compile.
<br>

Sorry Darrel about calling you dave.

I can compile but not Build. I use a IDC2 with MPLAB to run the PIC 18F1220. I use Microcode studio to write code and compile it to create a .asm file for MPLAB to build.

mackrackit
- 31st July 2009, 21:10
Dave here :)

in MCS -view-program options-assembler tab. Check the box for using MPASM. The hex will be created when you compile with MCS.

You do not need to start MPLAB. MCS will start MPASM for you.

wbubel
- 31st July 2009, 21:21
Dave here :)

in MCS -view-program options-assembler tab. Check the box for using MPASM. The hex will be created when you compile with MCS.

You do not need to start MPLAB. MCS will start MPASM for you.

Dave
I am using MPASM.


; Initialize your hardware first.

INCLUDE "DT_INTS-18.bas" ' Base Interrupt System
INCLUDE "ReEnterPBP-18.bas" ' Include if using PBP interrupts
DEFINE OSC 4 'Define the Osc to 4 MHz

asm
bsf OSCCON, SCS1 ; 1x = Internal Block
bcf OSCCON, SCS0 ; 00 = Primary Oscillator (20Mhz?)
bsf OSCCON, IRCF2 ; 111=8000 110=4000 101=2000
bsf OSCCON, IRCF1 ; 100=1000 011=0500 010=0250
bcf OSCCON, IRCF0 ; 001=0125 000=0032
MSTABLE010 btfss OSCCON, IOFS
bra MSTABLE010 ; wait until Oscillator is stable
endasm
LED1 VAR PORTB.2
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 > 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

This code produces errors when I attempt to Build

wbubel
- 31st July 2009, 21:47
Here is the errors I get


Clean: Deleting intermediary and output files.
Clean: Deleted file "C:\Pic Programs\Blink i.mcs".
Clean: Done.
Executing: "C:\Program Files\Microchip\MPASM Suite\MPAsmWin.exe" /q /p18F1220 "Blink i.asm" /l"Blink i.lst" /e"Blink i.err"
Warning[230] C:\PBP\18F1220.INC 20 : __CONFIG has been deprecated for PIC18 devices. Use directive CONFIG.
Warning[230] C:\PBP\18F1220.INC 21 : __CONFIG has been deprecated for PIC18 devices. Use directive CONFIG.
Warning[230] C:\PBP\18F1220.INC 22 : __CONFIG has been deprecated for PIC18 devices. Use directive CONFIG.
Warning[230] C:\PBP\18F1220.INC 23 : __CONFIG has been deprecated for PIC18 devices. Use directive CONFIG.
Error[105] C:\PIC PROGRAMS\BLINK I.ASM 204 : Cannot open file (Include File "BLINKI~2.MAC" not found)
Warning[207] C:\PIC PROGRAMS\BLINK I.ASM 219 : Found label after column 1. (DDISABLE?)
Warning[207] C:\PIC PROGRAMS\BLINK I.ASM 227 : Found label after column 1. (GOTO?L)
Error[122] C:\PIC PROGRAMS\BLINK I.ASM 227 : Illegal opcode (_OVER_DT_INTS_18)
Warning[207] C:\PIC PROGRAMS\BLINK I.ASM 231 : Found label after column 1. (ASM?)
Warning[207] C:\PIC PROGRAMS\BLINK I.ASM 369 : Found label after column 1. (ENDASM?)
Warning[207] C:\PIC PROGRAMS\BLINK I.ASM 374 : Found label after column 1. (ASM?)
Warning[207] C:\PIC PROGRAMS\BLINK I.ASM 392 : Found label after column 1. (ENDASM?)
Warning[207] C:\PIC PROGRAMS\BLINK I.ASM 397 : Found label after column 1. (ASM?)
Warning[207] C:\PIC PROGRAMS\BLINK I.ASM 696 : Found label after column 1. (ENDASM?)
Warning[207] C:\PIC PROGRAMS\BLINK I.ASM 701 : Found label after column 1. (ASM?)
Warning[207] C:\PIC PROGRAMS\BLINK I.ASM 714 : Found label after column 1. (ENDASM?)
Error[116] C:\PIC PROGRAMS\BLINK I.ASM 714 : Address label duplicated or different in second pass (ENDASM?)
Warning[207] C:\PIC PROGRAMS\BLINK I.ASM 719 : Found label after column 1. (ASM?)
Error[116] C:\PIC PROGRAMS\BLINK I.ASM 719 : Address label duplicated or different in second pass (ASM?)
Warning[207] C:\PIC PROGRAMS\BLINK I.ASM 758 : Found label after column 1. (ENDASM?)
Error[116] C:\PIC PROGRAMS\BLINK I.ASM 758 : Address label duplicated or different in second pass (ENDASM?)
Warning[207] C:\PIC PROGRAMS\BLINK I.ASM 763 : Found label after column 1. (ASM?)
Error[116] C:\PIC PROGRAMS\BLINK I.ASM 763 : Address label duplicated or different in second pass (ASM?)
Warning[207] C:\PIC PROGRAMS\BLINK I.ASM 782 : Found label after column 1. (ENDASM?)
Error[116] C:\PIC PROGRAMS\BLINK I.ASM 782 : Address label duplicated or different in second pass (ENDASM?)
Warning[207] C:\PIC PROGRAMS\BLINK I.ASM 787 : Found label after column 1. (ASM?)
Error[116] C:\PIC PROGRAMS\BLINK I.ASM 787 : Address label duplicated or different in second pass (ASM?)
Warning[207] C:\PIC PROGRAMS\BLINK I.ASM 793 : Found label after column 1. (ENDASM?)
Error[116] C:\PIC PROGRAMS\BLINK I.ASM 793 : Address label duplicated or different in second pass (ENDASM?)
Warning[207] C:\PIC PROGRAMS\BLINK I.ASM 798 : Found label after column 1. (ASM?)
Error[116] C:\PIC PROGRAMS\BLINK I.ASM 798 : Address label duplicated or different in second pass (ASM?)
Warning[207] C:\PIC PROGRAMS\BLINK I.ASM 852 : Found label after column 1. (ENDASM?)
Error[116] C:\PIC PROGRAMS\BLINK I.ASM 852 : Address label duplicated or different in second pass (ENDASM?)
Warning[207] C:\PIC PROGRAMS\BLINK I.ASM 857 : Found label after column 1. (ASM?)
Error[116] C:\PIC PROGRAMS\BLINK I.ASM 857 : Address label duplicated or different in second pass (ASM?)
Warning[207] C:\PIC PROGRAMS\BLINK I.ASM 914 : Found label after column 1. (ENDASM?)
Error[116] C:\PIC PROGRAMS\BLINK I.ASM 914 : Address label duplicated or different in second pass (ENDASM?)
Warning[207] C:\PIC PROGRAMS\BLINK I.ASM 919 : Found label after column 1. (ASM?)
Error[116] C:\PIC PROGRAMS\BLINK I.ASM 919 : Address label duplicated or different in second pass (ASM?)
Warning[207] C:\PIC PROGRAMS\BLINK I.ASM 969 : Found label after column 1. (ENDASM?)
Error[116] C:\PIC PROGRAMS\BLINK I.ASM 969 : Address label duplicated or different in second pass (ENDASM?)
Warning[207] C:\PIC PROGRAMS\BLINK I.ASM 974 : Found label after column 1. (ASM?)
Error[116] C:\PIC PROGRAMS\BLINK I.ASM 974 : Address label duplicated or different in second pass (ASM?)
Warning[207] C:\PIC PROGRAMS\BLINK I.ASM 1044 : Found label after column 1. (ENDASM?)
Error[116] C:\PIC PROGRAMS\BLINK I.ASM 1044 : Address label duplicated or different in second pass (ENDASM?)
Warning[207] C:\PIC PROGRAMS\BLINK I.ASM 1049 : Found label after column 1. (ASM?)
Error[116] C:\PIC PROGRAMS\BLINK I.ASM 1049 : Address label duplicated or different in second pass (ASM?)
Warning[207] C:\PIC PROGRAMS\BLINK I.ASM 1126 : Found label after column 1. (ENDASM?)
Error[116] C:\PIC PROGRAMS\BLINK I.ASM 1126 : Address label duplicated or different in second pass (ENDASM?)
Warning[207] C:\PIC PROGRAMS\BLINK I.ASM 1131 : Found label after column 1. (ASM?)
Error[116] C:\PIC PROGRAMS\BLINK I.ASM 1131 : Address label duplicated or different in second pass (ASM?)
Warning[207] C:\PIC PROGRAMS\BLINK I.ASM 1224 : Found label after column 1. (ENDASM?)
Error[116] C:\PIC PROGRAMS\BLINK I.ASM 1224 : Address label duplicated or different in second pass (ENDASM?)
Warning[207] C:\PIC PROGRAMS\BLINK I.ASM 1229 : Found label after column 1. (LABEL?L)
Error[122] C:\PIC PROGRAMS\BLINK I.ASM 1229 : Illegal opcode (_OVER_DT_INTS_18)
Warning[207] C:\PIC PROGRAMS\BLINK I.ASM 1232 : Found label after column 1. (DENABLE?)
Warning[207] C:\PIC PROGRAMS\BLINK I.ASM 1237 : Found label after column 1. (DDISABLE?)
Error[116] C:\PIC PROGRAMS\BLINK I.ASM 1237 : Address label duplicated or different in second pass (DDISABLE?)
Warning[207] C:\PIC PROGRAMS\BLINK I.ASM 1244 : Found label after column 1. (GOTO?L)
Error[122] C:\PIC PROGRAMS\BLINK I.ASM 1244 : Illegal opcode (_OverReEnterH)
Warning[207] C:\PIC PROGRAMS\BLINK I.ASM 1248 : Found label after column 1. (LABEL?L)
Error[122] C:\PIC PROGRAMS\BLINK I.ASM 1248 : Illegal opcode (_SavePBP_H)
Warning[207] C:\PIC PROGRAMS\BLINK I.ASM 1251 : Found label after column 1. (CMPNE?TCL)
Error[122] C:\PIC PROGRAMS\BLINK I.ASM 1251 : Illegal opcode (PB01)
Warning[207] C:\PIC PROGRAMS\BLINK I.ASM 1267 : Found label after column 1. (ASM?)
Error[116] C:\PIC PROGRAMS\BLINK I.ASM 1267 : Address label duplicated or different in second pass (ASM?)
Warning[207] C:\PIC PROGRAMS\BLINK I.ASM 1277 : Found label after column 1. (ENDASM?)
Error[116] C:\PIC PROGRAMS\BLINK I.ASM 1277 : Address label duplicated or different in second pass (ENDASM?)
Warning[207] C:\PIC PROGRAMS\BLINK I.ASM 1315 : Found label after column 1. (ASM?)
Error[116] C:\PIC PROGRAMS\BLINK I.ASM 1315 : Address label duplicated or different in second pass (ASM?)
Warning[207] C:\PIC PROGRAMS\BLINK I.ASM 1335 : Found label after column 1. (ENDASM?)
Error[116] C:\PIC PROGRAMS\BLINK I.ASM 1335 : Address label duplicated or different in second pass (ENDASM?)
Warning[207] C:\PIC PROGRAMS\BLINK I.ASM 1340 : Found label after column 1. (ASM?)
Error[116] C:\PIC PROGRAMS\BLINK I.ASM 1340 : Address label duplicated or different in second pass (ASM?)
Warning[207] C:\PIC PROGRAMS\BLINK I.ASM 1395 : Found label after column 1. (ENDASM?)
Error[116] C:\PIC PROGRAMS\BLINK I.ASM 1395 : Address label duplicated or different in second pass (ENDASM?)
Warning[207] C:\PIC PROGRAMS\BLINK I.ASM 1402 : Found label after column 1. (LABEL?L)
Error[122] C:\PIC PROGRAMS\BLINK I.ASM 1402 : Illegal opcode (L00001)
Warning[207] C:\PIC PROGRAMS\BLINK I.ASM 1406 : Found label after column 1. (ASM?)
Error[116] C:\PIC PROGRAMS\BLINK I.ASM 1406 : Address label duplicated or different in second pass (ASM?)
Warning[207] C:\PIC PROGRAMS\BLINK I.ASM 1409 : Found label after column 1. (ENDASM?)
Error[116] C:\PIC PROGRAMS\BLINK I.ASM 1409 : Address label duplicated or different in second pass (ENDASM?)
Warning[207] C:\PIC PROGRAMS\BLINK I.ASM 1414 : Found label after column 1. (LABEL?L)
Error[122] C:\PIC PROGRAMS\BLINK I.ASM 1414 : Illegal opcode (_RestorePBP_H)
Warning[207] C:\PIC PROGRAMS\BLINK I.ASM 1417 : Found label after column 1. (CMPNE?TCL)
Error[122] C:\PIC PROGRAMS\BLINK I.ASM 1417 : Illegal opcode (PB01)
Warning[207] C:\PIC PROGRAMS\BLINK I.ASM 1433 : Found label after column 1. (ASM?)
Error[116] C:\PIC PROGRAMS\BLINK I.ASM 1433 : Address label duplicated or different in second pass (ASM?)
Warning[207] C:\PIC PROGRAMS\BLINK I.ASM 1443 : Found label after column 1. (ENDASM?)
Error[116] C:\PIC PROGRAMS\BLINK I.ASM 1443 : Address label duplicated or different in second pass (ENDASM?)
Warning[207] C:\PIC PROGRAMS\BLINK I.ASM 1481 : Found label after column 1. (ASM?)
Error[116] C:\PIC PROGRAMS\BLINK I.ASM 1481 : Address label duplicated or different in second pass (ASM?)
Warning[207] C:\PIC PROGRAMS\BLINK I.ASM 1501 : Found label after column 1. (ENDASM?)

(rest of errors deleted)
Halting build on first failure as requested.
BUILD FAILED: Fri Jul 31 16:45:07 2009

mackrackit
- 31st July 2009, 21:51
OK, so you have MCS set up to use MPASM. You are not using MPLAB.

Can you post your current config settings? Copy the Inc file. And can you post all of the errors you ar getting?

I may have missed something before.

mackrackit
- 31st July 2009, 21:55
I do not really like the way you are doing the configs.
Have you read this?
http://www.picbasic.co.uk/forum/showthread.php?t=543
if you set the configs in your program you will need to comment out the correct lines in the Inc.

wbubel
- 3rd August 2009, 13:19
OK, so you have MCS set up to use MPASM. You are not using MPLAB.

Can you post your current config settings? Copy the Inc file. And can you post all of the errors you ar getting?

I may have missed something before.

I am using MPLAB for Building

Here is a copy of the config file



;************************************************* ***************
;* 18F1220.INC *
;* *
;* By : Leonard Zerman, Jeff Schmoyer *
;* Notice : Copyright (c) 2004 microEngineering Labs, Inc. *
;* All Rights Reserved *
;* Date : 01/27/04 *
;* Version : 2.45 *
;* Notes : *
;************************************************* ***************
NOLIST
ifdef PM_USED
LIST
"Error: PM does not support this device. Use MPASM."
NOLIST
else
LIST
LIST p = 18F1220, r = dec, w = -311, f = inhx32
INCLUDE "P18F1220.INC" ; MPASM Header
__CONFIG _CONFIG1H, _IESO_OFF_1H & _FSCM_OFF_1H & _INTIO2_OSC_1H
__CONFIG _CONFIG2H, _WDT_ON_2H & _WDTPS_128_2H
__CONFIG _CONFIG3H, _MCLRE_ON_3H
__CONFIG _CONFIG4L, _LVP_OFF_4L
NOLIST
endif
LIST
EEPROM_START EQU 0F00000h
BLOCK_SIZE EQU 8

wbubel
- 3rd August 2009, 14:16
Here is the rest of the errors


Error[116] C:\PIC PROGRAMS\BLINK I.ASM 1501 : Address label duplicated or different in second pass (ENDASM?)
Warning[207] C:\PIC PROGRAMS\BLINK I.ASM 1506 : Found label after column 1. (ASM?)
Error[116] C:\PIC PROGRAMS\BLINK I.ASM 1506 : Address label duplicated or different in second pass (ASM?)
Warning[207] C:\PIC PROGRAMS\BLINK I.ASM 1566 : Found label after column 1. (ENDASM?)
Error[116] C:\PIC PROGRAMS\BLINK I.ASM 1566 : Address label duplicated or different in second pass (ENDASM?)
Warning[207] C:\PIC PROGRAMS\BLINK I.ASM 1573 : Found label after column 1. (LABEL?L)
Error[122] C:\PIC PROGRAMS\BLINK I.ASM 1573 : Illegal opcode (L00003)
Warning[207] C:\PIC PROGRAMS\BLINK I.ASM 1577 : Found label after column 1. (ASM?)
Error[116] C:\PIC PROGRAMS\BLINK I.ASM 1577 : Address label duplicated or different in second pass (ASM?)
Warning[207] C:\PIC PROGRAMS\BLINK I.ASM 1580 : Found label after column 1. (ENDASM?)
Error[116] C:\PIC PROGRAMS\BLINK I.ASM 1580 : Address label duplicated or different in second pass (ENDASM?)
Warning[207] C:\PIC PROGRAMS\BLINK I.ASM 1585 : Found label after column 1. (LABEL?L)
Error[122] C:\PIC PROGRAMS\BLINK I.ASM 1585 : Illegal opcode (_OverReEnterH)
Warning[207] C:\PIC PROGRAMS\BLINK I.ASM 1588 : Found label after column 1. (DENABLE?)
Error[116] C:\PIC PROGRAMS\BLINK I.ASM 1588 : Address label duplicated or different in second pass (DENABLE?)
Warning[207] C:\PIC PROGRAMS\BLINK I.ASM 1593 : Found label after column 1. (ASM?)
Error[116] C:\PIC PROGRAMS\BLINK I.ASM 1593 : Address label duplicated or different in second pass (ASM?)
Warning[207] C:\PIC PROGRAMS\BLINK I.ASM 1604 : Found label after column 1. (ENDASM?)
Error[116] C:\PIC PROGRAMS\BLINK I.ASM 1604 : Address label duplicated or different in second pass (ENDASM?)
Warning[207] C:\PIC PROGRAMS\BLINK I.ASM 1610 : Found label after column 1. (ASM?)
Error[116] C:\PIC PROGRAMS\BLINK I.ASM 1610 : Address label duplicated or different in second pass (ASM?)
Warning[207] C:\PIC PROGRAMS\BLINK I.ASM 508 : Found label after column 1. (ENDASM?)
Error[116] C:\PIC PROGRAMS\BLINK I.ASM 508 : Address label duplicated or different in second pass (ENDASM?)
Warning[207] C:\PIC PROGRAMS\BLINK I.ASM 513 : Found label after column 1. (ASM?)
Error[116] C:\PIC PROGRAMS\BLINK I.ASM 513 : Address label duplicated or different in second pass (ASM?)
Warning[207] C:\PIC PROGRAMS\BLINK I.ASM 570 : Found label after column 1. (ENDASM?)
Error[116] C:\PIC PROGRAMS\BLINK I.ASM 570 : Address label duplicated or different in second pass (ENDASM?)
Warning[207] C:\PIC PROGRAMS\BLINK I.ASM 575 : Found label after column 1. (ASM?)
Error[116] C:\PIC PROGRAMS\BLINK I.ASM 575 : Address label duplicated or different in second pass (ASM?)
Warning[207] C:\PIC PROGRAMS\BLINK I.ASM 622 : Found label after column 1. (ENDASM?)
Error[116] C:\PIC PROGRAMS\BLINK I.ASM 622 : Address label duplicated or different in second pass (ENDASM?)
Warning[207] C:\PIC PROGRAMS\BLINK I.ASM 627 : Found label after column 1. (ASM?)
Error[116] C:\PIC PROGRAMS\BLINK I.ASM 627 : Address label duplicated or different in second pass (ASM?)
Warning[207] C:\PIC PROGRAMS\BLINK I.ASM 652 : Found label after column 1. (ENDASM?)
Error[116] C:\PIC PROGRAMS\BLINK I.ASM 652 : Address label duplicated or different in second pass (ENDASM?)
Warning[207] C:\PIC PROGRAMS\BLINK I.ASM 657 : Found label after column 1. (ASM?)
Error[116] C:\PIC PROGRAMS\BLINK I.ASM 657 : Address label duplicated or different in second pass (ASM?)
Error[113] C:\PBP\PBPPIC18.LIB 703 : Symbol not previously defined (_SavePBP_H)
Error[113] C:\PBP\PBPPIC18.LIB 713 : Symbol not previously defined (_SavePBP_H)
Error[113] C:\PBP\PBPPIC18.LIB 714 : Symbol not previously defined (_SavePBP_H)
Error[113] C:\PBP\PBPPIC18.LIB 703 : Symbol not previously defined (_ToggleLED1)
Error[113] C:\PBP\PBPPIC18.LIB 713 : Symbol not previously defined (_ToggleLED1)
Error[113] C:\PBP\PBPPIC18.LIB 714 : Symbol not previously defined (_ToggleLED1)
Error[113] C:\PBP\PBPPIC18.LIB 703 : Symbol not previously defined (_RestorePBP_H)
Error[113] C:\PBP\PBPPIC18.LIB 713 : Symbol not previously defined (_RestorePBP_H)
Error[113] C:\PBP\PBPPIC18.LIB 714 : Symbol not previously defined (_RestorePBP_H)
Warning[207] C:\PIC PROGRAMS\BLINK I.ASM 1618 : Found label after column 1. (ENDASM?)
Error[116] C:\PIC PROGRAMS\BLINK I.ASM 1618 : Address label duplicated or different in second pass (ENDASM?)
Warning[207] C:\PIC PROGRAMS\BLINK I.ASM 1626 : Found label after column 1. (ASM?)
Error[116] C:\PIC PROGRAMS\BLINK I.ASM 1626 : Address label duplicated or different in second pass (ASM?)
Warning[207] C:\PIC PROGRAMS\BLINK I.ASM 508 : Found label after column 1. (ENDASM?)
Error[116] C:\PIC PROGRAMS\BLINK I.ASM 508 : Address label duplicated or different in second pass (ENDASM?)
Warning[207] C:\PIC PROGRAMS\BLINK I.ASM 513 : Found label after column 1. (ASM?)
Error[116] C:\PIC PROGRAMS\BLINK I.ASM 513 : Address label duplicated or different in second pass (ASM?)
Warning[207] C:\PIC PROGRAMS\BLINK I.ASM 570 : Found label after column 1. (ENDASM?)
Error[116] C:\PIC PROGRAMS\BLINK I.ASM 570 : Address label duplicated or different in second pass (ENDASM?)
Warning[207] C:\PIC PROGRAMS\BLINK I.ASM 575 : Found label after column 1. (ASM?)
Error[116] C:\PIC PROGRAMS\BLINK I.ASM 575 : Address label duplicated or different in second pass (ASM?)
Warning[207] C:\PIC PROGRAMS\BLINK I.ASM 622 : Found label after column 1. (ENDASM?)
Error[116] C:\PIC PROGRAMS\BLINK I.ASM 622 : Address label duplicated or different in second pass (ENDASM?)
Warning[207] C:\PIC PROGRAMS\BLINK I.ASM 627 : Found label after column 1. (ASM?)
Error[116] C:\PIC PROGRAMS\BLINK I.ASM 627 : Address label duplicated or different in second pass (ASM?)
Warning[207] C:\PIC PROGRAMS\BLINK I.ASM 652 : Found label after column 1. (ENDASM?)
Error[116] C:\PIC PROGRAMS\BLINK I.ASM 652 : Address label duplicated or different in second pass (ENDASM?)

wbubel
- 3rd August 2009, 14:17
Warning[207] C:\PIC PROGRAMS\BLINK I.ASM 657 : Found label after column 1. (ASM?)
Error[116] C:\PIC PROGRAMS\BLINK I.ASM 657 : Address label duplicated or different in second pass (ASM?)
Warning[207] C:\PIC PROGRAMS\BLINK I.ASM 1629 : Found label after column 1. (ENDASM?)
Error[116] C:\PIC PROGRAMS\BLINK I.ASM 1629 : Address label duplicated or different in second pass (ENDASM?)
Warning[207] C:\PIC PROGRAMS\BLINK I.ASM 1634 : Found label after column 1. (LABEL?L)
Error[122] C:\PIC PROGRAMS\BLINK I.ASM 1634 : Illegal opcode (_Main)
Warning[207] C:\PIC PROGRAMS\BLINK I.ASM 1638 : Found label after column 1. (LABEL?L)
Error[122] C:\PIC PROGRAMS\BLINK I.ASM 1638 : Illegal opcode (L00005)
Warning[207] C:\PIC PROGRAMS\BLINK I.ASM 1639 : Found label after column 1. (CMPGT?BCL)
Error[122] C:\PIC PROGRAMS\BLINK I.ASM 1639 : Illegal opcode (_DutyCycle)
Warning[207] C:\PIC PROGRAMS\BLINK I.ASM 1642 : Found label after column 1. (GOSUB?L)
Error[122] C:\PIC PROGRAMS\BLINK I.ASM 1642 : Illegal opcode (_SetDutyCycle)
Warning[207] C:\PIC PROGRAMS\BLINK I.ASM 1645 : Found label after column 1. (PAUSE?C)
Error[108] C:\PIC PROGRAMS\BLINK I.ASM 1645 : Illegal character (0)
Warning[207] C:\PIC PROGRAMS\BLINK I.ASM 1648 : Found label after column 1. (NEXT?BCL)
Error[122] C:\PIC PROGRAMS\BLINK I.ASM 1648 : Illegal opcode (_DutyCycle)
Warning[207] C:\PIC PROGRAMS\BLINK I.ASM 1649 : Found label after column 1. (LABEL?L)
Error[122] C:\PIC PROGRAMS\BLINK I.ASM 1649 : Illegal opcode (L00006)
Warning[207] C:\PIC PROGRAMS\BLINK I.ASM 1653 : Found label after column 1. (LABEL?L)
Error[122] C:\PIC PROGRAMS\BLINK I.ASM 1653 : Illegal opcode (L00007)
Warning[207] C:\PIC PROGRAMS\BLINK I.ASM 1654 : Found label after column 1. (CMPLT?BCL)
Error[122] C:\PIC PROGRAMS\BLINK I.ASM 1654 : Illegal opcode (_DutyCycle)
Warning[207] C:\PIC PROGRAMS\BLINK I.ASM 1657 : Found label after column 1. (GOSUB?L)
Error[122] C:\PIC PROGRAMS\BLINK I.ASM 1657 : Illegal opcode (_SetDutyCycle)
Warning[207] C:\PIC PROGRAMS\BLINK I.ASM 1660 : Found label after column 1. (PAUSE?C)
Error[108] C:\PIC PROGRAMS\BLINK I.ASM 1660 : Illegal character (0)
Warning[207] C:\PIC PROGRAMS\BLINK I.ASM 1663 : Found label after column 1. (NEXTM?BCL)
Error[122] C:\PIC PROGRAMS\BLINK I.ASM 1663 : Illegal opcode (_DutyCycle)
Warning[207] C:\PIC PROGRAMS\BLINK I.ASM 1664 : Found label after column 1. (LABEL?L)
Error[122] C:\PIC PROGRAMS\BLINK I.ASM 1664 : Illegal opcode (L00008)
Warning[207] C:\PIC PROGRAMS\BLINK I.ASM 1667 : Found label after column 1. (GOTO?L)
Error[122] C:\PIC PROGRAMS\BLINK I.ASM 1667 : Illegal opcode (_Main)
Warning[207] C:\PIC PROGRAMS\BLINK I.ASM 1671 : Found label after column 1. (LABEL?L)
Error[122] C:\PIC PROGRAMS\BLINK I.ASM 1671 : Illegal opcode (_SetDutyCycle)
Warning[207] C:\PIC PROGRAMS\BLINK I.ASM 1674 : Found label after column 1. (MULMID?CBW)
Error[122] C:\PIC PROGRAMS\BLINK I.ASM 1674 : Illegal opcode (_TotalCount)
Warning[207] C:\PIC PROGRAMS\BLINK I.ASM 1677 : Found label after column 1. (SUB?CWW)
Error[122] C:\PIC PROGRAMS\BLINK I.ASM 1677 : Illegal opcode (_TotalCount)
Warning[207] C:\PIC PROGRAMS\BLINK I.ASM 1680 : Found label after column 1. (CMPNE?BCL)
Error[122] C:\PIC PROGRAMS\BLINK I.ASM 1680 : Illegal opcode (_DutyCycle)
Warning[207] C:\PIC PROGRAMS\BLINK I.ASM 1686 : Found label after column 1. (LOW?T)
Error[122] C:\PIC PROGRAMS\BLINK I.ASM 1686 : Illegal opcode (PORTB)
Warning[207] C:\PIC PROGRAMS\BLINK I.ASM 1689 : Found label after column 1. (GOTO?L)
Error[122] C:\PIC PROGRAMS\BLINK I.ASM 1689 : Illegal opcode (L00010)
Warning[207] C:\PIC PROGRAMS\BLINK I.ASM 1690 : Found label after column 1. (LABEL?L)
Error[122] C:\PIC PROGRAMS\BLINK I.ASM 1690 : Illegal opcode (L00009)
Warning[207] C:\PIC PROGRAMS\BLINK I.ASM 1696 : Found label after column 1. (LABEL?L)
Error[122] C:\PIC PROGRAMS\BLINK I.ASM 1696 : Illegal opcode (L00010)
Warning[207] C:\PIC PROGRAMS\BLINK I.ASM 1699 : Found label after column 1. (RETURN?)
Warning[207] C:\PIC PROGRAMS\BLINK I.ASM 1702 : Found label after column 1. (DDISABLE?)
Error[116] C:\PIC PROGRAMS\BLINK I.ASM 1702 : Address label duplicated or different in second pass (DDISABLE?)
Warning[207] C:\PIC PROGRAMS\BLINK I.ASM 1706 : Found label after column 1. (ASM?)
Error[116] C:\PIC PROGRAMS\BLINK I.ASM 1706 : Address label duplicated or different in second pass (ASM?)
Warning[207] C:\PIC PROGRAMS\BLINK I.ASM 1709 : Found label after column 1. (ENDASM?)
Error[116] C:\PIC PROGRAMS\BLINK I.ASM 1709 : Address label duplicated or different in second pass (ENDASM?)
Warning[207] C:\PIC PROGRAMS\BLINK I.ASM 1714 : Found label after column 1. (LABEL?L)
Error[122] C:\PIC PROGRAMS\BLINK I.ASM 1714 : Illegal opcode (_ToggleLED1)
Warning[207] C:\PIC PROGRAMS\BLINK I.ASM 1717 : Found label after column 1. (CMPF?TL)
Error[122] C:\PIC PROGRAMS\BLINK I.ASM 1717 : Illegal opcode (PORTB)
Warning[207] C:\PIC PROGRAMS\BLINK I.ASM 1720 : Found label after column 1. (LOW?T)
Error[122] C:\PIC PROGRAMS\BLINK I.ASM 1720 : Illegal opcode (PORTB)
Warning[207] C:\PIC PROGRAMS\BLINK I.ASM 1732 : Found label after column 1. (GOTO?L)
Error[122] C:\PIC PROGRAMS\BLINK I.ASM 1732 : Illegal opcode (L00012)
Warning[207] C:\PIC PROGRAMS\BLINK I.ASM 1733 : Found label after column 1. (LABEL?L)
Error[122] C:\PIC PROGRAMS\BLINK I.ASM 1733 : Illegal opcode (L00011)
Warning[207] C:\PIC PROGRAMS\BLINK I.ASM 1736 : Found label after column 1. (HIGH?T)
Error[122] C:\PIC PROGRAMS\BLINK I.ASM 1736 : Illegal opcode (PORTB)
Warning[207] C:\PIC PROGRAMS\BLINK I.ASM 1748 : Found label after column 1. (LABEL?L)
Error[122] C:\PIC PROGRAMS\BLINK I.ASM 1748 : Illegal opcode (L00012)
Warning[207] C:\PIC PROGRAMS\BLINK I.ASM 1752 : Found label after column 1. (ASM?)
Error[116] C:\PIC PROGRAMS\BLINK I.ASM 1752 : Address label duplicated or different in second pass (ASM?)
Warning[207] C:\PIC PROGRAMS\BLINK I.ASM 1755 : Found label after column 1. (ENDASM?)
Error[116] C:\PIC PROGRAMS\BLINK I.ASM 1755 : Address label duplicated or different in second pass (ENDASM?)
Warning[207] C:\PIC PROGRAMS\BLINK I.ASM 1759 : Found label after column 1. (DENABLE?)
Error[116] C:\PIC PROGRAMS\BLINK I.ASM 1759 : Address label duplicated or different in second pass (DENABLE?)
Halting build on first failure as requested.
BUILD FAILED: Mon Aug 03 09:13:22 2009

Bruce
- 3rd August 2009, 14:29
When I compile it works but trying to build using MPLAB I get a masive amount of errors

Are you compiling from MCS, then importing the .asm file into MPLAB, and trying to
build it?

wbubel
- 3rd August 2009, 15:10
Are you compiling from MCS, then importing the .asm file into MPLAB, and trying to
build it?
Yes, that is the way I have always built .asm files. I never encounted errors to this magnatude before.

Bruce
- 3rd August 2009, 15:43
If you're using MPLAB with PBP just setup PBP as a language tool in MPLAB. There's no
reason to compile in MCS, then import the .asm produced and assemble it again.

Your PBP code has already been assembled, and the .HEX file has already been created.

If you have an old version of PBP that's not compatible with the version of MPLAB you have,
then upgrade PBP or download & install an older version of MPLAB.

Why are you compiling in MCS then trying to assemble it all again in MPLAB?

wbubel
- 3rd August 2009, 15:56
If you're using MPLAB with PBP just setup PBP as a language tool in MPLAB. There's no
reason to compile in MCS, then import the .asm produced and assemble it again.

Your PBP code has already been assembled, and the .HEX file has already been created.

If you have an old version of PBP that's not compatible with the version of MPLAB you have,
then upgrade PBP or download & install an older version of MPLAB.

Why are you compiling in MCS then trying to assemble it all again in MPLAB?

Just how do I do that in MPLAB? I tried looking and found nothing to make PBP the language tool?

Bruce
- 3rd August 2009, 16:01
See this page: http://melabs.com/support/mplab.htm

wbubel
- 5th August 2009, 20:52
Ok, I'm about to give up. Ive tried everything on Darrel's program that was suggested. I'm still getting the same Build errors as before. I'm using a 18F1220 Pic and MCS to compile with MPLAB to build. I tried to compile using MPLAB but it wont work. All other programs I've compiled and Built I had no problems. HELP

Bruce
- 5th August 2009, 21:12
What errors do you get when trying to compile from within MPLAB?

wbubel
- 5th August 2009, 21:26
What errors do you get when trying to compile from within MPLAB?

I've already posted them (See above Posts 410, 414, and 415 in this thread)

Bruce
- 5th August 2009, 21:50
You have PBP setup in MPLAB as the language tool as shown here: http://melabs.com/support/mplab.htm and you still get the same errors?

wbubel
- 5th August 2009, 21:56
You have PBP setup in MPLAB as the language tool as shown here: http://melabs.com/support/mplab.htm and you still get the same errors?

I tried it with PBP setup in MPLAB and I got a bunch of compile errors

Bruce
- 5th August 2009, 22:03
Those are the errors I was asking about. If you can just setup PBP to work from within MPLAB you really will save yourself a TON of time & headaches.

Show me the errors you get (when PBP is setup to compile in MPLAB), and I'll do my best
to help you get that working.

Bruce
- 6th August 2009, 00:39
I just compiled your code in MCS, then opened the .asm generated in MPLAB, selected
the 18F1220, and clicked the Quickbuild option, and it worked fine. Odd way of doing it,
but it did work.

Can you explain how you're setting up your project in MPLAB? Which version MPASM/MPLAB
you're using, etc?

Also, since it's not finding the .MAC file, I would check my path statement to make sure it
can find all files it needs.

wbubel
- 6th August 2009, 13:19
I found the problem. It was the name of the program I chose. I called it Blink i.bas once I changed its name to Blink_i.bas the whole thing compiled then I could build it in MPLAB.
I should have known better. I'm going to put my Dunce hat on and stand in the corner for a while.

Darrel Taylor
- 6th August 2009, 18:57
That's great you got it working ... But ...
I just don't understand why you are doing it that way? :confused:

When you compile it in MicroCode Studio, it's compiled. Done deal.

Why are you then trying to compile (build) it again with MPLAB.
You already have a .HEX file before you even open MPLAB. :confused:
<br>

Acetronics2
- 20th August 2009, 13:39
Hi, Darrel

I just have turned to MPLAB 8.36 and PBP 2.60 ...

Headache : I get this error screen while re-building an existing project :




Executing: "C:\PBP\PBPMPLAB.BAT" -ampasmwin -k# -p18F452 "Tracteur.bas"
Executing: "C:\PBP\PBPW.EXE" -ampasmwin -k# -p18F452 "Tracteur.bas"
Message[301] C:\PBP\18F452.INC 23 : MESSAGE: ( PENSEZ à INDIQUER la BONNE CONFIGURATION ... )
Message[301] C:\PBP\18F452.INC 24 : MESSAGE: ( PENSEZ à INDIQUER la BONNE CONFIGURATION ... )
Error[116] C:\PROGRAM FILES\MICROCHIP\MPLAB IDE\PROJETS\TRACTEUR.ASM 1083 : Address label duplicated or different in second pass (Z00063)
Error[116] C:\PROGRAM FILES\MICROCHIP\MPLAB IDE\PROJETS\TRACTEUR.ASM 1146 : Address label duplicated or different in second pass (Z00064)
Error[116] C:\PROGRAM FILES\MICROCHIP\MPLAB IDE\PROJETS\TRACTEUR.ASM 1199 : Address label duplicated or different in second pass (Z00065)
Error[116] C:\PROGRAM FILES\MICROCHIP\MPLAB IDE\PROJETS\TRACTEUR.ASM 1230 : Address label duplicated or different in second pass (Z00066)
Error[116] C:\PROGRAM FILES\MICROCHIP\MPLAB IDE\PROJETS\TRACTEUR.ASM 1083 : Address label duplicated or different in second pass (Z00063)
Error[116] C:\PROGRAM FILES\MICROCHIP\MPLAB IDE\PROJETS\TRACTEUR.ASM 1146 : Address label duplicated or different in second pass (Z00064)
Error[116] C:\PROGRAM FILES\MICROCHIP\MPLAB IDE\PROJETS\TRACTEUR.ASM 1199 : Address label duplicated or different in second pass (Z00065)
Error[116] C:\PROGRAM FILES\MICROCHIP\MPLAB IDE\PROJETS\TRACTEUR.ASM 1230 : Address label duplicated or different in second pass (Z00066)
Error[116] C:\PROGRAM FILES\MICROCHIP\MPLAB IDE\PROJETS\TRACTEUR.ASM 1083 : Address label duplicated or different in second pass (Z00063)
Error[116] C:\PROGRAM FILES\MICROCHIP\MPLAB IDE\PROJETS\TRACTEUR.ASM 1146 : Address label duplicated or different in second pass (Z00064)
Error[116] C:\PROGRAM FILES\MICROCHIP\MPLAB IDE\PROJETS\TRACTEUR.ASM 1199 : Address label duplicated or different in second pass (Z00065)
Error[116] C:\PROGRAM FILES\MICROCHIP\MPLAB IDE\PROJETS\TRACTEUR.ASM 1230 : Address label duplicated or different in second pass (Z00066)
Error[116] C:\PROGRAM FILES\MICROCHIP\MPLAB IDE\PROJETS\TRACTEUR.ASM 1083 : Address label duplicated or different in second pass (Z00063)
Error[116] C:\PROGRAM FILES\MICROCHIP\MPLAB IDE\PROJETS\TRACTEUR.ASM 1146 : Address label duplicated or different in second pass (Z00064)
Error[116] C:\PROGRAM FILES\MICROCHIP\MPLAB IDE\PROJETS\TRACTEUR.ASM 1199 : Address label duplicated or different in second pass (Z00065)
Error[116] C:\PROGRAM FILES\MICROCHIP\MPLAB IDE\PROJETS\TRACTEUR.ASM 1230 : Address label duplicated or different in second pass (Z00066)
Error[116] C:\PROGRAM FILES\MICROCHIP\MPLAB IDE\PROJETS\TRACTEUR.ASM 1083 : Address label duplicated or different in second pass (Z00063)
Error[116] C:\PROGRAM FILES\MICROCHIP\MPLAB IDE\PROJETS\TRACTEUR.ASM 1146 : Address label duplicated or different in second pass (Z00064)
Error[116] C:\PROGRAM FILES\MICROCHIP\MPLAB IDE\PROJETS\TRACTEUR.ASM 1199 : Address label duplicated or different in second pass (Z00065)
Error[116] C:\PROGRAM FILES\MICROCHIP\MPLAB IDE\PROJETS\TRACTEUR.ASM 1230 : Address label duplicated or different in second pass (Z00066)
Error[116] C:\PROGRAM FILES\MICROCHIP\MPLAB IDE\PROJETS\TRACTEUR.ASM 1083 : Address label duplicated or different in second pass (Z00063)
Error[116] C:\PROGRAM FILES\MICROCHIP\MPLAB IDE\PROJETS\TRACTEUR.ASM 1146 : Address label duplicated or different in second pass (Z00064)
Error[116] C:\PROGRAM FILES\MICROCHIP\MPLAB IDE\PROJETS\TRACTEUR.ASM 1199 : Address label duplicated or different in second pass (Z00065)
Error[116] C:\PROGRAM FILES\MICROCHIP\MPLAB IDE\PROJETS\TRACTEUR.ASM 1230 : Address label duplicated or different in second pass (Z00066)
Error[116] C:\PROGRAM FILES\MICROCHIP\MPLAB IDE\PROJETS\TRACTEUR.ASM 1083 : Address label duplicated or different in second pass (Z00063)
Error[116] C:\PROGRAM FILES\MICROCHIP\MPLAB IDE\PROJETS\TRACTEUR.ASM 1146 : Address label duplicated or different in second pass (Z00064)
Error[116] C:\PROGRAM FILES\MICROCHIP\MPLAB IDE\PROJETS\TRACTEUR.ASM 1199 : Address label duplicated or different in second pass (Z00065)
Error[116] C:\PROGRAM FILES\MICROCHIP\MPLAB IDE\PROJETS\TRACTEUR.ASM 1230 : Address label duplicated or different in second paPICBASIC PRO(TM) Compiler 2.60, (c) 1998, 2009 microEngineering Labs, Inc.
All Rights Reserved.

ERROR: Unable to execute mpasmwin.ss (Z00066)
Error[116] C:\PROGRAM FILES\MICROCHIP\MPLAB IDE\PROJETS\TRACTEUR.ASM 1083 : Address label duplicated or different in second pass (Z00063)
Error[116] C:\PROGRAM FILES\MICROCHIP\MPLAB IDE\PROJETS\TRACTEUR.ASM 1146 : Address label duplicated or different in second pass (Z00064)
Error[116] C:\PROGRAM FILES\MICROCHIP\MPLAB IDE\PROJETS\TRACTEUR.ASM 1199 : Address label duplicated or different in second pass (Z00065)
Error[116] C:\PROGRAM FILES\MICROCHIP\MPLAB IDE\PROJETS\TRACTEUR.ASM 1230 : Address label duplicated or different in second pass (Z00066)
Halting build on first failure as requested.
BUILD FAILED: Thu Aug 20 14:24:12 2009



All the error lines are referring to DT Instant interrupts ...

Could you give me a pointer ???

Alain

Acetronics2
- 20th August 2009, 18:53
the faulty 1083 Line :

[quote]
ENDASM?


1082 ; C:\PROGRAM FILES\MICROCHIP\MPLAB IDE\PROJETS\DT_INTS-18.BAS 00313 Z00063 asm
1083 Z00063

ASM?

; -- Added for ver. 3.2 --
ifdef SPPIF ;----{ Streaming Parallel Port Read/Write }--[PIR1, SPPIF]---
INT_Source PIR1,SPPIF, PIE1,SPPIE, IPR1,SPPIP
endif
ifdef BCL1IF ;----{ Bus 1 Collision }--------------------[PIR2, BCL1IF]---
INT_Source BUS1_INT, PIE2,BCL1IE, IPR2,BCL1IP
endif


...

; ifdef ;----{ }-------------[, ]---
; INT_Source , ,, ,
; endif


ENDASM?


1145 ; C:\PROGRAM FILES\MICROCHIP\MPLAB IDE\PROJETS\DT_INTS-18.BAS 00369 Z00064 asm ; -- USB sources --
1146 Z00064

ASM?
; -- USB sources --
ifdef USBIF ;----{ USB Interrupt funnel }---------------[PIR2, USBIF]---
INT_Source PIR2,USBIF, PIE2,USBIE, IPR2,USBIP

;----{ Bus Activity Detect }-----------------[UIR, ACTVIF]---
INT_Source USB_ACTV_INT, UIE,ACTVIE, _NoPriority


....


INT_Source USB_PID_INT, UEIE,PIDEE, _NoPriority
endif


ENDASM?


1198 ; C:\PROGRAM FILES\MICROCHIP\MPLAB IDE\PROJETS\DT_INTS-18.BAS 00415 Z00065 asm ; -- Ethernet sources --
1199 Z00065

ASM?
; -- Ethernet sources --
ifdef ETHIF ;----{ Ethernet Module }----------------------[PIR2, ETHIF]---
INT_Source ETH_INT, PIE2,ETHIE, IPR2,ETHIP

;----{ DMA Interrupt }-------------------------[EIR, DMAIF]---
INT_Source ETH_DMA_INT, EIE,DMAIE, _NoPriority


......

INT_Source ETH_TXER_INT, EIE,TXERIE, _NoPriority

;----{ Transmit }-------------------------------[EIR, TXIF]---
INT_Source ETH_TX_INT, EIE,TXIE, _NoPriority
endif


ENDASM?


1229 ; C:\PROGRAM FILES\MICROCHIP\MPLAB IDE\PROJETS\DT_INTS-18.BAS 00439 Z00066 asm ; -- CAN Module --
1230 Z00066

ASM?
; -- CAN Module --
ifdef WAKIF
;----{ CAN bus Error }------------------------[PIR3, ERRIF]---
INT_Source CAN_ERR_INT, PIE3,ERRIE, IPR3,ERRIP

;----{ Invalid Received Message }-------------[PIR3, IRXIF]---
INT_Source CAN_IRX_INT, PIE3,IRXIE, IPR3,IRXIP


Hope it Helps ...

PS: Program compiled fine with PBP 2.50c and MPLAB 8.15 ... of course ...
Alain

Darrel Taylor
- 20th August 2009, 20:24
Have you made changes? Or is the TRACTEUR program the same as ...

http://www.picbasic.co.uk/forum/showpost.php?p=46723&postcount=4

It compiles fine here with PBP 2.60 / MPASM 5.20.

If it's different, can you send me the new version?

Acetronics2
- 20th August 2009, 21:07
Hi, Darrel

Same errors ... looks same program !!!

MPASM is V5.33 here ...

All other programs NOT USING DT Interrupts compile fine ... sooo, I do not understand what's going on ...

Alain

Darrel Taylor
- 20th August 2009, 22:02
Because of all the problems people have been reporting, I didn't want to upgrade MPLAB.
But now I have the latest and greatest.

The first time compiling the TRACTEUR program, and it compiles just fine.

I do get that DOS window popping up instead of the progress bar, like others described.

I'm compiling with MicroCode Studio.
Are you using MPLABs IDE?

Added: I'm also using the original Elapsed_INT-18.bas, I don't have your modified version. But I think we talked about that before somewhere and it wasn't a problem.

Darrel Taylor
- 20th August 2009, 22:29
Are you using MPLABs IDE?
Duh! Another stupid question on my part ...

Error[116] C:\PROGRAM FILES\MICROCHIP\MPLAB IDE\PROJETS\TRACTEUR.ASM 1083 : Address ...

I don't use MPLAB, so can't offer much help there.
Does anything that Bruce was telling wbubel about MPLAB above help?

At least it's not related to DT_INTS.
<br>

Darrel Taylor
- 20th August 2009, 22:50
Or another thought, regarding limited length of file names. (Charles Leo)

http://www.picbasic.co.uk/forum/showpost.php?p=76402&postcount=7
<br>

Acetronics2
- 21st August 2009, 09:24
Hi, Darrel,

I Ported it to MCS ...

ERROR : MACRO BUFFER OVERFLOW ...

Which looks sililar to the error MPASM raised.

??????????

Alain

Acetronics2
- 21st August 2009, 09:30
HI,Darrel,

a special character compiler do not like ???

Alain

Darrel Taylor
- 21st August 2009, 09:39
I Ported it to MCS ...

ERROR : MACRO BUFFER OVERFLOW ...

That error only happens when compiling with PM.
Switch to MPASM for an 18F452.

Normally it will warn you when compiling 18F programs with PM.exe. But I think the macro overflow causes too many errors before it gets to that warning, so you don't see it in MCS.
<br>

Acetronics2
- 21st August 2009, 09:51
That error only happens when compiling with PM.
Switch to MPASM for an 18F452.

Normally it will warn you when compiling 18F programs with PM.exe. But I think the macro overflow causes too many errors before it gets to that warning, so you don't see it in MCS.
<br>

Ooooops, sorry.

Compiled fine in MCS ...

Great mistery ... for sure !!!

Alain

Acetronics2
- 21st August 2009, 11:11
Hi,

Result is the same with " T-Elapsed_18" ... straight out of the Package ...



Executing: "C:\Program Files\Microchip\MPLAB IDE\PBP\PBPMPLAB.BAT" -ampasmwin -k# -p18F452 "T_Elapsed-18.bas"
Executing: "C:\Program Files\Microchip\MPLAB IDE\PBP\PBPW.EXE" -ampasmwin -k# -p18F452 "T_Elapsed-18.bas"
PICBASIC PRO(TM) Compiler 2.60, (c) 1998, 2009 microEngineering Labs, Inc.
All Rights Reserved.

ERROR: Unable to execute mpasmwin.Message[301] C:\PROGRAM FILES\MICROCHIP\MPLAB IDE\PBP\18F452.INC 23 : MESSAGE: ( PENSEZ à INDIQUER la BONNE CONFIGURATION ... )
Message[301] C:\PROGRAM FILES\MICROCHIP\MPLAB IDE\PBP\18F452.INC 24 : MESSAGE: ( PENSEZ à INDIQUER la BONNE CONFIGURATION ... )
Error[116] C:\PROGRAM FILES\MICROCHIP\MPLAB IDE\PROJETS\T_ELAPSED-18.ASM 609 : Address label duplicated or different in second pass (Z00022)
Error[116] C:\PROGRAM FILES\MICROCHIP\MPLAB IDE\PROJETS\T_ELAPSED-18.ASM 672 : Address label duplicated or different in second pass (Z00023)
Error[116] C:\PROGRAM FILES\MICROCHIP\MPLAB IDE\PROJETS\T_ELAPSED-18.ASM 725 : Address label duplicated or different in second pass (Z00024)
Error[116] C:\PROGRAM FILES\MICROCHIP\MPLAB IDE\PROJETS\T_ELAPSED-18.ASM 756 : Address label duplicated or different in second pass (Z00025)
Halting build on first failure as requested.
BUILD FAILED: Fri Aug 21 12:08:46 2009

Acetronics2
- 21st August 2009, 12:31
Strange thing ...

DT 14 bits interrupts Examples Compile fine ( With MPLAB ), but NOT 16 bits interrupts Examples ...

Alain

Darrel Taylor
- 22nd August 2009, 02:04
No wonder I don't like MPLAB.

The problem seems to have something to do with the -k# command line option. (new option for pbp2.60)
If I use the same batch file that MPLAB uses ... PBPMPLAB.BAT
Then this command gives me the same errors you reported.

c:\PIC\PBP260\PBPMPLAB.BAT -ampasmwin -k# -p18F452 "Tracteur.bas"

If I remove the -k# option it compiles fine.

I haven't found a way to remove it from within MPLAB.
And I think if you did, you wouldn't be able to debug in MPLAB.

Added: In the PBP manual it only shows -k- and -k+. -k# doesn't even seem to be a valid option.
Not that it matters much, because it fails with either -k- or -k+ too.

Darrel Taylor
- 22nd August 2009, 03:25
I see exactly what's happening now.
This is one for meLabs to solve.

In an attempt to produce the COFF information for debugging with MPLAB, ... PBP with the -k option places Z????? Labels on every line of code ... including the "ASM" or @ lines.

If the program has any ASM macros in it (like DT_INTS), you can normally jump in and out of ASM anytime you need to within that macro.

But with it putting labels at the "ASM" statements, ... when those macros get used (more than once) it duplicates labels that were not in the original program.

For instance with this macro ...

ASM
MyMacro macro
; asm statements here
ENDASM
; PBP statements here
ASM ; This statement creates a label in the middle of a macro.
endm
ENDASM

@ MyMacro ; The first time it's used is OK
@ MyMacro ; the second time or more duplicates that label


I'll send a report to support at melabs.com

Darrel Taylor
- 22nd August 2009, 08:29
OMG!

If it's making a label for every PBP statement.
Then ANY PBP statements in a macro will cause the same error.

Apparently, every program I've ever written is now useless. :(
Well, (with MPLAB).
<br>

Acetronics2
- 22nd August 2009, 09:30
If I remove the -k# option it compiles fine.

.

Hi darrel ...

YES ... but BUILD fails ... no HEX generated, halas.

Bouhouuuuu ...

Alain

Ioannis
- 22nd August 2009, 11:26
I am still at 2.50c and although I have an itch to upgrade to 2.60 I do no think I'll do it now.

Darrel, If one uses MCS to edit and complile (with MPASM assembler) is there a problem?

Ioannis

mackrackit
- 22nd August 2009, 12:26
Am I following this correctly?
The problem is not with the new PBP it is with the new MPLAB?
Does it work with the MPLAB that we used with PBP 2.5?

Acetronics2
- 22nd August 2009, 12:45
Hi, Dave and Ioannis

YES ...

I really think it's URGENT to wait a little !!!

BUT it seems the problem only Occurs with DT 18 Instant Interrupts ...

Alain

mackrackit
- 22nd August 2009, 12:52
So other includes with ASM work properly?
That would be strange...

Ioannis
- 22nd August 2009, 13:06
Thanks Alain.

But with MCS does it compile OK?

Ioannis

Darrel Taylor
- 22nd August 2009, 17:31
BUT it seems the problem only Occurs with DT 18 Instant Interrupts ...

NOT TRUE!

As explained in the previous posts, the problem will happen with ANY program that uses PBP statements inside of macro's, when using MPLAB<hr>

Ioannis,
PBP 2.60 is really nice. And it works really well with Microcode Studio.

MPLAB is the problem. But trying to make PBP work with the new MPLAB, meLabs made a mistake, and now it causes new problems.

Don't wait, go ahead and get the upgrade, but forget about MPLAB.
<br>

Acetronics2
- 22nd August 2009, 21:03
NOT TRUE!

As explained in the previous posts, the problem will happen with ANY program that uses PBP statements inside of macro's, when using MPLAB<hr>

<br>

Hi, Darrel

You should have understood :

It works with "DT_INTS-14.bas" ... but not with "DT_INTS-18.bas"

Its a pity to have also lost the PBP label NAMES ...

Alain

Terry
- 24th August 2009, 19:04
Darrel,
Quick question, off topic from the most recent posts. I am using a PIC16F876A part with the DT_INTS-14.bas and using a timer0 interrupt, everything works wonderful, many many thanks! but when my program size goes past the 2k size I get the message when compiling "Message[306] ... Crossing page boundary -- ensure page bits are set." while I know this is only a warning, my program seems to work fine, but I would like to double check, whether this is a concern or not.
Thanks,
Terry

Darrel Taylor
- 24th August 2009, 20:14
Hi Terry,

DT_INTS won't have any problems when it crosses page boundaries, and most normal PBP programs won't either.

But if the program uses the BRANCH command or has assembly language routines, it can be a problem.


Crossing Page Boundary - Solution
http://www.picbasic.co.uk/forum/showthread.php?t=40

Warning (and other Compilation Error) Messages (Melanie)
http://www.picbasic.co.uk/forum/showthread.php?t=555

Acetronics2
- 24th August 2009, 20:21
Thanks Alain.

But with MCS does it compile OK?

Ioannis

Hi, Ioannis

I've verified in real life ... my old programs Work fine, compiled With MCS.

Was not so evident due to little changes in the resulting HEX ...

Alain

Terry
- 24th August 2009, 22:06
Darrel,
In my PBP code the only assembly routine would be your code for the interrupt and I have no branch routines. My interrupt routine is in PBP, not assembly, but if is was, could this then be a possible issue. Also in searching this thread, I did see the possibly of inserting "@ errorlevel -306 " to suppress the warning, if this is a OK, where does it makes sense to insert it, such as right after the includes.
Thanks for your help,
Terry

Darrel Taylor
- 24th August 2009, 22:29
The ASM that declares Interrupts, will be OK because all the GOTO's and GOSUB's/CALLs in DT_INTS already use Paging code.

If the ISR is assembly language, there would be a possibility of page problems.
But if you use L?GOTO or L?CALL instead of goto or call, then it won't be a problem either.
They are macro's that are part of PBP and automatically set PCLATH to the correct page before jumping. They also reset to BANK0, so anywhere they jump to should assume the bank is currently 0.

The -306 line can technically be put anywhere in the program before the first Page Crossing. But it's usually found at the very top, right up there with your __CONFIG lines.
<br>

Terry
- 24th August 2009, 22:37
Many Thanks Darrel,
For your help now and for a GREAT easy to use approach for interrupts using PBP.
Terry

Darrel Taylor
- 24th August 2009, 23:22
Alain,

I got ahold of Charles Leo, RE: the duplicate label problem.

Like I said before, I don't use MPLAB so I didn't know you could do this.

Under Project | Build Options | Project | PICBASIC PRO tab ...
Check the "Use Alternate Settings" checkbox, and remove the -k- or -k# parameter.

The Tracteur program then compiles without error within MPLAB.
And the setting only affects the Tracteur program.

http://www.pbpgroup.com/files/MPLAB-k.JPG

HTH,

hatchethand1000
- 29th August 2009, 19:41
I am running into a problem trying to figure out how to use RBC_INT on portB.1

I am using a 16F883 and I am looking for B.1 to drop from high to low. Below is part of my code to read the interrupt.

readchar:
@ INT_DISABLE RBC_INT
Dummy = PortB
if Dummy.1 = 0 then
goto good_int
Else
@ INT_CLEAR RBC_INT
@ INT_ENABLE RBC_INT
@ INT_RETURN
endif
good_int:
' process the interrupt code here


I know this is not correct but I cannot figure out why?

Any help would be appreciated.

Acetronics2
- 31st August 2009, 18:22
Alain,

I got ahold of Charles Leo, RE: the duplicate label problem.

Like I said before, I don't use MPLAB so I didn't know you could do this.

Under Project | Build Options | Project | PICBASIC PRO tab ...
Check the "Use Alternate Settings" checkbox, and remove the -k- or -k# parameter.

The Tracteur program then compiles without error within MPLAB.
And the setting only affects the Tracteur program.

HTH,

Hi, Darrel

Thanks for the trick ...

Now, we've completely lost the debug view of produced ASM ... no more labels and even breakpoints can't be used.

Hope Melabs will correct that soon ... !!!

BTW I've appreciated Melabs has cleaned the LOOKUP tables ... New EEPROM commands are also fine ... knowing the LSByte is written first !!!

Alain

LinkMTech
- 3rd September 2009, 19:35
Hi everyone,
I think I'm getting very close to understanding DT's interrupt routine but need some direction.
I'm using a PIC16F688 to make myself a test fixture to test some product but pretty sure I did something wrong in the setups.
Using this small test program and a scope to monitor an output, I see the "Toggling" led stop during the interrupt routine. This only happens when PAUSE, FOR/NEXT and PAUSEUS is used in the main.
Ultimately, I will need to send serial data using SEROUT2 continueously in the background so I can do other chores in the foreground that will use TMR1, A/D and some simple LED indications.



'************************************************* ************************
'* Name : Test fixture.BAS
'* Author : Louis Chagoya
'* Notice : Copyright (c) 2008 Link M Technologies
'* : All Rights Reserved
'* Date : 8/24/2009
'* Version : 1.1
'* Notes : This system uses the PIC16F688 to learn DT's Interrupt system
'* while utilizing other signalling functions at the same time.
'************************************************* ************************
'/////////////////////////////////////////////////////////////////////////
' Configs
'/////////////////////////////////////////////////////////////////////////
@ __config _INTRC_OSC_NOCLKOUT & _WDT_OFF & _MCLRE_OFF & _CP_OFF
OSCCON = %01100001 ' Oscillator set to 4MHz, bits 6-4
CMCON0 = 7 ' Analog comparators off
ADCON0 = %10010000 ' A/D right justified, Vref=VDD, AN2 selected
ADCON1 = %01010000 ' A/D conversion CLK/16
ANSEL = %00000100 ' AN2 set to analog input rest digital
TRISA = %00101101 ' Set ports 0,2,3 and 5 as inputs, rest outputs
TRISC = %00000000 ' Set all pins as outputs

'DEFINE OSC 8 ' Define OSC to 8Mhz for PAUSE setting
DEFINE ADC_BITS 10 ' ADCIN resolution (Bits)
DEFINE ADC_CLOCK 5 ' ADC clock source (Fosc/16)
DEFINE ADC_SAMPLEUS 7 ' ADC sampling time (uSec)
DEFINE SER2_BITS 8 ' Set up baud rate for 7812bps

'/////////////////////////////////////////////////////////////////////////
' Pin I/O naming
'/////////////////////////////////////////////////////////////////////////
Data_In VAR PORTA.0 ' Pin 13 Data from UUT
Data_Out VAR PORTA.1 ' Pin 12 Data to UUT
' VAR PORTA.2 ' Pin 11 GPS input from UUT
Test VAR PORTA.3 ' Pin 4 Push button to begin test
Bypass VAR PORTA.4 ' Pin 3 Puts UUT into Bypass or Active mode
Byp_Sel VAR PORTA.5 ' Pin 2 Select type switch input
BCDval var PORTC ' All of PortC declared as variable
Ready VAR PORTC.0 ' Pin 10 READY LED
Byp_Pass VAR PORTC.1 ' PIn 9 BYPASS test PASS LED - Green
Byp_Fail VAR PORTC.2 ' PIn 8 BYPASS test FAIL LED - Red
Act_Pass VAR PORTC.3 ' PIn 7 ACTIVE test PASS LED - Green
Act_Fail VAR PORTC.4 ' PIn 6 ACTIVE test FAIL LED - Red
Pwr_ON VAR PORTC.5 ' PIn 5 Provides power to UUT


'/////////////////////////////////////////////////////////////////////////
' Variable declarations
'/////////////////////////////////////////////////////////////////////////
i VAR BYTE ' Increment counter when needed
cksm VAR BYTE ' Checksum variable


'/////////////////////////////////////////////////////////////////////////
' DT's Interrupt Routine
'/////////////////////////////////////////////////////////////////////////
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 TMR0_INT, _Gen_Data, PBP, YES
endm
INT_CREATE ; Creates the interrupt processor
ENDASM

'.....Various OPT_Reg tries....

'OPTION_REG.3 = 1 ' Prescaler is assigned to the WDT
'OPTION_REG.2 = 1 ' N/G, even with WDT ON
'OPTION_REG.1 = 1
'OPTION_REG.0 = 1 ; REGISTER 5-1: Prescaler = 1:1 via WDT rate

OPTION_REG = 7 ' Times out in 65.2ms. Will need 100ms when
' get it to work
@ INT_ENABLE TMR0_INT ; enable Timer 0 interrupts

cksm = 85

'/////////////////////////////////////////////////////////////////////////
' Main Program
'/////////////////////////////////////////////////////////////////////////
start:

TOGGLE act_fail ' Use this output to monitor routine
PAUSE 1
TOGGLE act_fail
PAUSE 1

GOTO start

'---[TMR0 - interrupt handler]--------------------------------------------

Gen_Data:

SEROUT2 Data_out, 108, [cksm] ' Serial out cksm value at 7812bps
PAUSEUS 3720 ' Total time= 5ms

@ INT_RETURN


END


My understanding is that main program should not be disturbed by the interrupt routine if done properly. In this case, I'm hoping I'm not being proper rather than using the wrong PIC for my app.

Thank for your help...

hatchethand1000
- 3rd September 2009, 20:09
Louie,

There are a couple of things I found while using Instant Ints. that may be worth looking at.
I am not an expert on them, I have found out what works for me by trial and error, and error and error as with all things Pic. But when you find the solution they work great!

When entering the interrupt, I stop additional interrupts from being serviced or re-serviced until I am ready to release control again.

INTCON needs to be set, looking at bits 7,6,5 and 2 page 15 and 45-47 of the data sheet.


INTCON = %111xx1xx ' with x set for other functions and the 1's are a guess for your application

Code suggestion


'---[TMR0 - interrupt handler]--------------------------------------------

Gen_Data:
@ INT_DISABLE TMR0_INT
SEROUT2 Data_out, 108, [cksm] ' Serial out cksm value at 7812bps
PAUSEUS 3720 ' Total time= 5ms

@ INT_CLEAR TMR0_INT
@ INT_ENABLE TMR0_INT
@ INT_RETURN


END

Kevin

Darrel Taylor
- 3rd September 2009, 20:22
Kevin,

You should NOT set INTCON, PIEx, PIRx, IPRx or any other interrupt related registers manually. DT_INTS handles all of those bits for you.

There is NO reason to INT_DISABLE / INT_ENABLE inside of an interrupt handler. Interrupts are automatically disabled by the hardware during an interrupt event, and can not cause another interrupt until the current one is finished. You are confusing things with ON INTERRUPT which must have DISABLE/ENABLE wrapped around them.

Louie,

When an interrupt occurs, the main program STOPS.
Program execution jumps to the ISR where it remains until the handlers have completed.
The main program will continue only after the entire ISR is finished.

The ISR and the main program do not execute at the same time.

It's why they're called Interrupts.
They Interrupt the main program to go do something else.
<br>

hatchethand1000
- 3rd September 2009, 20:32
Darrel,

Thanks! I will modify my code, this will reduce overhead. Like I tried to say I do not know much about this, just enought to be dangerous and wrong most of the time.

I have been using the 16F688 and the 16F883 on a couple of projects, your routines work great.

When wanting to use the RBC_INT I found I had to set IOCB to get the interrupt to work on one input of PORTB.


Thanks,
Kevin

____________________

If you want the best seat in the house, you will have to move the Cat.

LinkMTech
- 4th September 2009, 00:03
Thanks for ending the misery Darrel.
I guess I was seeing too much into it. I still need to learn to juggle the events properly so they don't clash.
When I read the second post that says "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.", it's true, but I made the mistake of assumming that the main program would go along like some absent minded fool without a bother in the world.


Thanks for all your contributions,

Darrel Taylor
- 4th September 2009, 00:20
I have been using the 16F688 and the 16F883 on a couple of projects, your routines work great.
Sweet!


When wanting to use the RBC_INT I found I had to set IOCB to get the interrupt to work on one input of PORTB.
Yes, you're correct.
I shouldn't have said "... or any other interrupt related registers manually". That was a little too broad.
There are several registers like IOCB that will need to be changed.

I probably should have limited it to ... "You should NOT set INTCON, PIEx, PIRx, IPRx". As those are the only interrupt bits that DT_INTS does handle for you.

Thanks for the correction.


If you want the best seat in the house, you will have to move the Cat.
Which is why the "best" seats in my house "belong" to the cats.
They know not to sit in mine ... they might get sat on. :D

Darrel Taylor
- 4th September 2009, 00:40
Thanks for ending the misery Darrel.
I guess I was seeing too much into it.
Well don't end it there ...
It's probably that you're "not seeing enough into it".

Interrupts can definitely be used to make multiple things happen at the same time.
It's just that those things need to be happening in hardware.

If you want to send RS232 from an interrupt, then you should use the USART.
If you want to have an interrupt driven PAUSE, then use a Timer.

Jumping to the ISR and executing a software routine like serout(2) is not normally very productive, because the same routine could have been run from the main program without interrupts without much additional overhead. And since either way ... the program can't continue until the serout has completed, with or without interrupts makes little difference.

But if that interrupt uses the hardware USART, only a few instructions need to be executed to start the USART sending data, then it immediately returns from the interrupt and continues running the main program at the same time that the USART is sending the data.

There are several hardware peripherals on the various PIC's, and you might have 5 or 6 things all happening at the same time.

While software timed, bit-bang routines in your interrupts will occasionally be very useful ... avoid them at all cost.

Hardware and Interrupts make good companions.

hth,

LinkMTech
- 4th September 2009, 05:30
Well don't end it there ...

Alrighty then! Just when I was about to go with plan "B", add a PIC12F683 as a stand alone serial generator.
I just took a look at USART along with Mister E's PIC calculator and found that 7812 baud is configurable. A first glance some time ago gave me the impression that only common baud rates were available. I just recently discovered SEROUT2!
Is the USART hardware like the HPWM that can run continueously in the background?
If so, which commands will disrupt it or vice versa? I ran into some surprises when trying to use the HPWM while using the A/D in a WHILE:WEND. So went with PWM sprinkled through out the program along with a nice filter to hold my Vout.

The RS232 does not have to be interrupt started, just running all the time with the same 8x8 bytes of data. It will be processed and returned without any delay so I will have to act on it immediately.
Do you think this is still possible? Or go with plan "B"?

Darrel Taylor
- 5th September 2009, 06:15
7812 baud ... ECU / ALDL ??

Yes, the USART will continue sending data at the same time the main program is running. But you have to feed it bytes every now and then.

The TX_INT (USART Transmit Interrupt) makes it fairly easy.
When the transmit buffer is empty it generates a TX_INT, which jumps to a handler that sends the next byte.

That handler just needs to send one byte at a time, by keeping track of where it is in an array and incrementing/wrapping as needed. It only takes a few instructions for each byte, so the main program is hardly affected by it.

You can then very easily have it sending continuous RS232 data via the USART, while the main program continues what it's doing at the same time.

Typically, when you have data to send, you ENABLE TX_INT's, and when it's finished sending the available data, DISABLE TX_INT. And that handler won't be called again until there's more data.


I ran into some surprises when trying to use the HPWM while using the A/D in a WHILE:WEND. So went with PWM sprinkled through out the program along with a nice filter to hold my Vout.

The HPWM command doesn't like being updated continuously.
It resets the PWM cycles every time it executes.

If you limit the HPWM updates to only when the Duty value changes, it gives a better response.
You can also synchronise the updates with Timer2 to make it "glitch-free".

hth,

LinkMTech
- 6th September 2009, 16:50
Thanks for the direction Darrel. I did some research on the USART and like what I found now that I'm beginning to understand the use of your interrupt routine and how the information is presented in the data sheets. I think it makes more sense as the need increases.



7812 baud ... ECU / ALDL ??

The 7812 baud is on a motorcycle ECM alias ECU.



The HPWM command doesn't like being updated continuously.
It resets the PWM cycles every time it executes.

If you limit the HPWM updates to only when the Duty value changes, it gives a better response.
You can also synchronise the updates with Timer2 to make it "glitch-free".


Sorry, I wasn't clear on my attempt with the HPWM. I set it early in the program to run on its own and would get updated only when needed (when a rider shifts gear). But while using a 55ms timer controlled ADCIN inside a WHILE:WEND, I found it jumping out of the loop way before the timer overflowed because the HPWM triggered it somehow. So I'm sure I didn't account for other hardware commonalities.

Michael Wakileh
- 3rd October 2009, 22:53
I've been wondering what it would take...or if anyone has managed to change the Timereload (External Constant), to a variable that can be altered in the main program...
Actually, I would like to load this value from eeprom on startup, but I am at a loss for how to go about this short of learning asm...


;---Reload Timer1------ (T1 asm interrupt handler)
ASM
ReloadTMR1
MOVE?CT 0, T1CON, TMR1ON ; 1 stop timer
MOVLW LOW(TimerReload) ; 1 Add TimerReload to the
ADDWF TMR1L,F ; 1 value in Timer1
BTFSC STATUS,C ; 1/2
INCF TMR1H,F ; 1
MOVLW HIGH(TimerReload) ; 1
ADDWF TMR1H,F ; 1
MOVE?CT 1, T1CON, TMR1ON ; 1 start timer
INT_RETURN
ENDASM

Darrel Taylor
- 4th October 2009, 00:50
I've been wondering what it would take...or if anyone has managed to change the Timereload (External Constant), to a variable that can be altered in the main program...
Actually, I would like to load this value from eeprom on startup, but I am at a loss for how to go about this short of learning asm...



;---Reload Timer1------ (T1 asm interrupt handler)
ASM
ReloadTMR1
MOVE?CT 0, T1CON, TMR1ON ; 1 stop timer
MOVLW LOW(TimerReload) ; 1 Add TimerReload to the
ADDWF TMR1L,F ; 1 value in Timer1
BTFSC STATUS,C ; 1/2
INCF TMR1H,F ; 1
MOVLW HIGH(TimerReload) ; 1
ADDWF TMR1H,F ; 1
MOVE?CT 1, T1CON, TMR1ON ; 1 start timer
INT_RETURN
ENDASM

I'm sure there are a number of ways to do it, but a direct translation of that routine might look like this ...

TimerReload VAR WORD BANK0

ASM
ReloadTMR1
MOVE?CT 0, T1CON, TMR1ON ; 1 stop timer
MOVF _TimerReload,w ; 1 Add TimerReload to the
ADDWF TMR1L,F ; 1 value in Timer1
BTFSC STATUS,C ; 1/2
INCF TMR1H,F ; 1
MOVF _TimerReload + 1,w ; 1
ADDWF TMR1H,F ; 1
MOVE?CT 1, T1CON, TMR1ON ; 1 start timer
INT_RETURN
ENDASM
Then TimerReload is a PBP word variable.
You can calculate it or read it from EEPROM as desired.

Michael Wakileh
- 4th October 2009, 20:02
Thanks Darrel! works great!


I've been experimenting with the interrupt system lately and although its not relevant for my purposes, I noticed something I can't explain...
I'm guessing it has something to do with the port variables saved...

I have a pic12f683
Led1 GPIO.1 toggled by 1Hz Timer1 interrupt (...in my case via external crystal)
Led2 GPIO.2 toggled by IOC/RB interrupt.
The RB interrupt also starts or stops the timer...allowing for control of the blinking LED1. This part works however LED2 only turns off briefly when the button is pressed.

Things work normal if a flag bit is "toggled" and the Leds are controlled in the main program...



RBPortIntPBP:
'toggle gpio.2
if T1CON.0 = 0 then
TOGGLEFLAG = 1 'attempt doing this via main handler
else
TOGGLEFLAG = 0
endif
pause 300
@ INT_RETURN


Can anyone explain, and is there away to do this from within the handler?

Ioannis
- 4th October 2009, 21:01
Hi. I am getting an error Symbol not previously defined (PIR2) on a 16F628 with Darrels interrupts.

On the program I do not use any PIR2 register. So why does this error come up? Can't this be taken care automatically?

Also if I want to disable TMR0 interrupts inside the timer0 INT Handler, will the Interrupts be enabled on exiting the routine? Like this:



INT_Service_TMR0:
@ INT_DISABLE TMR0_INT
tmr0=21 'Preload for 60msec time out
timer0=1 'timer 0 has timed out flag
@ INT_RETURN <<<<<<<<----------------Here I do not want to enable timer0


Thanks,
Ioannis

Darrel Taylor
- 4th October 2009, 22:36
Michael,

With the Port Change Interrupts ...
The PORT (GPIO) has to be read within the handler to end the mismatch condition. Otherwise it can't clear the interrupt flag and as soon as it exits the ISR it'll jump right back into another interrupt, essentially halting the main program.

You'll also receive interrupts on both the Rising and Falling edges, so you'll need to check the state of the PIN to know if it's been pressed or released.

And since you have to read the PORT to know which state the PIN is in, that qualifies as the port READ, and ends the mismatch.


RBPortIntPBP:
if GPIO.3 = 0 then TOGGLE GPIO.2
pause 10
@ INT_RETURN

Darrel Taylor
- 4th October 2009, 22:42
Hi. I am getting an error Symbol not previously defined (PIR2) on a 16F628 with Darrels interrupts.

Ioannis,

I've compiled your program here for a 16F628 with several versions of PBP, and I don't get that error.

<strike>Have you made any changes to the DT_INTS-14 file?</strike>

Added:
Oh shoot, now I remember.
That was fixed in version 0.93 (Jan '06)

Try downloading the lastest version.
http://www.darreltaylor.com/DT_INTS-14/downloads.htm
<br>

Ioannis
- 4th October 2009, 22:48
Hi Darrel.

Yes I commended the wsave3 as I compile for 16F628 chip.

Also to get rid of the error I commended out the PIR2 references too.

I attach the modified file to check.

Thanks,
Ioannis

Darrel Taylor
- 4th October 2009, 22:57
Sorry, I added to my previous post.
Didn't get it in there soon enough.

It should help.
<br>

Ioannis
- 4th October 2009, 23:15
Thanks Darrel. Besides the wsave3 thing I had to commend out, yes it helped.

Now is fine.

About the disable interrupt, will the timer be enabled upon @ INT_RETURN ?

Ioannis

Darrel Taylor
- 4th October 2009, 23:33
Also if I want to disable TMR0 interrupts inside the timer0 INT Handler, will the Interrupts be enabled on exiting the routine? Like this:



INT_Service_TMR0:
@ INT_DISABLE TMR0_INT
tmr0=21 'Preload for 60msec time out
timer0=1 'timer 0 has timed out flag
@ INT_RETURN <<<<<<<<----------------Here I do not want to enable timer0


No it will not be re-enabled automatically.

And you won't get any more interrupts from the timer untill there's an @ INT_ENABLE TMR0_INT somewhere else in the program.

The Timer will continue to run and overflow, so the next time you Enable the timer ints ... make sure you clear the flag first or it will immediately jump into an unwanted INT.
@ INT_CLEAR TMR0_INT
<br>

Ioannis
- 4th October 2009, 23:44
OK. Better is to use Tmr1 but not available at the moment.

Thank you very much.
Ioannis

Michael Wakileh
- 5th October 2009, 00:47
Thanks! ...Hadn't noticed because the main routine wasn't doing anything, and the other Led still seamed to toggle at 1 Hz...

Michael Wakileh
- 5th October 2009, 01:23
I still had some strange anomalies going on...
reading GPIO.2 to a testvariable (Testbit VAR BIT BANK0)
just before the @ INT_RETURN seems to solve those...

Darrel Taylor
- 5th October 2009, 01:56
Good Point Michael,

I'll have to remember that. :)
<br>

bcd
- 5th October 2009, 07:49
Hey Darrel,
Have you had a chance to try any of the new enhanced core pics yet ?

I have a few 16f1936 chips on order and would love to know if you have had a chance to play with DT_INT on them yet.

bill

Darrel Taylor
- 5th October 2009, 22:53
I have a few 16f1936 chips on order and would love to know if you have had a chance to play with DT_INT on them yet.

Did you order them in the QFN package?
Apparently the SOIC's won't be available from Microchip till November

I think the only thing you can get in a DIP package so far is the 1934, but they're usually out of stock on those.

I have some on order too, have no idea when I'll get them.

Consequently, DT_INTS will not work with the "E" (F1) chips. :(
<br>

bcd
- 6th October 2009, 00:52
Got 16f1936 and 16f1937 in DIP and some 16f1936 in SOIC due to arrive with UPS today.
Ordered them last week from microchip direct.

Want me to send you a couple ?

Bill.

Darrel Taylor
- 6th October 2009, 03:02
Ohhhh, that's great news.
And thanks for the offer.

I should have looked at Microchip Direct more often.
There's all kinds of them now.

They are on order.
Supposedly shipping tomorrow.

Thanks for the reminder Bill!
<br>

circuitpro
- 6th October 2009, 17:00
Never used an interrupt before in my life, but am going to try in my current project. I need to use the 'interrupt-on-change' capability of the 18F to detect (and hopefully count) the decoded clock output from a rotary encoder. Do you have (or) can you point me to, an example of 'interrupt-on-change' using your routines?

Thanks very much, and I'm waiting to see the unfinished pages on your site, Darrel!

Darrel Taylor
- 6th October 2009, 22:28
... I need to use the 'interrupt-on-change' capability of the 18F to detect (and hopefully count) the decoded clock output from a rotary encoder.Try this one from SteveB ...

http://www.picbasic.co.uk/forum/showthread.php?p=25396#post25396

There were some changes to it, so read the rest of the thread too.

hth,

circuitpro
- 6th October 2009, 22:55
I'm on it, and thanks!

Darrel Taylor
- 9th October 2009, 05:56
WOW!

Kudos to Microchip Direct!!!
Ordered them on the 5th, shipped from Thailand on the 6th, received on the 8th.
I can't get anything from California shipped that fast.

5 - 16F1937
5 - 16F1936
1 - 16F1934

$34 with shipping (Fed-Ex).

Everything else is on hold.
Time to update DT_INTS-14. :)
<br>

Ioannis
- 9th October 2009, 07:03
I can double that. My experience with Microchip Direct was wonderful.

Either 1 pcs or 250, service is top.

Ioannis

circuitpro
- 10th October 2009, 00:56
Darrel,

Want to thank you again for your Instant Interrupts. I inserted them into my huge 18F program, and the elapsed timer is working perfectly! Am going to watch your website and waiting for the "Command Reference"!!

bcd
- 10th October 2009, 01:04
I find it is actually easier and quicker to deal with Microchipdirect than the local microchip office - seems to be a lot cheaper as well ! I wonder if the office just orders online and then drop ships ???

Glad to hear you got some new toys ! Looking forward to the news.

bill.

Darrel Taylor
- 10th October 2009, 01:22
These chips are Amazing ....
They've got everything you could need in a 16F.
I think I even found a kitchen sink :)

And they are backwards compatible enough that it shouldn't even take very long for the update to DT_INTS.

At $2.52 ea. for the 40-pin jobs, I may never use another 16F.<hr>

And for the "Command reference" ... It's been waiting a few years now. :o
Everyone just kinda picked it up and went with it. So I got lazy.
Should've, could've, would've, maybe ...
<br>

bcd
- 10th October 2009, 02:31
I love the fact they are 5v as well - seemed a lot of the newer 18f series were moving to 3.3v only.

I think they are my new favourite series of PICs.

bill

Ioannis
- 10th October 2009, 10:36
I do not want to destroy the good climate that 16F193x have created, but look at the errata file 80479A.pdf. They have some issues that may affect users that will use EEPROM or CCP rgisters.

Ioannis