.ino for PCB+MD13S+Danfoss valve

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

I was wondering about using dir for both but unsure how much current . Would rather just continue with pwm2 being it’s already there and connected. I never power off pcb from field to field, is why I am using pwm2.
Yes, I will uncomment that line and try it. Thanks

I tried uncommenting the pwm2 line. With no change. As soon as the sketch is uploaded, pwm2 goes to 5v. I did get an error when verifying though. The analogWrite line just above it is finished with a comma instead of a semicolon. Changed that and it verified. But didn’t help. Also tried to swap the 1 with 0 in the main file around 489 I think, to turn off pwm2, and took out if cytronDriver. No change. I’m just not finding where it is signaling that pin to go high.

@Jhmach I just took a quick look at @JohnP 's code.

To use the pwm2 the way you want you should remove the “if (aogSettings.CytronDriver)” in watchdogTimer like this:

if (watchdogTimer < 10)
      { 
       //Disable H Bridge for IBT2, hyd aux, etc for cytron
        //if (aogSettings.CytronDriver) 
        //{
          if (aogSettings.isRelayActiveHigh) 
          {
            digitalWrite(PWM2_RPWM, 0); 
          }
          else  
          {
            digitalWrite(PWM2_RPWM, 1);       
          }
        //}
        //else
        digitalWrite(DIR1_RL_ENABLE, 1);     
        
        steerAngleError = steerAngleActual - steerAngleSetPoint;   //calculate the steering error
        //if (abs(steerAngleError)< steerSettings.lowPWM) steerAngleError = 0;
        
        calcSteeringPID();  //do the pid
        motorDrive();       //out to motors the pwm value
      }
    else
      {
        //we've lost the comm to AgOpenGPS, or just stop request
        //Disable H Bridge for IBT2, hyd aux, etc for cytron
        //if (aogSettings.CytronDriver) 
        //{
          if (aogSettings.isRelayActiveHigh) 
          {
            digitalWrite(PWM2_RPWM, 1); 
          }
          else  
          {
            digitalWrite(PWM2_RPWM, 0);       
          }
        //}
        //else
        digitalWrite(DIR1_RL_ENABLE, 0); //IBT2
                
        pwmDrive = 0; //turn off steering motor
        motorDrive(); //out to motors the pwm value
        pulseCount=0;
     }

And in the “autosteerPID” tab you will have to remove the “digitalWrite(PWM2_RPWM, HIGH);”(at the bottom.)

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

Now you should be able to use the cytron(with IBT2 in AOG setting) and pwm2 should switch between lo and hi, with the possibility to invert in AOG.

From what I reed from your previous posts you did similar things but maybe not exactly this?
I have no danfoss valve to test it!

Thanks Pat. Yes I took it out, but with no real understanding of the code syntax, I couldn’t get it to verify. I will make the changes you have written and give it a try.

Pat, I loaded the ino with your edits, didn’t get to drive due to weather, but everything works as it should. Voltage goes high on pwm2, and dir at steer switch. Pwm1 read half voltage, as it should.
Brian, can we get this code put on github, so all the Danfoss guys can have access, and get switched over to 4.3.10 ?
If you will tell me how to get the code to you, I will be glad to do so. Thanks

1 Like

@Jhmach here is a version that should work with both Cytron and IBT. check “Cytron” in AGO for use with Cytron. It also should use a frequency of 980hz for pinD3, it’s closer to the 1000hz recommended by Danfoss than the default 480 hz.

Autosteer_USB_4.3.10_8330.zip.txt (100,6 Ko)

You can test it to see if it work.

Pat, I know I need to take the txt off to unzip, but when I click on it, it downloads automatically as a text. Can you advise ?