Problems with timer. CNT
DarkGFX
Posts: 17
Hello everyone I'm new to Propeller chip and SimpleIDE and have some questions about a part of my program.
I have two COG's that is supposed to save the time from CLK register when they their input is "HIGH".
I tough it was working pretty good, but when I connected the input for both of them together and triggered them at the same time, I got a different CLK time on both of them.
Code for one of the cogs, both are equal:
So my question is, why are these two cogs reading different CLK times when they have the same function?
I have two COG's that is supposed to save the time from CLK register when they their input is "HIGH".
I tough it was working pretty good, but when I connected the input for both of them together and triggered them at the same time, I got a different CLK time on both of them.
Code for one of the cogs, both are equal:
// Function that can continue on its // own if launched into another cog. void microphone1(void *par) // microphone1 keeps going on its own { unsigned temp_tid1; // local variable for reading CLK while(1) // Endless loop { if(input(1) == 1){ // Check if Input 1 is triggerd temp_tid1 = CNT; // save CNT to internal ram! L1 = temp_tid1; // L1 sends ram value to global ram trigg1 = 1 ; // send triggerd value to main us_delay(50); // Wait 50us <- hommade delay function trigg1 = 0; // reset trigger } } }
So my question is, why are these two cogs reading different CLK times when they have the same function?
Comments
because the user TxRX and I are working on the same project, he is trying to write it in SPIN while I try to write it in C.
So we are both trying to find a good solution for the "no sync" problem and hope someone could come up with a good answer.
While some of the solutions in the other thread is good, I will have a problem implementing these for 6 cogs that will be the final project.
So my question: is there a good way to synchronize the clock for all the cogs?
Your approach needs some refinement. Mainly, you should consider using the waitpne() macro instead of input().
I show a program that does this below.
@kuroneko, Could you go into more detail about why the counts read immediately after waitpne() by different COGs would be different by 2? I know that if we simply log the value received by INA after syncing on CNT that the count difference can be as low as 1.
Eric
Ya, it works.
Eric, I'm sorry I forgot that CMM/LMM read instructions from HUB (which you did point out ... more coffee!).
Simply adding "__attribute__ ((fcache)) " solves it.
Thanks for making it clear.
COG 1 CNT 0
COG 2 CNT 0
COG 3 CNT 0
COG 4 CNT 0
COG 5 CNT 0
COG 6 CNT 0
COG 1 CNT b939c109
COG 2 CNT b939c109
COG 3 CNT b939c109
COG 4 CNT b939c109
COG 5 CNT b939c109
COG 6 CNT b939c109
COG 1 CNT 0
COG 2 CNT 0
COG 3 CNT 0
COG 4 CNT 0
COG 5 CNT 0
COG 6 CNT 0
COG 1 CNT be266769
COG 2 CNT be266769
COG 3 CNT be266769
COG 4 CNT be266769
COG 5 CNT be266769
COG 6 CNT be266769
This a lot of good information, and I have now fixed my sync problem!
thanks to you're code jazzed, I can now see clearly that I need to learn more about how to initialize the COG's.
Could care to explain you're method to me?
There are different ways to start a COG.
1. Use cognew to start PASM, GAS, or COGC running in a COG.
https://sites.google.com/site/propellergcc/documentation/libraries/propeller-h-library#TOC-cognew
2. Use cogstart to start a C function which runs in the CMM/LMM interpreter.
https://sites.google.com/site/propellergcc/documentation/libraries/propeller-h-library#TOC-cogstart
I used the cogstart method since it can all be in one file. The stack is a two dimensional array where the stacks are kept for each COG. The mailbox structure is used for communications with the COGs. I set a target clock CNT for each COG to find before doing cogstart.
The critical piece that makes the display show the exact counts is to make sure that each pin monitor sits entirely in the COGs' cache overlay area.
One more thing, I just swapped out my if() function for the waitpne, but I do not quite understand how to set it up.
If I want it to wait for HIGH on pin 1, how do I write this?
I'm going to try this as soon as I come hope, really exited!
Thank you so much, I really appreciate all the help you are giving me!