Hallo, I have a problem with my Atmega16 project and I am afraid that I am running out of ideas of solution. Here is my task:
I have two POTs connected to Atmega16 ADC. By these POTS I want to change the frequency and the duty cycle of a signal generated by Timer 1. POT_0 is connected to ADC channel 0(determines the frequency) and POT_1 is connected to ADC channel 1(determines the duty cycle). I have set up timer 1 in the following way: ICR register determines the frequency and OCR register determines the duty cycle. I use Phase and frequency correct PWM mode.
I store the data from the ADC in an 8x10 array, because later I will probably need all 8 channels of the ADC and I want to keep some data history.
I update the Timer 1 registers in Timer1 Overflow interrupt. There I pick up the desired value from the ADC data array. As ICR register is not double buffered so I use a software buffer for it. In this way I can update correctly OCR and ICR register.
The frequencies I need vary between 8kHz and 266kHz.
If I use only the ADC (Timer is off) it is working perfect(I sample and store the data without any problems). If I disable the ADC and turn Timer 1 on everything is fine again. By writing predefined data to the timer registers I successfully generate PWM signal.
But when I turn both ADC and timer together everything falls apart. Neither of the POTs is working. What I found out is that the the program never enters the ADC interrupt. Obviously the timer interrupt occupies too much time. I tried to allow interrupts during Timer 1 ISR, but this resulted in constant reset of the MCU?!?!
Please give me some clues?