Skip to content

Instantly share code, notes, and snippets.

@JoshAshby
Created December 10, 2010 05:28
Show Gist options
  • Save JoshAshby/735826 to your computer and use it in GitHub Desktop.
Save JoshAshby/735826 to your computer and use it in GitHub Desktop.
Old, horrible and dirty pwm ramp code for BOB, simply a backup
void pwm_ramp1A(int value, int speed)
{
if (value == 0) {//safe gaurd to prevent i from over flowing
pwm1A(0);
}
else {
if (value > pwm_value_old1A){//determine if it should ramp up or down
TCCR1A |= (1<<COM1A1);
unsigned int i = pwm_value_old1A;
while (i<=value) {//ramp up
OCR1A=i;
i++;
_delay_ms(speed);
}
pwm_value_old1A = value;//store the old pwm for autoramping
} else {
TCCR1A |= (1<<COM1A1);
unsigned int i = pwm_value_old1A;
while (i>=value) {//ramp down
OCR1A=i;
i--;
_delay_ms(speed);
}
}
pwm_value_old1A = value;//store the old pwm for autoramping
}
}
void pwm_rampUp1A(unsigned int value, unsigned int speed)
{
TCCR1A |= (1<<COM1A1);
unsigned int i = pwm_value_old1A;
while (i<=value) {//ramp up
OCR1A=i;
i++;
_delay_ms(speed);
}
pwm_value_old1A = value;//store the old pwm for autoramping
}
void pwm_rampDown1A(unsigned int value, unsigned int speed)
{
if (value == 0) {//safe gaurd to prevent i from over flowing
pwm1A(0);
}
else {
TCCR1A |= (1<<COM1A1);
unsigned int i = pwm_value_old1A;
while (i>=value) {//ramp down
OCR1A=i;
i--;
_delay_ms(speed);
}
}
pwm_value_old1A = value;//store the old pwm for autoramping
}
void pwm_ramp1B(unsigned int value, unsigned int speed)
{
if (value == 0) {//safe gaurd to prevent i from over flowing
pwm1B(0);
}
if (value > pwm_value_old1B){//determine if it should ramp up or down
TCCR1A |= (1<<COM1B1);
unsigned int i = pwm_value_old1B;
while (i<=value) {//ramp up
OCR1B=i;
i++;
_delay_ms(speed);
}
pwm_value_old1B = value;//store the old pwm for autoramping
} else {
TCCR1A |= (1<<COM1B1);
unsigned int i = pwm_value_old1B;
while (i>=value) {//ramp down
OCR1B=i;
i--;
_delay_ms(speed);
}
pwm_value_old1B = value;//store the old pwm for autoramping
}
}
void pwm_rampUp1B(unsigned int value, unsigned int speed)
{
TCCR1A |= (1<<COM1B1);
unsigned int i = pwm_value_old1B;
while (i<=value) {//ramp up
OCR1B=i;
i++;
_delay_ms(speed);
}
pwm_value_old1B = value;//store the old pwm for autoramping
}
void pwm_rampDown1B(unsigned int value, unsigned int speed)
{
if (value == 0) {//safe gaurd to prevent i from over flowing
pwm1B(0);
}
TCCR1A |= (1<<COM1B1);
unsigned int i = pwm_value_old1B;
while (i>=value) {//ramp down
OCR1B=i;
i--;
_delay_ms(speed);
}
pwm_value_old1B = value;//store the old pwm for autoramping
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment