i am having some trouble setting up this code. i need to use an external interrupt to output 4 different PWM values and each button press must loop the PWM until the button is pressed again, but after setup i have no idea what to do next. any ideas?
Code:
/*
* PWMdutycycle.c
*
* Created: 23/10/2020 12:39:40
* Author : camog
*/
#include <avr/io.h>
#include <avr/interrupt.h>
#include "avr/iom328p.h"
#define OCR0A_0
#define OCR0A_1
#define OCR0A_2
#define OCR0A_3
void T0Interrupt1();
void T0interrupt2();
void T0interrupt3();
void T0interrupt4();
int main(void)
{
DDRD | = 1<<PORTD6; /* OCR0A output port */
PORTD &= ~ 1 << PORTD6; /* set OCR0A to 0 */
DDRB &= ~ 1 << PORTD2;
EIMSK = ( 1 << INT0 );
EICRA |= ( 1 << ISC00, | 1 << ISC01 );
TCCR0A | = ( 1<< WGM00, | 1 << WGM01, | 1<< COM0A1, | 1<< COM0A0); /* fast PWM mode, inverting mode set*/
TCCR0B | = 1 << CS00; /* clk no prescaling */
OCR0A_0 = 0;
OCR0A_1 = 0x3F; /*duty cycle=63, for 25% for inverting mode*/
OCR0A_2 = 0x9F;/*duty cycle=159, for 62.5%*/
OCR0A_3 = 0xDF; /*duty cycle =223 for 87.5%*/
sei();
while (1);
}
ISR (INT0_vect)
{
if (PIND2 == 1 )
{
OCR0A = OCR0A_1;
}
else (PIND2 = 0)
{
OCR0A = 0;
}
}