Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Added 2 examples for FPGA and Microcontroller work
  • Loading branch information
kyp12002 committed Jul 1, 2018
0 parents commit 1258f22
Show file tree
Hide file tree
Showing 7 changed files with 178 additions and 0 deletions.
4 changes: 4 additions & 0 deletions C/Exam5/Explanation.txt
@@ -0,0 +1,4 @@
Deployed on at ATMega 328p

A light sensor is setup up to function as a button.
-ADC reads light sensor. When threshold voltage is reached, and held for 1 second, a counter is incremented.
87 changes: 87 additions & 0 deletions C/Exam5/main.c
@@ -0,0 +1,87 @@
#define F_CPU 16000000UL
#include <avr/io.h>
#include <avr/pgmspace.h>
#include <inttypes.h>
#include <avr/interrupt.h>
#include <util/delay.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "lcd_lib.h"
// PWM variables
volatile unsigned int Ain;
volatile float Voltage;
// LCD Strings
char lcd_buffer[17]; // LCD display buffer
const uint8_t LCD_Volage[] PROGMEM = "Voltage: ";
const uint8_t ButtonTaps[] PROGMEM = "Taps: ";
int oneshot = 0;
int waitForLower = 0;
int count = 0;
int state = 0;

// All initializations
void initialize_all(void)
{
// start the LCD
initialize_LCD();
LCDcursorOFF();
LCDclr();
CopyStringtoLCD(ButtonTaps, 0, 0);
//CopyStringtoLCD(ButtonTaps, 0, 1);
// ADC Setup
ADMUX |= (1<<MUX2) | (1<<MUX1); // Select ADC Channel 6
ADCSRA |= (1<<ADPS2) | (1<<ADPS1) | (1<<ADPS0); // Set ADC prescaler to 128
ADCSRA |= (1<<ADEN); // Enable ADC circuit
}

void start_ADC_and_wait()
{
// Start A to D conversion
ADCSRA |= (1<<ADSC);
// Wait until this conversion is completed
while((ADCSRA & (1<<ADSC)));
}

int main(void)
{
initialize_all();
while(1)
{
// Convert A to D
start_ADC_and_wait();
// Read the ADC value
Ain = (ADCL); // First read lower byte
Ain |= (ADCH<<8); // Then read upper byte
// Typecast the volatile integer into floating type data,
// divide by maximum 10-bit value, and
// multiply by 5V for normalization
Voltage = (float)Ain/1024.00 * 5.00;
if((Voltage >= 1) && waitForLower == 0)
{
oneshot = 1;
waitForLower = 1;
state = 1; //Pressed
}
if(Voltage < 0.5)
{
waitForLower = 0;
state = 0; //Released
}
if(oneshot == 1)
{
oneshot = 0;
count++;
}
// Write Voltage to string format and print
// (3 char string + “.” + 3 decimal places)
dtostrf(count, 4, 3, lcd_buffer);
// Print
LCDGotoXY(6,0);
LCDstring((uint8_t*)lcd_buffer, strlen(lcd_buffer));
dtostrf(state, 4, 3, lcd_buffer);
LCDGotoXY(6,1);
LCDstring((uint8_t*)lcd_buffer, strlen(lcd_buffer));
_delay_ms(100);
}
}
3 changes: 3 additions & 0 deletions C/Exam6/Explanation.txt
@@ -0,0 +1,3 @@
Deployed over ATMega328p

Setup non-blocking internal SPI. The program analizes the time it takes to communicate between the master and slave.
81 changes: 81 additions & 0 deletions C/Exam6/main.c
@@ -0,0 +1,81 @@
/*********** ECE3411 Lab Test 7, Task 2 ************/
#define F_CPU 16000000UL
#include <avr/io.h>
#include <avr/pgmspace.h>
#include <inttypes.h>
#include <avr/interrupt.h>
#include <stdio.h>
#include <string.h>
#include "lcd_lib.h"
// SPI related definitions
#define DDR_SPI DDRB
#define SPI_SS 2
#define SPI_MOSI 3
#define SPI_MISO 4
#define SPI_SCK 5
// Variables
volatile unsigned int InputByte;
volatile uint8_t data_byte;
// LCD Strings
char lcd_buffer[17]; // LCD display buffer
const uint8_t LCDCLK[] PROGMEM = "CLK: ";
const uint8_t LCDData[] PROGMEM = "BIT: ";
volatile int T1poll_before;
volatile int T1poll_after;
volatile int clk_cycles;
//-----------------------------------------------------------------------
// All initializations
void initialize_all(void)
{
initialize_LCD();
LCDcursorOFF();
LCDclr();
CopyStringtoLCD(LCDCLK, 0, 0);
CopyStringtoLCD(LCDData, 0, 1);
InputByte = 12;
// SPI Initialization
DDR_SPI |= (1<<SPI_SS)|(1<<SPI_MOSI)|(1<<SPI_SCK); //SS,MOSI,SCK: output, MISOinput
SPCR |= (1<<SPE)|(1<<MSTR)|(1<<SPR1)|(1<<SPR0); // Enable SPI, Master, CLK = 128
SPCR |= (1<<SPIE); // SPI Interrupt Enabled

// Timer1 Setup
TCCR1B |= (1<<WGM12); //CTC mode
TIMSK1 |= (1<<TOIE1); //ISR on Overflow
TCCR1B |= (1<<CS10); //Prescalar: 1
}
//-----------------------------------------------------------------------
// SPI ISR
ISR(SPI_STC_vect)
{
T1poll_after = TCNT1;
/* Write your code here */
PORTB |= (1<<SPI_SS); // Pull Slave Select High
data_byte = SPDR; // Read received data

if (T1poll_after > T1poll_before)
{
clk_cycles = (T1poll_after - T1poll_before); //Cycles is difference between After and before

}
else
{
clk_cycles = ( (T1poll_after - T1poll_before) + 65536); //Overflow so add pre overflow value
}
sprintf(lcd_buffer, "%u ", clk_cycles);
LCDGotoXY(8,0);
LCDstring((uint8_t*)lcd_buffer, strlen(lcd_buffer)); sprintf(lcd_buffer, "%u ", data_byte);
LCDGotoXY(8,1);
LCDstring((uint8_t*)lcd_buffer, strlen(lcd_buffer));
}
//-----------------------------------------------------------------------
/* Main Function */
int main(void)
{
initialize_all(); // Initialize everything
sei(); // Enable Global Interrupts
T1poll_before = TCNT1;
PORTB &= ~(1<<SPI_SS); // Pull Slave_Select low
SPDR = (InputByte >>2); // Start transmission
while(1); // Nothing to do.
}
//-----------------------------------------------------------------------
Expand Down
Binary file not shown.
3 changes: 3 additions & 0 deletions VHDL/Lab9/Explanation.txt
@@ -0,0 +1,3 @@
Deployed on Nexys4 DDR

Program receives Keyboard data, and displays that data to a screen via VGA. The program effectively functions as a basic word processor.
Binary file added VHDL/Lab9/Kyle_Parshall_Lab9.pdf
Binary file not shown.

0 comments on commit 1258f22

Please sign in to comment.