Counter Question
Spilly
Posts: 26
I have been playing around with propeller's counters. I believe I am counting rising edges. I am using an Arduino to send 24 pulses to pin 17 (PHSA) and then send one to pin 16 (PHSB). I want the propeller to count the pulses on 17 and to return PHSA to zero when PHSB increases by one. Seemingly randomly I am getting 23, 24, 25, or 26 (supposed to be 24) counts on PHSA before returning to zero.
I have played around with the timing but I unable to consistently get 24.
What am I doing wrong?
Here is the code on the propeller:
Here is the code on the Arduino:
I have played around with the timing but I unable to consistently get 24.
What am I doing wrong?
Here is the code on the propeller:
#include "simpletools.h" volatile int keepTrack; void test(); int main() { cog_run(&test, 80); while(1) { if(keepTrack !=24) { print("count = %d\n", keepTrack); pause(100); } } } void test() { int previous; CTRA = (0b01010<<26) + 17; FRQA = 1; CTRB = (0b01010<<26) + 16; FRQB = 1; while(1) { previous = PHSB; while(previous == PHSB) { //wait for reset //pause(100); } keepTrack = PHSA; PHSA = 0; } }
Here is the code on the Arduino:
void setup(){ pinMode(12, OUTPUT); pinMode(13, OUTPUT); } void loop() { int x = 0; for (x = 0; x < 24; x++) { delayMicroseconds(1000); digitalWrite(13, HIGH); delay(10); digitalWrite(13, LOW); delay(100); } digitalWrite(12, HIGH); delayMicroseconds(1000); digitalWrite(12, LOW); }
Comments
Thanks for reporting that. It could help someone in the future.
Amazing how some silly mistakes can cause loss of hair!