Skip to content

L298n stepper system#13

Open
asgar-t wants to merge 19 commits intomainfrom
l298n_stepper_system
Open

L298n stepper system#13
asgar-t wants to merge 19 commits intomainfrom
l298n_stepper_system

Conversation

@asgar-t
Copy link
Copy Markdown
Contributor

@asgar-t asgar-t commented Apr 29, 2026

it builds now

Comment thread App/Inc/l298n_stepper_system.h
Comment thread App/Inc/l298n_stepper_system.h
Comment thread App/Inc/l298n_stepper_system.h Outdated
Comment thread App/Inc/l298n_stepper_system.h
Copy link
Copy Markdown
Contributor

@dzhang39 dzhang39 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lots of Comments that I would like clarification for in your code.

Comment thread App/systems/l298n_stepper_system.c Outdated
Comment thread App/systems/l298n_stepper_system.c
Comment thread App/systems/l298n_stepper_system.c
Comment thread App/systems/l298n_stepper_system.c
Comment thread App/systems/l298n_stepper_system.c
bool ports_seen[num_ports] = {};
GPIO_PIN pins_for_port[num_ports] = {};

//iterate through all the ports we will use, set seen flag and |= the pins
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we iterating? Is it because each GPIO controlls a certain enable, counter clockwise, clockwise pins of the HBridge?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

iterating because we have to initiallze each gpio

uint8_t max_speed;

uint8_t current_step;
uint8_t dir;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is dir?


if (speed < 0){
if (-1*speed > l298n->max_speed) return false;
l298n->dir = -1;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Internal Thought: Direction is counterclockwise?

l298n->dir = 0; l298n->ticks_per_step = (1<<31); return true;
}

l298n->ticks_per_step = (uint32_t)(
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Internal Thought: Main function which is non-bloking way for turning the stepper. Each tick takes 1 millionth of the current stepper timer period? Then setting the steps per revolution? Where did this come from? How would I know how to do this?

HAL_GPIO_Init((GPIO_TypeDef*)((uint32_t)GPIOA + i*port_dist), &GPIO_InitStruct);


}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How is GPIO_InitStruct impacting the actual pin; how can a single GPIO pin have multiple parameters?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

its what the HAL library uses to initalize the pin, not sur ewhat you mean by the second question


uint32_t max_time_ms; //max time
uint32_t current_time_running_ms;//how long its been running
uint32_t max_time_ms; //max time (currently not implemented)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I ignore this then

Copy link
Copy Markdown
Contributor

@dzhang39 dzhang39 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All Drivers and Debug not viewed

Comment thread App/Inc/project_config.h
#define PROJECT_CAN_ID_SCIENCE_DC_MOTOR_R 0x071U
#define PROJECT_CAN_ID_SCIENCE_SERVO_PCB_C 0x080U
#define PROJECT_CAN_ID_SCIENCE_SERVO_PCB_R 0x081U
#define PROJECT_CAN_ID_SCIENCE_STEPPER_PCB_C 0x090U
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Internal_Thoughts: From an outside perspective, this is where you would type the 3 bit ID into Cangaroo?

Comment thread App/Src/can_config.c
PROJECT_CAN_ID_SCIENCE_DC_MOTOR_R,
PROJECT_CAN_ID_SCIENCE_SERVO_PCB_C,
PROJECT_CAN_ID_SCIENCE_SERVO_PCB_R,
PROJECT_CAN_ID_SCIENCE_STEPPER_PCB_C,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Including Science Stepper Now

@@ -0,0 +1,694 @@
#include "dc_motor_system.h"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not reviewing this, Only Steppers at the momemnt

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unless the steppers are using the DC_motor_system.c

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unless the steppers are using the this system, I am ignoring this for now

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah that was an accident or smth just ignore

l298n_stepper_driver_t drivers[NUM_STEPPERS] = {


// {GPIOA, GPIO_PIN_6,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Commented Out to prevent GPIO overlap. Still Confused as this seems like you don't need to configure these in the IOC file?

Copy link
Copy Markdown
Contributor Author

@asgar-t asgar-t Apr 30, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

they are nto supposed to be configured in the ioc, its just commented out because i was using it to test but didnt want to delete yet.
also it serves as an example

Comment thread Core/Src/main.c
#include "../../App/Inc/servo_system.h"
#include "../../App/Inc/dbc_examples_system.h"
#include "../../App/Inc/test_pwm_system.h"
#include "../../App/Inc/dc_motor_system.h"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is stepper not in here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it deosnt have to be until the pcb branch is written

Copy link
Copy Markdown
Contributor

@dzhang39 dzhang39 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just cleaning up?

#include "l298n_stepper_system.h"


#define L298N_STEPPER_STATUS_UNDEFINED (uint8_t)0
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All Status Pins are from the DBC or CAN Protocol file?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not pins, just statuses, they are defined in the protocol file

GPIOA, GPIO_PIN_4,
GPIOC, GPIO_PIN_5,
GPIOA, GPIO_PIN_7,
l298n_stepper_driver_t drivers[NUM_STEPPERS] = {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is this?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

its just the array of structs, user has to define this


}; // needs to be defined in the .c
TIM_TypeDef* global_interrupt_clock = TIM2;
uint32_t l298n_stepper_timer_period_us = 100;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is our stepper specific right? Don't need to change these?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these parameters are stepper agnostic, the system will adjust behavior dependong on the stepper speciifc parameters to get the correct behavior, this is just which timer to trigger the interrupt, and how often you want to trigger the interrupt

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants