.ino for PCB+MD13S+Danfoss valve

Great, and wow that is a nice build you have in that box. Is back plate acting as cooler for ibt_2?

Edit dec 2020: in post 66 Kaupoi also got it working with 4.3.10

Thanks. Had similar box and parts in use last summer with hydraforce valve. Never had any issues with it. Valve solenoid works with low amps so no extra heat sink needed.

I have my pcb v2 and Danfoss system working with cytron md13s. Brian was right, put the pwm signal from pwm1 and the ground. If the dir is not connected it puts the signal to MA output. With 5v to dir, it switches to MB. I want to put 5v to pwm2 to energize an ssr relay to send 12v to Udc on valve. I just connected direct for testing. I haven’t been able to get code to work with v4.1, 4.1.12, or 4.3.10, so I’m still using coffeetrac button. Its works fine but I can’t adjust anything from AOG. I tried using an ino that was on github, cant remember who’s, but I cant seem to get a pwm signal or 5v from dir and pwm2 out of any of them.
Also when I use v4.1 or v4.1.12, the screen spins when I turn roll from mma 1d. I sat the rate to 8 from GPS but I haven’t been able to figure out how to set it for gga and vgt only from the co99 f9p. I’m hoping that is what my problem is.
Short astory long, one ibt2 quit working. Another didn’t work out of the box, and the cytron works well and the steering was a lot more stable, it seems with v4.1 and v4.1.12.
If anyone has any help, for any of these problems, I would appreciate it.

Got .ino working in v4.4.12 with danfoss valve. Also got rtk base up and running.
Proportional is at 100, output is at 180 or so, min pwm is at 26. Angle per degree is 24.
Steering is pretty decent but seems to be busy all the time.
The gains are a lot higher than they were with coffeetrac and ibt.
Should I change pwm frequency, or is there something else I’m missing ?

Have been trying to modify 4.3.10 ino to work with danfoss valve. I cant seem to get pwm1 to give voltage. Dir works on switch, but nothing out of pwm1. Could sure use some help

Did you use this part of ino made by JhnP?

JohnP

28 Apr

I am using an IBT2 to control the steering on an 8330 with Danfoss. I have 12v on the Udc pin, and the pwm signals from the arduino sets the Us. 6V steers straight ahead, 9V to the left and 3V to the right. I have some pics JD 8230 hydraulic steering . Its not a clean setup but it has been working nice on my one field test cultivating. @theGtknerd i noticed while i was originally setting up that with 1 hz on gps it was all over the place, but now at 10hz its smooth. Any chance that could be an issue for you? I have been using v3.9 with the coffeetrac button ino. I think that with the code written like i have it below that it seems to be working fine on my bench test setup but no actual field experience yet. I am a total arduino beginner so if anything in this coding seems wrong please let me know.

Autosteer PID

void motorDrive(void)
{
// Used with Cytron MD30C Driver
// Steering Motor
// Dir + PWM Signal
if (aogSettings.CytronDriver)
{
pwmDisplay = pwmDrive;

  //fast set the direction accordingly (this is pin DIR1_RL_ENABLE, port D, 4)
  if (pwmDrive >= 0) bitSet(PORTD, 4);  //set the correct direction
  else   
  {
    bitClear(PORTD, 4); 
    pwmDrive = -1 * pwmDrive;  
  }

  //write out the 0 to 255 value 
  analogWrite(PWM1_LPWM, pwmDrive);
}

else
{ // Danfoss: PWM 25% On = Left Position max (below Valve=Center)
// Danfoss: PWM 50% On = Center Position
// Danfoss: PWM 75% On = Right Position max (above Valve=Center)
// Used with IBT 2 Driver for Danfoss
// Dir1 connected to BOTH enables
// PWM Left + PWM Right Signal

pwmDrive = pwmDrive / 4;
pwmDrive = pwmDrive + 128; // add Center Pos.

pwmDisplay = pwmDrive;
analogWrite(PWM1_LPWM, pwmDrive),  // apply varying voltage to the Usignal valve pin
digitalWrite(PWM2_RPWM, HIGH);     // apply 100% DC current to Udc

}
}

