Good day,
I am having trouble with programming of my PCB which makes use of 328P chip. The program I wrote was tested on a Arduino Uno and all worked fine. The problem comes when transferring the program to a chip to be used on the PCB.
Background:
The PCB runs a motor driver with input from a Nextion screen. This is the starting/stopping interface for the motors. On a certain page of the screen, the program is commanded into a function with a while loop to run the motor. This works perfectly fine on the Uno and even when I transfer the UNO chip to the PCB, but doesn't work at all with the 328P Chip.
All of the other commands work excellent on the chip, even when starting the motor outside a while loop, the only problem is experienced when calling the while loop, then nothing happens.
Below is the code for the loop:
void AdvCalibrate() {
while (run2 == 1) {
myNex.NextionListen();
currT = micros();
deltaT = currT - prevT;
myNex.NextionListen();
if (deltaT >= 100) {
deltaT = ((float)(currT - prevT)) / 1.0e06;
diff = pos - pos_i;
velocity2 = diff / deltaT;
v2 = velocity2 / 1080 * 60.0;
myNex.NextionListen();
vFilt = Filter.updateEstimate(v2);
Input = (vFilt / RPM_max) * 255;
prevT = currT;
pos_i = pos;
}
myNex.NextionListen();
Setpoint = MSpeed_cal;
int gap = abs(Setpoint - Input);
myNex.NextionListen();
if (gap < Diffpid_save) {
encoder.SetTunings(Kp, Ki, Kd);
} else
{
encoder.SetTunings(aggKp, aggKi, aggKd);
}
myNex.NextionListen();
encoder.Compute();
analogWrite(Motor, Output);
myNex.NextionListen();
advcurT = millis();
if (advcurT - advprevT >= 1000) {
myNex.writeNum("rpmtest.val", vFilt);
advprevT = advcurT;
}
myNex.NextionListen();
if (run2 == 0) {
analogWrite(Motor, 0);
break;
}
}
}