Changing SDA Pin mode in software

Hi. I’m using a TIC 36v4 to control a stepper motor that drives my dome around. I use the limit switch reverse function on SDA to allow the dome to find Home. The snag arrives if I want to travel beyond the switch position as of course a dome can continuously rotate. So I decided I could maybe use the set_sda_pin_mode function to turn SDA off as a limit switch after the homing had been done and turn it back on as a limit switch when I need it for homing. I only use the home function at most once per evening viewing, and often not even then !
However try as I might I cannot get this switching to actually happen. I’m verifying the pin status by using the Pololu Tic control center having run code to change the pin mode. The pin mode never changes. I’ve also tried using

bool v = m_tic.set_setting_byte(61, 9);
to set it as a limit switch and then

bool v = m_tic.set_setting_byte(61, 2);
to disable the limit switch

and again nothing changes when I check in the control center. I’m using C# in Microsoft Visual Studio

Any suggestions
Thanks
Tim

Hello, Tim.

It looks like you’re trying to use an offset of 61 (which is 0X3D in hex); please note that this is the offset value for the TX pin configuration. For the SDA pin configuration, you should be using an offset of 60 (0x3C in hex).

Are you using a C# library for the Tic, and if so, could you link to it? Alternatively, could you post the code for your set_setting_byte() function?

Brandon

Hi Brandon

Thank you for the response

My mistake, in the actual code I did use the correct address. This was a test to see if I could change any of the pins modes, which I couldn’t

Yes I am using the C# library for the TIC. I tried using the method to directly change the SDA pin but that didn’t work either and actually returned “false”.

Regards

Tim

Can you post a link to the C# library you’re using?

Brandon

Hi Brandon
I’m using the TicDotNet library from here GitHub - jigarciacortazar/TicDotNet: .NET access to Pololu TIC stepper controllers Written in C #

A line of code that uses the set_sda_pin_mode function to change the mode to “Limit switch forward” or “Limit switch reverse” would be very welcome, with another to set the pin back to some other value when it’s not homing. The pin also needs to be set to high as the switch closes when it senses the home position.
Whenever I call this function it returns “false” so I’m clearly doing something wrong. I’m using C# in Visual Studio Code 2022.

Other than that my Astronomy Dome software works a treat under the ASCOM protocol. What I wish to do is have the limit switches only active when I am homing, not when I’m slewing. If active when slewing they prevent the dome from passing through the home position. The home position is used to ensure the dome is synced precisely to north so it accurately follows the telescope as it slews.

Thank you for any help you can offer
Tim

Hello.

TicDotNet does not have a method named set_sda_pin_mode, and you haven’t shown us the code you wrote to call that function, so it is still unclear what code you were trying to run.

You should be able to change the function of the SDA pin via USB using the Tic’s “Set setting” command and its “Reinitialize” command. However, please see this warning about “Set setting” from the “Command reference” section of the Tic user’s guide:

Be careful not to call this command in a fast loop to avoid wearing out the Tic’s EEPROM, which is rated for only 100,000 write cycles.

–David

Thank-you for the tip about the Reinitialise command.

The library I have says “Copyright 2019 Jose Ignacio Garcia de Cortazar” It has the following function

public bool set_sda_pin_mode(byte sda_pin_mode)
{
return transfer(request: TIC_SETTING_SDA_CONFIG, value: sda_pin_mode);
}

and the following constant

const int TIC_SETTING_SDA_CONFIG = 60;

It is called TicDotNet.cs. I did not write any of it and it would seem to have been written by the same person as the current one on github. Where I got the version I use I’m not sure as it was a while ago now. It does seem more complete than the current one on GitHub though.

Regards
Tim
TicDotNet.cs (35.0 KB)

Trying to set the pin modes in C# is driving me nuts. But then I’m an airline pilot not a software engineer !

Looking at the documentation I decided I’d be better of using the RX or TX pins as limit forward or limit reverse switches when needed for homing. Outside of the homing requirement I don’t want them to stop the motion so need to set them back to default.
I’m using Visual Studio 2022 to generate and ASCOM drive for a telescope dome, at least that’s the final aim. To test things out I’m using the code from GitHub - jigarciacortazar/TicDotNet: .NET access to Pololu TIC stepper controllers Written in C # (linked to from the Pololu website) which compiles and runs ok.

I then use the Pololu Tic Control Center to test the pin modes. Initially I use the control center to set all pin modes to default. Then I disconnect. I’ve modified the TicDotNet code to have an additional button on the form. When clicked it performs the following code

private void button1_Click(object sender, EventArgs e)
{   
    m_tic.set_setting_byte(0X3D, 9);
    m_tic.reinitialize();            
}

