Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

creating a clokck signal from a 18F452

Status
Not open for further replies.

french_student

New Member
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 said:
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?.
 
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 said:
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.
 
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=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 said:
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=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.
 
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top