1

Hello to the community!

I am using ATTINY85 and I am programming it through the AVRISP using an Arduino UNO.

This is the code I am using :

#include <avr/io.h>
#include <avr/interrupt.h>
void setup() {
 PORTB = 0; //Reset values on port B
 // After setting up the timer counter,
 // set the direction of the ports to output
 DDRB |= (1<<PB1) | (1<<PB0) | (1<<PB3); // PB0, PB1 and PB3
 // PLLCSR - PLL control and status register:
 // PLL is a clock multiplier
 // - multiplies system 8 MHz by 8 to 64 MHz
 // PLL is enabled when:PLLE bit is enabled,
 // CKSEL fuse is programmed to 0001. This clock is
 // switched off in sleep modes!
 PLLCSR |= (1<<PLLE); // PLL enable
 // Wait until the PLOCK bit is enabled
 // before allowing the PCK to be enabled
 //WaitForPLOCK();
 //unsigned int i = 0;
 while ((PLLCSR & (1<<PLOCK)) == 0x00)
 {
 // Do nothing until plock bit is set
 }
 // Enable asynchronous mode, sets PWM clock source
 PLLCSR |= (1<<PCKE);
 TCCR1 = (1<<CTC1) | // Enable PWM
 (1<<PWM1A) | // Set source to pck
 (0<<(CS13)) |
 (0<<(CS12)) |
 (1<<(CS11)) |
 (1<<(CS10)) | // Clear the pin when match with ocr1x
 (1<<COM1A1);
 GTCCR = (1<<PWM1B) | (1<<COM1B1);
 // Set PWM TOP value - counter will count and reset
 // after reaching this value
 // OCR1C
 // 100 kHz 159
 // 80 kHz 199
 OCR1C = 199;
 // Enable Timer1 OVF interrupt
 TIMSK = (1<<OCIE1A) | (1<<TOIE1);
 sei();
 OCR1A = 190; //chaning th FR
}
void loop() {
 PORTB |= (1 << PB3);
 delay(500);
 PORTB &= ~(1 << PB3);
 delay(500);
}

the problem is that when I use the PWM my rest of the outputs do not work . Any idea why is this happening?

I am using the ATTINY CORE library from Spence Konde.

asked Mar 25, 2021 at 7:59

1 Answer 1

5

This line:

TIMSK = (1<<OCIE1A) | (1<<TOIE1);

enables a couple of interrupts generated by Timer 1. Whenever you enable an interrupt source, you should make sure that the matching ISR has been defined. Otherwise, the interrupt request is routed to __bad_interrupt(), which by default jumps to the reset vector, thus resetting your program.

answered Mar 25, 2021 at 8:25
1
  • Amazing!! Thank you! That worked out! Commented Mar 25, 2021 at 14:36

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.