Created
October 6, 2017 00:43
-
-
Save JHeld07/25940b46f93e603cb754c5c5fa517f67 to your computer and use it in GitHub Desktop.
Actuator_Test_1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Actuator_Test_1.c | |
* | |
* Created on: Oct 5, 2017 | |
* Author: heldjj | |
* | |
* Purpose: Create 4 pwm pins that can have the duty cycle varried independently from eachother. | |
*/ | |
#include <avr/io.h> | |
#include <inttypes.h> | |
#include <MSOE/delay.c> | |
#include <MSOE/bit.c> | |
#include <MSOE/lcd.c> | |
#include <avr/interrupt.h> | |
//Function prototypes | |
void Actuator_Fire(int Actuator_Number); | |
//Global Variables | |
int Actuator_Number=0; | |
int Actuator_PWM=0; | |
int Time=0; | |
int TimeOn=0; | |
int TimeCount=0; | |
int count=0; // flag for ISR use | |
int main(void) | |
{ | |
//Timer1 | |
TCCR1A |= (1<<COM1A1)|(1<<COM1B1)|(1<<WGM11)|(1<<WGM10); // fast pwm, mode 7, 0x03ff(1024) top, 10 bit | |
TCCR1B |= (1<<WGM12)|(1<<CS11); // Pre-scaler 5 top | |
//Timer0 | |
TCCR0A |= (1<<COM0A1)|(1<<COM0B1)|(1<<WGM01)|(1<<WGM00); // fast pwm, mode 3, 0x0ff(255) top, 10 bit | |
TCCR0B |= (1<<WGM02)|(1<<CS11)|(1<<CS10); // Pre-scaler 1024 top | |
//PWM Duty Cycle Settings | |
OCR1A=1000; //Duty cycle /1024 Pin B1 | |
OCR1B=1000; // Duty cycle /1024 Pin B2 | |
OCR0A=250; // Duty cycle /255 Pin D6 | |
OCR0B=50; // Duty cycle /255 Pin D5 | |
//Pin output settings | |
DDRB |=0x06; //0000 0110 Pin D9&10 output | |
DDRD |=0x60; //0110 0000 set output | |
// Going to want to turn pins off initially then on for the period of fire time. | |
// DDRB &=~(0x06); //0000 0110 Pin B1 & B2 input | |
// DDRD &=~(0x60); //0110 0000 Pin D5 & D6 input | |
sei(); // global interrupt enable | |
while(1) | |
{ | |
Actuator_Fire(Actuator_Number); | |
}//end while | |
}//end main | |
void Actuator_Fire(int Actuator_Number) | |
{ | |
Time=0; // set Time to 0 to control duty cycle time | |
TimeOn=Time+TimeCount; | |
switch (Actuator_Number)//Control which actuator is firing | |
{ | |
case '0': | |
DDRB|= 0x02; //0000 0010 Set pin B1 to output | |
OCR1A=Actuator_PWM; | |
// if (Time==TimeOn) | |
// { | |
// delay_ms(100); | |
// DDRB&= ~(0x02); //0000 0010 Set pin B1 to output | |
// } | |
break; | |
case '1': | |
break; | |
case '2': | |
break; | |
case '3': | |
break; | |
case '4': | |
break; | |
case '5': | |
break; | |
default: | |
Actuator_Number=0; | |
}// end switch | |
}// end Actuator_Fire | |
//TImer isr to control on and off sinals. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment