AnsweredAssumed Answered

Has anybody ever used the code in BLDC demo?

Question asked by Josh Jordan on Dec 16, 2014
Latest reply on Dec 17, 2014 by Hui_Ma

I've been trying to get this BLDC demo to work using the 3PH tower module.  It blew up fets when I turned it on so I'm auditing every line of code here.  The part that inits the adcs raises questions-


  calib = ADC1_CLP0;

  calib =+ ADC1_CLP1;

  calib =+ ADC1_CLP2;

  calib =+ ADC1_CLP3;

  calib =+ ADC1_CLP4;

  calib =+ ADC1_CLPS;

  calib = calib >> 1;

  calib = calib | 0x8000; // set the MSB

  ADC1_PG = calib; // set the plus side gain register


I have not been able to find any information on a "=+" operator, it seems this operator does not exist in C or any language.  Stepping through the code it appears to be setting calib equal to the positive value of ADC1_CLPx.  This is odd because all of these registers are cast to unsigned ints, you should not have to specify a positive value, and all of it but the last line should be optimized out.  I thought maybe whoever wrote this meant "+=", and the calibration section of the datasheet says you need to sum these calibration registers.  But after downloading the current BLDC code for the KV chips, it contains the same code with "=+" in it.  I also noticed a lot of spelling errors, redundant code, and code mechanisms that are not implemented correctly.  Like, why demand that clock defines be set and then hard code all the timing based values?  Maybe I'm wrong and the "=+" is supposed to do something that I don't understand since it is still in the code after several years of people using it, surely it would be fixed by now if it were a bug.  Maybe I'm the first person ever to use it?  Someone from freescale should audit or at least spell check this code.  And, if you are going to make us use a precompiled library for the motor driver, at least fix it so it doesn't have main() compiled into it and generates errors out of the box since almost all applications are going to have their own main().  I could be wrong about all this but it appears that an intern started this code and a different intern finished it and nobody at freescale proof read, audited or tested the code.