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);
}
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;
Yes I’m using the code you sent. Not sure if I’m not catching on to what you meant but it still does not work. Seems like leaving it on 10 gets the most stable speed.
What happens when the LOOP_TIME gets changed from 20 to 100 ? Seems like thats the only way that it works.
Just having it running on the bench I couldn’t notice anything.
LOOP_TIME is the time in ms between each loops.
radarLoop is the number of loop it take before calculate the output.
In real life autosteer will not run as smooth at 100 ms than 20 ms, controlling the wheel is much more precise with fast WAS readings and motor adjustments.
There is maybe something wrong in my code. Putting a “radarLoop” value of 50 should do the same than the LOOP_TIME of 100.
I will try to mount a board to test it in the next days.
Ok makes sense. What I found at 100ms the hz output at 5mph is around 280 and is very stable. At 20hz most of the time its between 45 and 55 but then it’ll go down to 25 or up to 80. Every bit though it’ll jump to 130 and then it must stall it out? as the speed goes to zero after.
if (radarLoopCnt >= radarLoop)
{
radarLoopCnt =0;
RadarOutput();
}
else radarLoopCnt ++;
In here I changed the zero to 50 and it stabalized the hz but it still would spike up to 130 but not as often and the speed would still 0.
Don’t know if any of this helps you.