Speed output pcb v2

1 k/h * 1000 m / k * 1 h/ 3600 sec * 130 pulses/meter

Speed in kmh * 130/ 3.6 = pulses per second.

Apparently Tone fill interfere with pin 3 and 11 on arduino?

So it will work only with Cytron and his pwm must be connected to pwm2.(Invert pin function 3 and 9)

PulsePerM = 130;

Frequency = Speed * PulsePerM / 3.6;

Ok so am using pwm 2 to wake up the Cytron. That will still work if they are switched around? Could do like @Jhmach said and use a esp32 if that would be easier. Haven’t looked to see what that would take to hook that up.

I will try to build the code tonight, it should be way easier to adapt the PCB ino than add an other esp32.

Pat, I’m interested also. Look forward to your results

Here a first (already edited :wink: )version with the radar output:Autosteer_USB_v5_0.ino (25,6 Ko)
(to copy in the folder instead the original)

PWM1 and 2 have to be inverted: PWM2 is now for the Cytron pwm.
Can make funny things with IBT(maybe).

To be tested, I’m not 100% sure about the rounding at the radarFreq (int and float)

What I added:

//define the radar pin
#define RADAR_PIN 2 //PD2

//Radar pulses variables
const uint8_t pulsePerM = 130; // number of pulses per metre
uint16_t radarFreq = 0; // frequency for the output
const uint8_t radarLoop = 10; //Number of main loops before it ticks
uint8_t radarLoopCnt = 0;

 if (radarLoopCnt >= radarLoop)
    {
      radarLoopCnt =0;
      RadarOutput();
    }
    else radarLoopCnt ++;

//Radar
void RadarOutput()
{
  //Caculate the frequency
  radarFreq = gpsSpeed*pulsePerM*10.00;
  radarFreq /= 36;

  if (radarFreq > 40) tone(RADAR_PIN, radarFreq);
  else noTone(RADAR_PIN);
}

Edit I now added a GPS speed of 0.0 when communication with AOG is lost.

Thanks I will try that.

Well I’ve finally been able to work with this a bit. The hertz fluctuates quite a bit. I tried our trimble out and I get a constant hz. Like 130 hz at 5 mph and then up and down from there. I’m getting 8v from our Dickey John rate controller so I put in a 4n35. Not totally sure how those things work but I can’t read the hz on the other side of it.

You should have voltage and ground coming from your monitor to the 4N35. The 4N35 uses the PWM from the output and closes to the circuit between the monitor voltage and ground to create pulses.

Do you need a pull up resistor on the other side of the 4n35 to get a hz reading?

I could try that.


This is the how I hooked it up.

1 Like

Usually an open collector output will look like nothing with a meter or an oscilloscope unless you add a pull-up resistor to the +.

Do you know what to change. I’m getting speed on my monitor but it goes for about 5 seconds then speed 0 then 1second speed 0 then 15 seconds then speed 0 and just keeps doing that over again. I had my 4n35 connected wrong why I didn’t speed before.

I never tested it on a board, so I can’t see if it work for sure.
@Jhmach do you tested it? Do you already tested on your teensy board?

To make it more stable we could make a change to recall tone() only if the speed changed X percent.

//Radar
void RadarOutput()
{
  //calculate the deadband.
  uint16_t pulseUnder = radarFreq * 0.95
  uint16_t pulseUpper = radarFreq * 1.05

  //Caculate the frequency
  radarFreq = gpsSpeed*pulsePerM*10.00;
  radarFreq /= 36;

  if (radarFreq > 40) 
  {
   if(radarFreq < pulseUnder || radarFreq > pulseUpper)
   {
    tone(RADAR_PIN, radarFreq);
   }
  }
  else noTone(RADAR_PIN);
}

Speed Test MPH.zip (44.0 KB)
This is the Teensy code I’m using. It has the speed pulse in it and works fine. No interruptions to the output that I’ve noticed. I’ve only ran it for an hour or so.

// Speed Pulse variables
unsigned long prev_PWM_Millis = 0;
#define speedPulse_Pin 36
#define pulseCorrection 1.00 //Normal is 130pulse per meter, enter % correction in here

// Speed pulse
if (millis() - prev_PWM_Millis > 100)
{
prev_PWM_Millis = millis();
//130 pp meter, 3.6 kmh = 1 m/sec or gpsSpeed * 130/3.6 or gpsSpeed * 36.1111
//gpsSpeed is 10x actual speed so 3.61111
//float speedPulse = gpsSpeed * 3.61111;
//speedPulse = speedPulse * pulseCorrection;
//tone(speedPulse_Pin,speedPulse);

// gpsSpeed is in 10x km/h 
// speedPulse in 10x mph?
float speedPulse = gpsSpeed * 0.621371192 * 10;
tone(speedPulse_Pin,speedPulse);

}


This might be worth remembering

In my arduino code it updates at 2Hz. Edit: 5hz

I loaded the code and have been playing around with the numbers but so far doesn’t seem like it makes much difference. For what we need it for it would probably work but if there are some more ideas to try I can do more testing.

I changed this 100 and then it still would cut out every once in awhile but at 150 it doesn’t. Will other parts of the program not work now?

//loop time variables in microseconds
const uint16_t LOOP_TIME = 150; //50Hz
uint32_t lastTime = LOOP_TIME;
uint32_t currentTime = LOOP_TIME;

You should leave the LOOP_TIME at 20 ms. 50hz

You must call the RadarOuput() fonction just each X loop count by adding something like this in the timed loop:

 if (radarLoopCnt >= radarLoop)
    {
      radarLoopCnt =0;
      RadarOutput();
    }
    else radarLoopCnt ++;

If you use the code in post 15 change the radarLoop instead, 10 is 5hz, 25 2hz, 50 1hz, 100 0.5hz.

//Radar pulses variables
const uint8_t pulsePerM = 130; // number of pulses per metre
uint16_t radarFreq = 0; // frequency for the output
const uint8_t radarLoop = 10; //Number of main loops before it ticks
uint8_t radarLoopCnt = 0;