CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

Re: Interrupt in delay???

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
xvi.lajos



Joined: 06 Sep 2003
Posts: 12
Location: Hungary

View user's profile Send private message Send e-mail

Interrupt in delay???
PostPosted: Tue Nov 06, 2001 7:18 am     Reply with quote

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???
PostPosted: Tue Nov 06, 2001 1:06 pm     Reply with quote

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

View user's profile Send private message Send e-mail

Re: Interrupt in delay???
PostPosted: Mon Nov 12, 2001 5:58 am     Reply with quote

:=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

View user's profile Send private message Send e-mail

Re: Interrupt in delay???
PostPosted: Mon Nov 12, 2001 6:13 am     Reply with quote

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???
PostPosted: Mon Nov 12, 2001 8:53 am     Reply with quote

<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???
PostPosted: Mon Nov 12, 2001 9:22 am     Reply with quote

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
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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