I also experimented with one (but stolen from @grabik ) , where I would let AOG setting be for Cytron, and want PWM out on PWM1
12V Power for Danfoss valve should be regulated and not through motordriver
I tried to edit autosteer_USB_4.3.10 PID.ino and it does compile but I don´t know if it works.

I put al new stuff between Start Danfoss and End Danfoss
And commented out what I don´t think is needed by //lvdfoss

Edit dec 2020: in post 66 Kaupoi made it work with 4.3.10


void calcSteeringPID(void) 
 {  
  //Proportional only
  pValue = steerSettings.Kp * steerAngleError;
    
  //pwmDrive = (constrain(pValue, -255, 255));
  pwmDrive = (int)pValue;

  //steerSettings.lowPWM
  
  errorAbs = abs(steerAngleError);
  int newMax = 0; 
   
  if (errorAbs < LOW_HIGH_DEGREES)
  {
    newMax = (errorAbs * highLowPerDeg) + steerSettings.lowPWM;
  }
  else newMax = steerSettings.highPWM;
    
  //add min throttle factor so no delay from motor resistance.
  if (pwmDrive < 0 ) pwmDrive -= steerSettings.minPWM;
  else if (pwmDrive > 0 ) pwmDrive += steerSettings.minPWM;

  //limit the pwm drive
  if (pwmDrive > newMax) pwmDrive = newMax;
  if (pwmDrive < -newMax) pwmDrive = -newMax;

  if (aogSettings.MotorDriveDirection) pwmDrive *= -1;
 }

//#########################################################################################

