i need this interrupt because i use the spi module to generate a clock signal but i need to generate it every 7 us.
As already mentioned (in this thread, and the other one) it looks very doubtful you can do what you want in 7uS, even writing in assembler - in C you don't have a hope!. Don't forget, it's only the time critical section you would need to write in assembler, the rest of the program could be in C - so at the very most, you only have less than 35 assembler commands to write.french_student said:Writing in asm will be difficult for me : i don't have lot of time (the project must be finished in last week' beginning) and i don't remember well how we write in asm. So i'll try to make it in C.
You should be writing your code in C if you are comfortable with that. However, as I said, the interrupt service routine should be written in assembly to allow you to to control exactly the number of program instructions it will use up. I am not familiar with PIC C because I have been writing code in assembly for PICs but I would think PICC should allow you to mix a small amount of assembly code with C code. The ISR written in assembly could be as short as the ff.Writing in asm will be difficult for me : i don't have lot of time (the project must be finished in last week' beginning) and i don't remember well how we write in asm. So i'll try to make it in C.
ORG 8 ISR: BSF SCLK BRA $+2 BCF SCLK RETFIE FAST
I already gave the code for the ISR above. I think you should be able to initialize the registers using C.A question for motion: where and how can i realise all the steps you gave me to use TMR2 interrupt. In fact to create my file .c i use PIC C W and i supposed that when i configured my project all the steps were realised automatically, but apparently they weren't! So must i write them in c in the main part of my program? What are the codes?
With a 20Mhz crystal you can't because of the odd timing. However, if operate at 40Mhz you can. If you replace the crystal with a 10Mhz one and select "HS oscillator with PLL enabled/Clock frequency = (4 x FOSC)" in the config register1, you should get a 40Mhz clock. With 40Mhz, you can initialize the period register PR2 with the value 35. This should give you 7us SCLK clock period on SCLK as per datasheet.To motion again: i do use the RC3 pin to generate the clock signal. In fact, from what i understood reading the datasheet concerning the spi module, the clock signal is generated when we write something in the buffer SSPBUF. That's what i'm doing and apparently it works, i do have the clock signal with the frequency i programmed. The issue is the time between two successive clock signal (7 us is what i need).