Ahhh Counters and modes..
TJHJ
Posts: 243
Im having a hell of a time trying to get these counters set up correctly.
So here is what I am trying to do, on condition pin 15 goes low, the timer starts and counts until pin 15 returns to high.
So only using 1 pin, I am trying to set the Apin to be my detector pin.
after reading the doc on counters I still cant seem to make it work correctly I think it is in my shift in for the pin
But this does not seem to be working, Any ideas and I get the mode selection but where does 26 come from, I only used it because it was used in the example in the counter docs, for setting a Apin value.
Thanks again for all the help.
So here is what I am trying to do, on condition pin 15 goes low, the timer starts and counts until pin 15 returns to high.
So only using 1 pin, I am trying to set the Apin to be my detector pin.
after reading the doc on counters I still cant seem to make it work correctly I think it is in my shift in for the pin
' mode PLL ctra := %01100<< 26 + 15 'Establish mode (APIN=15 and no b pin feedback) and APIN. Where does the 26 come from? frqa := 1 'Set FRQA so PHSA increases by 1 every clock. dira[noparse][[/noparse]15]~ 'Set APIN to input 'Start the count WaitPNE(0,|< 15,0)' Wait for Pin 15 to be high, to reset the counter while its high. Phsa := 0 ' Reset the counter WaitPNE(0,|<15,0) ' Wait until the end of the pulse Count := Phsa ' Store the Phas A value into count. Wait for the next start pulse Repeat
But this does not seem to be working, Any ideas and I get the mode selection but where does 26 come from, I only used it because it was used in the example in the counter docs, for setting a Apin value.
Thanks again for all the help.
Comments
You shift the mode (%01100) 26 bits left to set it at the right Position in the ctra and add the Pin Number (15) into the lower 5 bits, so this is correct!
Wrong are the WAITPNE commands. Try this:
WAITPEQ(|<15, |<15, 0) for waiting for High
WAITPNE(|<15, |<15, 0) for waiting for Low
Andy