void motorDrive(void) 
  {
    // Used with Cytron MD30C Driver
    // Steering Motor
    // Dir + PWM Signal
    if (aogSettings.CytronDriver)
    {     
      pwmDisplay = pwmDrive;
 //Start Danfoss=========================================
//#if (Output_Driver == 4) //PWM 50% if pwmDrive ~ 0 , PWM 0% if pwmDrive -255 …
//void motorDrive(void)
// Used with Danfoss valve 50% pwm off valve

 pwmDanfoss = (pwmDrive/2)+128;
if(pwmDanfoss > 195) pwmDanfoss = 195; // max 0,75 U , PWM 75%
if (pwmDanfoss < 1 ) pwmDanfoss = 48; // min 0,25 U ,PWM 25%

analogWrite(PWM1_LPWM, pwmDanfoss);
}
//#endif

//End Danfoss==========================================
      
  
//lvdfoss      //fast set the direction accordingly (this is pin DIR1_RL_ENABLE, port D, 4)
//lvdfoss      if (pwmDrive >= 0) bitSet(PORTD, 4);  //set the correct direction
 //lvdfoss     else   
//lvdfoss      {
//lvdfoss        bitClear(PORTD, 4); 
//lvdfoss        pwmDrive = -1 * pwmDrive;  
 //lvdfoss     }
  
//lvdfoss      //write out the 0 to 255 value 
//lvdfoss      analogWrite(PWM1_LPWM, pwmDrive);
 //lvdfoss   }

The PID.ino continues normal from here.

I’m also using ino from @grabik. I did uncomment
pwmDrive = (constrain(pValue, -255, 255))
And commented pwmDrive = (int)pValue
Also changed out pwmDrive > newMax to 255
And several other changes
I does verify but I get no pwm out

By that you mean that output from Dir changes every time you toggle the autosteer switch?

I don’t have a cytron but this is what I’m using with ibt2. There are no changes from what I posted earlier Autosteer_USB_4.3.10_8330 - Google Drive

1 Like

Yes, I have it connected so the Us goes to mB on cytron. Just another safety so there is no power to danfoss except with switch engaged

You answer yes, so it is not the problem with “must enable steerswitch once” even when manual/no steer switch is chosen in AGOpen setup.
Do you have a double Cytron? I believe the Dir pin change between mA and mB on the MD13s
So sometimes it is the PWMvalue PWM1_Lpwm that goes to mB and sometimes there is nothing, because not both mA and mB can output at same time.

Correct. I have connection from mB to Us, nothing on mA. When steer switch is engaged, cytron receives 5v from dir switching it from mA to Mb for output. This way there is no voltage to Us until steer switch. Also i have a opto relay with 12v from board, connected to Udc of valve. pwm2 is connected to relay, so relay energizes at steer switch true and sends 12 to Udc of danfoss. This way there are 2 safeties. I can get dir and pwm2 to work, but I continue to fail to get pwm1 to send any voltage.
The problem is that I have never written arduino code, so its probably something simple that I’m overlooking. Also was wondering if I should wait for Brian to release his new version, and start fresh with it, lest for some reason this ino not work with the new version.

Finally! A working INO file for AOG v4.3.10 and Danfoss!
Thank you very much. :+1:

20201223_203757

1 Like

I downloaded it. It is the same as the one I did but couldn’t get working, except the bitClear(port D). I left that out on mine. What does it do ?

I have loaded your ino on nano. When I choose ibt2, I get voltage from pwm2. It is always high, and doesn’t go low when I toggle steer switch. Dir toggles low to high, and pwm1 has variable voltage. Everything works, except pwm2. I have it connected to opto relay to send 12v to Udc when steer switch engaged. Presently it is sending power to valve constantly. Don’t understand the code well enough to change it, but I am looking at lines 162 to 189 in the main file, where it calls for output depending on cytron and active high. Can you confirm ?
Edit
Maybe line 189, if I take
if (aogSettings.cytronDriver) out
and just leave pinmode pwm2 output?
Edit
Just got back from testing. Left 12v to valve all time for now. Works well on 4.3.10. Steering was responsive but still smooth. Kept everything mostly the same but lowered proportional to 60 from 180, and output to 200 from 255. Left pwm at 490hz for now, but will test both higher and lower after Christmas. I believe it is very usable at 490 though.
Thanks John

If you have something working for Cytron maybe you can post your .ino to this thread and that will be helpful for anyone wanting to go your route. Glad it’s working for you. When I got mine working that was good enough for me. I was copy/pasteing and trying to learn anything I could. Big thanks to coffeetrac for originally getting danfoss working

I am using the ino that you posted on Google drive a few postes earlier.
For Cytron md13s :
Connect 5v and ground to cytron, and use dir to switch sourse from mA to mB, that way no power to valve until switch is engaged. Connect mB to valve Us pin. Put pwm1 to pwm on cytron. Use pwm2 to opto relay for 12v to valve Udc.
With this ino, module configuration set to ibt2, pwm2 is 5v always. I want to set it in the code like it is when module configuration is set to cytron. When set to cytron, pwm2 turns 5v when steer switch is engaged, and 0v when disengaged. This way when steer switch is engaged, 5v from pwm2 energizes opto relay, and sends 12v to valve Udc pin. So there is no power to valve Udc or Us pins until steer switch is engaged. Just a simple double safety for when driving on the road.
Edit
Just wondering if, instead of changing pwm2 code, I could just change if(aogSettings.cytronDriver) to if(aogSettings.ibt2)
?

Sorry I’m not much help with the coding. I was just happy to get it working for me. I power off the 12v relay manually when driving on the road for safety.

Edit2: But it seems you want triple protection?
Suppose you already have a switch to power the whole setup: no1 protection on road
Turn off steer switch in AOG: no 2 protection
Relay on PWM2: no 3 protection

In my Hydraulic IBT_2 setup the relay for 6/2 valve is on the DIR or also called R/L_enable, so I have only 2 steps of protection: Switch for whole system and that relay.

Maybe it would be enough just to have your opto-relay on same pin as DIR in the cytron setup

I think the reason that pwm2 stay 5v is this line in John’s ino pwm2=high
edit: in his AutosteerPID.ino last line:
digitalWrite(PWM2_RPWM, HIGH); // apply 100% DC current to Udc