Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

So far, we’ve only been dealing with running software on your PC, but in reality our software runs on a separate “mini computer” in the car. These are Microcontrollers (aka. MCU, controller, STM, STM32, Integrated Circuit [IC], or other). The one that was used for the MSXIV design is an STM32f0 STM32f1 chip, shown below:

...

The metal bits sticking out are called “pins”, and are essentially just wires which receive/send all signals to or from the MCU. Each pin has a specific purpose, and are what connect the computation part to the rest of the electrical system. The programs that we write can be loaded onto one of these bad boys, which then runs the code as soon as it receives power. These are like the CPU in your laptop, but 50x cheaper and simpler. The other major difference is that the microcontroller is a comprehensive computer (instead of just a CPU), with memory and peripherals included.

...

1.2 - Creating a task and setting a GPIO

Create a task to run your LEDs. We learned how to create tasks in FW 102, so take a look there to refresh on how to do that.

...

  1. Setting the config to continuous mode - The call to I2C write register is done for you, what you need to figure out is what value to actually write. Head to page 28 and 29 of the datasheet. Table 8 lays out what each bit means within the 16-bit configuration value. Your job is to construct what 16 bits we’re writing to the ADC by reading the table. Here’s the steps:

    1. Leave most things as default except for the Field “MODE”. Set this bit to a 0.

    2. To do this, look at the value in the “Bit” column. This is the bit number the Field corresponds to. For “OS”, it is defined by just 1 bit, bit 15. See below that when writing out binary, bit 15 is the most significant (to the left) and bit 0 is the least (all the way to the right).
      | 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |

  2. Completing the read raw function - You’ll need to use the i2c.h header to include some I2C functions in your code. To read from the ADC, use the function i2c_read_reg and the appropriate arguments. The arguments are as follows:

    1. Port: The function signature contains a config struct. The struct has a member i2c_port so use this value as the port argument.

    2. Address: Same as the port, use the i2c_addr member as the address argument.

    3. Register: Look at ads1115.h. Within the ADS1115_Reg enum, there’s a list of registers. You want to read from the conversion register, so use that value as the argument.

    4. Buffer/reading: This is the buffer to which the converted value is read into. Pass the reading pointer into this.

    5. Bytes: This is the number of bytes of data you want to read back. How many bytes are in a uint16_t?

  3. Completing the read converted function - The ADC gives you a value between 0 and 65535, which is the uin16_t max value. Let’s assume in this driver that this represents a reading between 0 -2.048V and 2.048V (as we had set in the config register). How would you convert the “raw” reading to a voltage? (Hint: think about what a reading of 1 means, that would be 1/65535 of 24.048V096V. Use that logic to convert the readings.

...