View Single Post
Old 03-19-2016, 08:51 AM   #2676 (permalink)
MPaulHolmes's Avatar
Join Date: Feb 2008
Location: Maricopa, AZ (sort of. Actually outside of town)
Posts: 3,832

Michael's Electric Beetle - '71 Volkswagen Superbeetle 500000
Thanks: 1,368
Thanked 1,202 Times in 765 Posts
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.

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:

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:

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.
kits and boards
  Reply With Quote
The Following 2 Users Say Thank You to MPaulHolmes For This Useful Post:
e*clipse (03-21-2016), tajman (03-19-2016)