I want to get rid of the phase B stuff for the encoder code. Where do I do that? Do I need ANYTHING in User_Routines_Fast.c…can I get rid of all of that stuff from Kevin’s code or do I still need it? Do I need the Encoder_1_Int_Handler() funciton (and 2) at all?
Also I dont fully understand how the GTS works. I’m not using a regular CIM motor, this is for my forklift. Im using one of those small black motors with the big black pulley attached to it (like a winch). How can I attach it in this case?
Also, I have the GTS, its a chip that has two sides almost identical and I think I know how to connect it to the RC, but I just place that next to a gear and it should work? There’s no other part except for the chip? No red box or anything?
Thanks for your help!
// Encoder 2's phase a signal just transitioned from zero to one, causing
// this interrupt service routine to be called. We know that the encoder
// just rotated one count or "tick" so now check the logical state of the
// phase b signal to determine which way the the encoder shaft rotated.
Encoder_22_Count += ENCODER_2_TICK_DELTA;
Also, this line of code wasn’t compiling…it came up with this problem:
C:\USFIRST\frc_camera_s_21\CAMERA CODE\encoder.c:130:Error  unknown member 'INT3IP' in '__tag_223'
C:\USFIRST\frc_camera_s_21\CAMERA CODE\encoder.c:130:Error  type mismatch in assignment
for this line of code:
// interrupt 2 is low priority
INTCON2bits.INT3IP = 0;
So I just commented it out. Do I still need it? I cant find anywhere in the code where it could be changed or anything.
Well if you are using encoder two, that line you commented out sets the phase a interrupt priority for your encoder. Really, if you look at the chip spec I think its power on reset value is zero, but i’m not sure. If zero is the reset value then you should be fine.
That line shouldnt be a problem though… are your sure ifi_default.h is included? is there an error in the previous line?
I don’t know where the “22” came from, but the logic (such as it is) is correct. However, I was hoping you’d also think to correct the comment to explain what you did and why you did it. Someone (perhaps you) is going to be reading this code later, and it will help to have comments that actually describe the code.
Thank you. I made encoder_22_count because For some reason when I compiled, it said that there were MULTIPLE DEFINITIIONS for All of those variables in the Encoder.c file. All of the counters, all of the functions had multiple definitions…were declared more than once in the code, but I couldn’t find out where! In using MPLAB, I looked everywhere, I did a search in all of the files…(Edit, Find in Files), and I found 16 declarations of Encoder_1_Count, and none of them were second declarations of the same variable. (same for all of the other variables). So I changed the variable names and I dont know where the original Encoder_1_Count is being used, but Im using Encoder_11_Count now, and Initialize_Encoders1() and Get_Encoder_1_Count1() now instead.
P.S. I cant use the gear tooth sensor I found out, because im not using a regular CIM motor or gearbox. I’m using a ___ for a winch. I’m going to have to use a bunch of Limit Switches instead. How do I connect the limit switches? What is NC2, N03, and COM1? Do these all connect into a PWM cable and then into Digital In/Out on the RC? Is in Analog? Thanks for your help!
If you don’t get expected results after following the directions, it’s usually because you didn’t follow the directions correctly. Instead of trying to compensate for the error, it’s better to retrace your steps and find out what you did wrong. For example, the multiple definitions problem can happen if you have accidentally put #include encoder.c at the top of one of your files instead of #include encoder.h.
The Gear Tooth Sensor is not limited to use with a CIM motor. All it needs is a set of rotating teeth that can affect a magnetic field. Do you have no sprockets or gears anywhere on the winch?
Limit switches have three connections: common, normally open, and normally closed. The numbers after COM, NC, and NO are just pin numbers. When the switch is not pressed, the NO pin is open and the NC pin is connected to COM. When the switch is pressed, the NO pin is connected to COM and the NC contact is open.
The limit switch should be wired to a digital input on the Robot Controller. Connect the common pin to the black (ground) wire, and connect either the normally open or normally closed pin to the white (signal) wire, depending on whether you want the signal to be grounded when the switch is pressed or when the switch is released. The red (+5) wire is not used. The digital input value is read as 1 when the switch is open, and 0 when it is closed.