Microcontroller

While working on this project I highly advise you get the datasheet for our microcontroller here: http://ww1.microchip.com/downloads/en/DeviceDoc/Atmel-2545-8-bit-AVR-Microcontroller-ATmega48-88-168_Datasheet.pdf  And reference it if you have any trouble with the code. Page 15 has a pinout of the microcontroller.

Also the code for our project is downloadable here

We used Atmel Studio 7 as our IDE (Integrated Development Enviroment), and  we recommend using it if you want to work with low level software on embedded systems.

To replicate this project you will need similar hardware to what we used in our project.  An H-bridge to drive our DC Motor. An Encoder on both the motor and pendulum. The purpose of the H-bridge is to control the speed of our motor using an PWM signal. The purpose of the Encoder is to generate a set of pulses that we can count in order to find the current position and direction that the motor or pendulum is moving.

We conected our hardware with the following pintout. keep in mind if you are using different sensors you will need to do some research to make sure you are able to read your sensors and output to your motor controller.

This is the General  form of our C Code: Please download and look at main.c in order to get more details about implementation. you will most likley want to do your own research and look at the microcontroller datasheet in order to understand why we set certain registers to specific values that enable our system to work. If you are using dissimilar hardware, then this is a neccessity, since there could be many differences in how your sensors or motor controller function in comparison to our hardware. 

Initialization 1. Set all registers for Inputs, Outputs, SPI Slave, PWM generation, Interrupts Main() Tasks 1. Translating Joystick inputs into H-bridge control signals, 2 digital outputs and 1 PWM output 2. Checking endstop microswitches, disabling directional movement when appropriate SPI Communication Interrupt 1. Signal from Raspberry pi will either i. Set current joystick input variable ii. Request certain data for raspberry pi to read Pendulum Encoder Interrupt Position Encoder Interrupt