Electronic Projects, forums and more.

Go Back   Electronic Circuits Projects Diagrams Free > Electronics Categories > Micro Controllers


Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc.

Reply
 
LinkBack Thread Tools Display Modes
Old 30th January 2004, 06:13 PM   (permalink)
Default creating a clokck signal from a 18F452

Hello again!

Does anyone know how we can create un clock signal from tha 18F452 without using the spi module?
In fact i tried to create it with the spi module : i configure an interrupt to happen every 7 micro sec and each time the interrupt happens i write in the SSPBUF to create the clock signal. In practice, the clock signal is generated every 20 micro sec!!! Where is the issue?

Help me please!
__________________
French student is working and still working !!!
french_student is offline  
Old 30th January 2004, 10:12 PM   (permalink)
Default Re: creating a clokck signal from a 18F452

Quote:
Originally Posted by french_student
Hello again!

Does anyone know how we can create un clock signal from tha 18F452 without using the spi module?
In fact i tried to create it with the spi module : i configure an interrupt to happen every 7 micro sec and each time the interrupt happens i write in the SSPBUF to create the clock signal. In practice, the clock signal is generated every 20 micro sec!!! Where is the issue?

Help me please!
What frequency are you running the PIC at?. And what are you actually wanting?, just a clock signal out of an I/O pin?.
Nigel Goodwin is offline  
Old 30th January 2004, 11:52 PM   (permalink)
Default

The pic is running with a 20 MHz quartz.
I need to generate this signal because i communicate with an adc AD7827.
I hope you could help me.
Thanks.
__________________
French student is working and still working !!!
french_student is offline  
Old 31st January 2004, 06:51 AM   (permalink)
Default

Quote:
Originally Posted by french_student
The pic is running with a 20 MHz quartz.
I need to generate this signal because i communicate with an adc AD7827.
I hope you could help me.
Thanks.
Well at 20MHz each instruction cycle takes 200nS, so with interrupts every 7uS there's not much time to do anything - not even in the interrupt routine. You only have a maximum possible 35 instructions in that time, it will actually be less than that, as some instructions take 2 cycles.

Do you have some particular need for 7uS sampling, and what are you wanting to do with the data - again, you don't have any time to do anything with it.
Nigel Goodwin is offline  
Old 31st January 2004, 08:53 AM   (permalink)
Default

here is the code i try to realise in the interrupt programm:

output_low(PIN_AO);
output_high(PIN_A0);
spi_write(0x00);
data_converted[i]=spi_read();
i=i+1;

My issue is that even if i change the interrupt period, the clock signal is generated about every 20 micro sec. I don't understand why!
__________________
French student is working and still working !!!
french_student is offline  
Old 31st January 2004, 09:29 AM   (permalink)
Default

Quote:
Originally Posted by french_student
here is the code i try to realise in the interrupt programm:

output_low(PIN_AO);
output_high(PIN_A0);
spi_write(0x00);
data_converted[i]=spi_read();
i=i+1;

My issue is that even if i change the interrupt period, the clock signal is generated about every 20 micro sec. I don't understand why!
The first obvious point is - don't write it in C! - it's extremely time critical, you've only got an absolute maximum of 35 possible instructions (and that leaves no time for anything else). Writing it in C is likely to introduce extra instructions which will make the routine longer than necessary.

Writing the data into an array is also going to add extra time to the routine.

Please post the assembler code generated for the interrupt routine, so we can see how long it is - I suspect it's going to be too long!. It's also important when the interrupt is re-enabled, you would normally do this at the beginning of the interrupt, but in your case (with such fast interrupt times) you run the risk of interrupting an interrupt. If your interrupt routine is taking 13uS, and re-enabling interrupts at the end, this would explain why it takes 20uS.

One thing you could try, is not using interrupts at all, simply use the routine above in an endless loop - and see how long it takes like that (this will save you the time spend saving and restoring registers, and the call and return times). Presumably you are using PIN_A0 to strobe an output pin, in order to time the routine? - I often do that as well.
Nigel Goodwin is offline  
Reply

Bookmarks

Thread Tools
Display Modes





All times are GMT. The time now is 05:15 AM.


Electronic Circuits  |  Learning Electronics
Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.

eXTReMe Tracker