|
Post by swiper on Jul 29, 2021 7:46:54 GMT
Hello, I have to synchronize a signal with a clock(pin 19) for about 300ms. A part of my code :
if(Fast_digitalRead(19) == HIGH)
{ for(int x=0; x < 1300000; x++) {
P10_OUT.U = 0b00111110; P10_OUT.U = 0b00111110; P10_OUT.U = 0b00111110; P10_OUT.U = 0b00000000; P10_OUT.U = 0b00000000; P10_OUT.U = 0b00000000; } } When I check my Logic Analyzer, until 2ms there is no problem, but after this time, the edges do not arrive in the right time. They are desynchronized. Maybe something happens after this time but i can't find what. Someone has an idea ? Thank you in advance.
|
|
|
Post by Admin on Jul 29, 2021 7:49:29 GMT
Try using core 1. Core0 has a 1ms interrupt running permanently to generate the Arduino-style timebase. This could cause a disturbance to your port write sequence. core 1 has no interrupt running so it should be more stable.
|
|
|
Post by swiper on Jul 29, 2021 8:42:02 GMT
Thank you for your reply. I am already using the core 1.
|
|
|
Post by Admin on Jul 29, 2021 9:11:51 GMT
Really using a loop is not the best way to generate a long sequence of signals. At the very least, there will be a gap between each loop. What frequency are you expecting?
|
|
|
Post by swiper on Jul 29, 2021 9:19:31 GMT
Ok, I have to send the port at 4 MHz. If I can't use a loop for doing this, what am I suppose to use?
|
|
|
Post by Admin on Jul 29, 2021 16:32:58 GMT
The tone() function can produce 4MHz for a defined time:
/* Pin4 has 4MHz for 300ms */ tone(4, 4000000, 300);
|
|
|
Post by swiper on Jul 30, 2021 6:55:15 GMT
Hi, I tried, but it's the same result. There is something happens and the tone signal become desynchronize. How can I put my code to the first place of priority ? I don't know which tasks are constantly running in the background. Thank you in advance for your reply.
|
|