Shop OBEX P1 Docs P2 Docs Learn Events
Counter Question — Parallax Forums

Counter Question

SpillySpilly Posts: 26
edited 2014-06-27 20:11 in Propeller 1
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:
#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

  • SpillySpilly Posts: 26
    edited 2014-06-27 08:36
    Felt pretty silly after solving this. Adding a ground between the two was the fix. I assumed having them both connected via USB to the same computer would be sufficient, however, it was not.
  • PublisonPublison Posts: 12,366
    edited 2014-06-27 08:39
    Spilly wrote: »
    Felt pretty silly after solving this. Adding a ground between the two was the fix. I assumed having them both connected via USB to the same computer would be sufficient, however, it was not.

    Thanks for reporting that. It could help someone in the future.

    Amazing how some silly mistakes can cause loss of hair! :)
  • NWCCTVNWCCTV Posts: 3,629
    edited 2014-06-27 20:11
    Amazing how some silly mistakes can cause loss of hair!
    Agreed. Back in 2005 when I first started using the Basic Stamp I was trying to control a stepper motor with a Stepper controller that I built. After several days of testing and tracing wires it dawned on me. Ground everything to the Homework board. Once I did that it all worked perfectly.
Sign In or Register to comment.