I then disconnect from the TIC and reconnect to the Pololu TIC control center expecting to see that the TX Pin Mode has changed to Limit Switch Reverse, but it stays at default. I try the command of
Device: Reload setting from device
to no effect.

Please could you write the code that should be in the above Button Click function that allows me to change the TX button mode. Code that allows me to read the mode into a variable would also be helpful

Thanks
Tim

Thank you for providing the code you are running. The set_setting_byte function in TicDotNet.cs is incorrectly setting the wValue and wIndex fields of the USB control transfer. You should be able to fix the function by changing it to:

  public bool set_setting_byte(int address, int byte_value) {
    return transfer(request: TIC_CMD_SET_SETTING, value: byte_value, index: address);
  }

For more information, see the “USB command encoding” section of the Tic User’s Guide, which documents how to send a “Set setting” command.

–David

Thank you David. I’ll give that a go tomorrow and let you know how I get on

Tim

I can confirm that this works well.
However it has highlighted another minor issue I can live with but would best be resolved. The Homing Reverse to the switch attached to the TX pin (set to Limit switch reverse) works perfectly. However setting the TX pin to Limit switch forward and then using Homing Forward does not cause the homing to stop as it passes the switch. When I’m slewing past the switch I set the TX pin to Default so that it doesn’t act as a kill switch and stop the dome rotating as used to happen
Here’s the function to find home which sets the TX pin according to whether the shortest way to home, which is due north (000 degress) is forwards of backwards. It sets a variable Limit_Switch_Set to true so that the Slew routine only changes the TX pin function if it is not set to default. This was to prevent too many writes to EEPROM.

 public void FindHome()
 {   //tl.LogMessage("FindHome", "Not implemented");
     //throw new MethodNotImplementedException("FindHome");                
     m_tic.exit_safe_start();
     m_tic.energize();
     Limit_Switch_Set = true;
     if (Azimuth >= 180)
     {

         m_tic.set_setting_byte(0X3D, 8);
         m_tic.reinitialize();
         m_tic.go_home(tic.GO_HOME.FORWARD);
     }
     else
     {
         m_tic.set_setting_byte(0X3D, 9);
         m_tic.reinitialize();
         m_tic.go_home(tic.GO_HOME.REVERSE);
     }

The slew function just checks that the Limit_Switch_Set is false, if not it sets the TX pin to default, and then performs the dome slew

 public void SlewToAzimuth(double Azimuth)
 {
     //make the Azimuth a golbal variable for use in the Slewing property
     TargetAzimuth = Azimuth;
     if (Limit_Switch_Set)
     {
         m_tic.set_setting_byte(0X3D, 0);
         m_tic.reinitialize();
         Limit_Switch_Set = false;
     }

     double RequiredMoveDegrees;

     double AzimuthDiff = TargetAzimuth - CurrentAzimuth;

     if (AzimuthDiff > 180)
     {
         RequiredMoveDegrees = AzimuthDiff - 360;
     }
     else if (AzimuthDiff < -180)
     {
         RequiredMoveDegrees = (AzimuthDiff + 360);
     }
     else
     {
         RequiredMoveDegrees = AzimuthDiff;
     }



     //convert the degrees to move to motor steps to move
     int TargetSteps;
     double StepsToMove = RequiredMoveDegrees * steps_per_degree;
     TargetSteps = currentMotorSteps + (int)StepsToMove;

     // have to interface with motor here to set slew in motion. After this the timer function handles de-enegising the motor once slew complete.
     m_tic.exit_safe_start();
     m_tic.energize();
     m_tic.set_target_position(TargetSteps);

 }

One thing I’d add for anyone doing this is to screen the wires from the switch (I use a magnetic sensor as a switch) and the board. I started getting a lot of serial port errors when the motor was running and found that just by moving the wires that improved. My solution was actually just to wrap the wire from the TX pin around the wire from the gnd pin producing a twisted pair. This totally solved the interference issue. I guess using shielded wire with the shield connected to the gnd pin would be even better but the twisted pair works.

1 Like

I don’t see anything wrong with the code you posted, but I wonder if somehow SlewToAzimuth might be running in the middle of your homing routine and disabling the limit switch.

To rule out problems with your code, I recommend shutting off the C# program and then trying to reproduce the problem just using the Tic Control Center. You should be able to set the TX pin’s function to “Limit forward”, click “Apply settings”, and then run the “Go home forward” command in the Device menu.

–David

Thanks David

The SlewToAzimuth routine will only run if the dome is commanded to track the telescope, or I command the dome to rotate to a specific azimuth via the ASCOM interface. When the dome is commanded to Home then the tracking element is automatically switched off by the ASCOM software. But I will try your suggestion of using the Tic Control Center to test it out

Tim