I am using a published sketch (with a few mods of mine) to run a sensorless BLDC and have copied it into and compiled it in two different IDEs, Arduino’s own and also Microsoft’s Visual Editor (with VisualMicro installed) to check all is OK.
In both cases a list of errors occurred that seem to be about the use of words or phrases that are not recognised and ‘declared in this scope’.
So what I would like to know is can one just define a list of words in setup that will remove these errors or is something more involved required? What syntax is required?
Below the first block of text was made by Arduino's own IDE and the second with Visual Editor. The whole sketch is shown in the attached pdf.
Thank you
Jules
In function 'void loop()':
sketch_BLDC-JP1:73:1: error: 'cycle' was not declared in this scope
cycle = PWM_START_DUTY
^~~~~
exit status 1
'cycle' was not declared in this scope
This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.
Compiling 'BLDC_JP1' for 'Arduino Uno'
BLDC_JP1.ino: 10:1: error: 'ESC' does not name a type
Error compiling project sources
ESC)
Build failed for project 'BLDC_JP1'
^~~
BLDC_JP1.ino: In function void __vector_23()
BLDC_JP1.ino: 41:13: error: 'bldc_step' was not declared in this scope
if (bldc_step & 1) {
^~~~~~~~~
BLDC_JP1.ino:41: note suggested alternative bldc_move
if (bldc_step & 1) {
^~~~~~~~~
bldc_move
BLDC_JP1.ino: 49:5: error: 'bldc_step' was not declared in this scope
bldc_step++
^~~~~~~~~
BLDC_JP1.ino:49: note suggested alternative bldc_move
bldc_step++
^~~~~~~~~
bldc_move
BLDC_JP1.ino: In function void bldc_move()
BLDC_JP1.ino: 53:13: error: 'bldc_step' was not declared in this scope
switch (bldc_step) {
^~~~~~~~~
BLDC_JP1.ino:53: note suggested alternative bldc_move
switch (bldc_step) {
^~~~~~~~~
bldc_move
BLDC_JP1.ino: In function void loop()
BLDC_JP1.ino: 82:5: error: 'cycle' was not declared in this scope
cycle = PWM_START_DUTY
^~~~~
BLDC_JP1.ino: 88:9: error: 'bldc_step' was not declared in this scope
bldc_step++
^~~~~~~~~
BLDC_JP1.ino:88: note suggested alternative bldc_move
bldc_step++
^~~~~~~~~
bldc_move
BLDC_JP1.ino: 92:5: error: 'motor_speed' was not declared in this scope
motor_speed = PWM_START_DUTY
^~~~~~~~~~~
cycle type has to be declared somewhere in the code and is not.
according to the Arduino reference, ++ must be either int or int long, so byte bldc_step++ not a valid type for using ++.
I'm not sure how you downloaded the code, but the error messages you posted are caused by the text being formatted incorrectly. As an example, your first error message was from this section of code:
void loop() {
SET_PWM_DUTY(PWM_START_DUTY); // Setup starting PWM with duty
cycle = PWM_START_DUTY
i = 10000; //5000
// Motor start
This is how it should appear:
void loop() {
SET_PWM_DUTY(PWM_START_DUTY); // Setup starting PWM with duty cycle = PWM_START_DUTY
i = 10000; //5000;
// Motor start
Ok I can see the difference in that a line break has occurred and that has been interpreted as a separate instruction. However, doesn't the compiler ignore white space after a // and so it shouldn't matter?
The sketch was exported into a pdf and I then copied it out of that.
The problem is that the comment has been broken up into two lines in the pdf file. As far as the compiler is concerned, the comment ends at the end of the 1st line, and the 2nd line is completely separate and is being interpreted as a line of code.
Attached is the original code I copied from the website you linked, formatted correctly so that it will compile.