NO..at least give more details... error message, code etc etc
Make sure you're using MPASM to compile![]()
NO..at least give more details... error message, code etc etc
Make sure you're using MPASM to compile![]()
Steve
It's not a bug, it's a random feature.
There's no problem, only learning opportunities.
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
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
Code: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
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.
Last edited by mister_e; - 30th April 2008 at 19:56.
Steve
It's not a bug, it's a random feature.
There's no problem, only learning opportunities.
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...
Regards
Sougata
LMAO! well this avatar is really me... if you feel concern... i'm sorry![]()
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...
this way + PBP type it should solve most, see all problems.Code: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
HTH
Steve
It's not a bug, it's a random feature.
There's no problem, only learning opportunities.
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:
Code: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
btw,
If I disable INT (INTCON=0) the LCD shows correctly, but of ocurse interrupts are not working.
What I do is turn off interrupts before serial and back on after serial completes. Like this:
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.Code:sendudp: INTCON.7 = 0 SerOut2 PORTC.6, 84, [$50] 'ask siteplayer to send udp INTCON.7 = 1 udpcount = 0 gosub delay return
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.
"It will never happen here!" just happened here.
My thoughts and prayers for Sandy Hook victims and families.
Well,
What if the interrupts are for the clock ?
Disabling it will cause the clock not to keep going.
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
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.
Regards
Sougata
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
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.
Last edited by Bruce; - 25th July 2008 at 20:20. Reason: Only for 17C7xx devices
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
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
If your oscilloscope costs more than your car...
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
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
We were just talking about that last month.
This might help.
http://www.picbasic.co.uk/forum/showthread.php?t=10263
<br>
DT
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
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.
"If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte
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
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>
DT
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
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>
DT
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
Bookmarks