|
|
View previous topic :: View next topic |
Author |
Message |
xvi.lajos
Joined: 06 Sep 2003 Posts: 12 Location: Hungary
|
Interrupt in delay??? |
Posted: Tue Nov 06, 2001 7:18 am |
|
|
Hi,
What does the pic do in the delay_ms.
I use the rtcc0 interrupt and it works fine until I use
the delay_ms(1000) function.
I seems to me the interrupt disabled in the delay function.
Is it true?
I read the manual several time but I can not find the answer.
I use pcw 3.047 and picem14 downloader with 16c63 module.
Thanks George
___________________________
This message was ported from CCS's old forum
Original Post ID: 976 |
|
|
Tomi Guest
|
Re: Interrupt in delay??? |
Posted: Tue Nov 06, 2001 1:06 pm |
|
|
ITs are not disabled in delay_ functions. Delay_ms() is just a simple inner loop, a middle loop, an outer loop, etc... What do you do in your RTCC ISR? If you just set a flag and serve the IT in your main() keep in mind that your ISR returns to the delay_ms() function instead of main() (til delay_ms() is active).
Az interrupt-ok nincsenek letiltva a delay_ rutinok alatt. A delay_ms() csak egy belső hurok, egy k�z�pső hurok, egy k�lső hurok, stb..... Mit csin�lsz az IT rutinodban? Ha csak egy flag-et �ll�tasz be, vedd figyelembe, hogy az ISR-ed a delay_ms()-hez t�r vissza a main() helyett (am�g a delay_ms() akt�v).
:=Hi,
:=What does the pic do in the delay_ms.
:=I use the rtcc0 interrupt and it works fine until I use
:=the delay_ms(1000) function.
:=I seems to me the interrupt disabled in the delay function.
:=Is it true?
:=I read the manual several time but I can not find the answer.
:=I use pcw 3.047 and picem14 downloader with 16c63 module.
:=
:=Thanks George
:=
___________________________
This message was ported from CCS's old forum
Original Post ID: 985 |
|
|
xvi.lajos
Joined: 06 Sep 2003 Posts: 12 Location: Hungary
|
Re: Interrupt in delay??? |
Posted: Mon Nov 12, 2001 5:58 am |
|
|
:=ITs are not disabled in delay_ functions. Delay_ms() is just a simple inner loop, a middle loop, an outer loop, etc... What do you do in your RTCC ISR? If you just set a flag and serve the IT in your main() keep in mind that your ISR returns to the delay_ms() function instead of main() (til delay_ms() is active).
Yes, It is.
The problem was the disabled interrupt during Delay_ms to prevent the recursion.
I spent a day and re-read the manual again and again and
I could find the problem.
I used a printf(myfunction," etc...\n") to print data to a Hitachi LCD in the interrupt rutin.
The lcd handler function also use the delay_ms function.
So, according to the manual it is the recursion which is not allowed with PICs.
Cheer George
:=:=Hi,
:=:=What does the pic do in the delay_ms.
:=:=I use the rtcc0 interrupt and it works fine until I use
:=:=the delay_ms(1000) function.
:=:=I seems to me the interrupt disabled in the delay function.
:=:=Is it true?
:=:=I read the manual several time but I can not find the answer.
:=:=I use pcw 3.047 and picem14 downloader with 16c63 module.
:=:=
:=:=Thanks George
___________________________
This message was ported from CCS's old forum
Original Post ID: 1064 |
|
|
xvi.lajos
Joined: 06 Sep 2003 Posts: 12 Location: Hungary
|
Re: Interrupt in delay??? |
Posted: Mon Nov 12, 2001 6:13 am |
|
|
Szia,
Ugy t�nik m�gis le vanak tiltva.
:=Az interrupt-ok nincsenek letiltva a delay_ rutinok alatt. A delay_ms() csak egy belső hurok, egy k�z�pső hurok, egy k�lső hurok, stb..... Mit csin�lsz az IT rutinodban? Ha csak egy flag-et �ll�tasz be, vedd figyelembe, hogy az ISR-ed a delay_ms()-hez t�r vissza a main() helyett (am�g a delay_ms() akt�v).
K�szi a v�laszod,
Leirom a v�laszom magyarul is h�tha ugy jobban �rthető.
(You know my English...)
�rdekes dolog t�rt�nt, le lett tiltva az interrupt.
A megszakit�si rutinban haszn�ltam egy LCD re kiiro utasit�st ami szint�n haszn�lta a delay_ms rutint.
Teh�t a delay_ms utasit�s k�zben elugrott a megszakit�sba �s ott ujra meghivta volna a be nem fejezett delayt_ms.
P�rszor v�gigbogar�szva a manualt r�j�ttem a hib�ra.
Tulajdunk�ppen fell�pett a rekurzio �s hogy ezt kikerulje a fordito letiltotta a main ban levő delay_ms rutin v�grehajt�sa előtt a megszakit�st.
Amint kit�r�ltem a megszakit�sban a delay_ms utasit�st azonnal megjavult.
Egy�bk�nt m�r r�gebben fel akartam venni a kapcsolatot veled csak eddig nem akartalak zavarni.
Rendszeresen figyelem a v�laszaidat a list�n �s olyan j� v�laszokat szokt�l irni hogy nag r�sz�t elmentem, h�tha k�sőbb sz�ks�gem lessz r�.
Szia Gyuri
___________________________
This message was ported from CCS's old forum
Original Post ID: 1065 |
|
|
Tomi Guest
|
Re: Interrupt in delay??? |
Posted: Mon Nov 12, 2001 8:53 am |
|
|
<font face="Courier New" size=-1>:=So, according to the manual it is the recursion which is not allowed with PICs.
Distinguish between the PIC (the hardware) and CCS C (the compiler).
Recursions are allowed by the PICs (of course, the depth of the recursion is limited by the HW stack).
Recursions are NOT allowed by CCS C. It is because CCS C uses static variables for internal operations.
(This is very useful to keep memory usage on an affordable level).
Your problem is about static variables.
Find below the list of the delay_ms() function commented by myself. As you can see there is no memory operation for 0x0B address to modify the IT flags.
But you can see that the delay_ms() function uses always the same memory (static vars 0x77,0x78) for loop counters.
Let's say you call delay_ms() from your main() and the RTCC IT occurs when your program is in the delay_ms() part.
If you have another call to delay_ms() in your ISR, the static loop variables are equal to ZERO after the execution of delay_.
When the ISR returns to the delay_ms()@main() the static loop variables are corrupted.
You can simply check this short calculation: if you have a loop with a loop variable of 0x0178 for 1 ms delay(@4MHz), the delay time is cca. 174 msec(!) for 0x0000.
Plus your "1000" is also corrupted, so your "delay_ms(1000)" is physically a cca. 11300 seconds(!) delay after the first RTCC IT.
(ZERO is a legal loop counter because the routine uses DECFSZ {decrement first - check last} instruction).
This means that your program is practically dead.
Additional note: the rest of the LCD displays have an execution time of cca. 40usec for a simple write and cca. 1.6msec for ClearDisplay and Return Home commands.
Plus you have a print format instruction so it is easy to miss at least one RTCC IT under your RTCC ISR (ITs are disabled under ISR, of course).
It would be better to keep your ISR as short as possible (as suggested by MicroChip and CCS).
And now the list:
.................... delay_ms(100); // here is the C call
007A: MOVLW 64
007B: MOVWF 2A
007C: CALL 039 // call the 1ms base routine
/* The elementar 1 ms delay function */
0039: MOVLW 2A
003A: MOVWF 04 // place input parameter's address into FSR
003B: MOVF 00,W // get the parameter
003C: BTFSC 03,2 // ZERO?
003D: GOTO 04F // calling delay_ms() with 0 means that we are ready
003E: MOVLW 01 // we have a 16-bit counter @ 0x77-78
003F: MOVWF 78
0040: MOVLW BF
0041: MOVWF 77 // init the 16-bit counter
0042: CLRWDT // restart_wdt included in #use delay directive
0043: DECFSZ 77,F // inner loop
0044: GOTO 042
0045: DECFSZ 78,F // middle loop
0046: GOTO 040
0047: MOVLW 4A // init 8-bit value for extra loop
0048: MOVWF 77
0049: DECFSZ 77,F // an extra loop for correction
004A: GOTO 049
004B: NOP
004C: CLRWDT // restart_wdt
004D: DECFSZ 00,F // outer loop
004E: GOTO 03E
004F: RETLW 00 // end of loop</font>
___________________________
This message was ported from CCS's old forum
Original Post ID: 1066 |
|
|
Tomi Guest
|
Re: Interrupt in delay??? |
Posted: Mon Nov 12, 2001 9:22 am |
|
|
Halih�,
Elker�lt�k egym�st, előbb v�laszoltam, azt�n n�ztem meg a priv�t board-omat (�ltal�ban nem jelentkezem be, v�laszolni �gy is tudok).
A v�laszomban megtal�lod a delay_ms list�j�t, ebből l�thatod, hogy nincsenek letiltva az ITk. R�viden magyarul is a probl�ma oka:
nem rekurzi�, ink�bb korrump�lt mem�ri�nak h�vn�m, az ISR-ben a delay_ v�grehajt�sa UT�N a ciklusv�ltoz�k 0-ban vannak, innen akarja folytatni a main()-ben levő delay_ms().
Valami olyasmi, mintha azt �rn�m:
for (i=100;i>0;--i)
i = 65535;
A k�l�nbs�g csak annyi, hogy a p�ld�n�l �n ir�ny�tom, hogy a ciklusv�ltoz� mikor m�dosuljon a cikluson bel�l, HW-ben ez aszinkron m�don t�rt�nik. (Na, meddig tart egy ciklus, ha k�zben időnk�nt maximumra �rom a ciklusv�ltoz�t?)
Am�gy �n soha nem haszn�lom a delay_ms() rutinokat az LCD handlereimben (az LCD_INIT-et kiv�ve, de ITt csak ez ut�n enged�lyezek): kiadom a parancsot �s v�rok, hogy elm�ljon a BUSY a D7 vezet�ken. Ez persze egy plusz ellen�ll�st jelent a f�ld fel� ,hogy ha v�letlen�l nincs r�dugva az LCD...
Ezzel a m�dszerrel az �r�s mindig csak addig tart, am�g a HW ig�nyli. Tapasztalatom szerint egy 2X20-as LCD a n�vleges 4usec helyett 20�C-on kb. 2usec alatt k�szen van egy �r�ssal.
Ennek persze t�rt�neti okai vannak: amikor kezdtem, nem volt CCS C a gazdag p�ldat�r�val, volt helyette elősz�r Parallax Assembler, azt�n MPLAB-C, majd HiTech C, stb.... Műk�dő rutinokat pedig ugye nem piszk�lunk...
___________________________
This message was ported from CCS's old forum
Original Post ID: 1067 |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|