View Single Post
Old 03-21-2016, 06:31 PM   #2678 (permalink)
e*clipse
Permanent Apprentice
 
Join Date: Jul 2010
Location: norcal oosae
Posts: 523
Thanks: 351
Thanked 314 Times in 215 Posts
Ohhhhh, OK....

Why don't I attempt to translate both the 6015 and the 6010A code at the same time; both IC's are in the same "family" and almost twins...

Right now I've printed out all 43 pages of code and the pinouts of the 4011 and 6010A. I've done a pin-pin comparison of the chips; I'll add the 6015 to the mix.

Yes, many of the pins are the same for the 6010A and 4011. In general, there is more pin sharing of functions on the 4011.

One of the key things to watch out for is also the PGC and PGD pins. Paul likes to use those pins for programming the IC vs their alternatives. The problem on the 6010A is that AN0 and AN1 use those pins.

Regarding frequency - it would be nice to have a way to adjust for different oscillator frequencies and PWM frequency settings without messing up code behavior later. I would really like to play with the PWM frequency.

Anyway, I'll keep plugging away.

- E*clipse


Quote:
Originally Posted by MPaulHolmes View Post
Actually, the 6015 is very very similar to the 4011. It just has more pins. I bet the changes you made would let it run on the 6015 right this minute. The new board's pins are ALMOST identical to the 4011 (well, the 4011 is ALMOST a subset. Maybe one pin different. I can't remember which one now). There are a few extra pins on the new board. There are 3 things to address a pin.
PORT
LAT
TRIS

So, if there's an input, let's say it's input1, on port B3. My convention is to do the following:

#define I_PORT_INPUT1 _RB3
#define I_LAT_INPUT1 _TRISB3
#define I_TRIS_INPUT1 _LATB3

Tris is the thing you set to define a port as input or output. 0 means output, 1 means input. So, in the function that configures the inputs and outputs, you would have:
I_TRIS_INPUT1 = 1;

LAT is the thing you write to to set the value of the port. This isn't very relevant for inputs, since it's an input! haha. But if you wanted an output to be high, you would type:
O_LAT_SOME_RAND0M_PIN = 1;

PORT is the thing you read to get the value of the port. Ex:

if (I_PORT_INPUT1 == 1) {
// holy moley! input1 is now high!
}

So, read the port, write the lat!

You also have to initialize inputs as either analog or digital. Analog inputs are configured as analog by default, so you have to explicitly configure an input as digital if it could also be used as analog.
You do that here:
ADPCFG = 0b1111111111000000; // Set the lowest 5 bits to 0 which is analog, and make all others 1, meaning that they are digital. Default is analog. 0b is just like 0x for hexadecimal. 0b means the number is binary.

That would make analog inputs an0, an1, an2, an3, an4, an5 ANALOG, and all the rest would be digital. So, 0 means analog, and 1 means digital.

The basic structure of the code is, make the A/D in sync with the PWM frequeny, (in my case it's 10KHz) so each time the A/D has new values for currents and throttle and temperature ready, you are running the ISR, which runs the clarke and park transforms and inverse transforms, and sets the new PWM duties for all 3 phases. Then, when that time critical part is not running, you try to squeeze in the other interrupt, which is the serial communications.

Really, once you get all the bits configured, it's really just C, and you don't have to think about the details of what chip it is anymore. The 6010a has some quirks that make it a little different from the others, but the 6015 is very similar to the 4011.
  Reply With Quote
The Following User Says Thank You to e*clipse For This Useful Post:
MPaulHolmes (03-22-2016)