Может кто знает как можно решить эту проблему?
Заранее благодарен.
А можно подробнее, что не получалось. На таких частотах (100-200 кГц) вполне можно сделать программный ШИМ, вопрос только в его "разрешении" (т.е. дискретизации).Serge_6989 писал(а):Пробывал реализовать программно с большей частотой, но не получилось.
Код: Выделить всё
// Timer 0 overflow interrupt service routine
interrupt [TIM0_OVF] void timer0_ovf_isr(void)
{ // Reinitialize Timer 0 value
TCNT0=0xb0; // 1 MHz
// Place your code here
static int c;
c++; c&=0x07;
PORTB.0=(c&0x04>>2);
}
Я это читал, там ведь разбирается аппаратный ШИМ. Однако перечитав нашел интересную идею, которую завтра попробую.phenomen писал(а):http://easyelectronics.ru/avr-uchebnyj- ... -shim.html
Почитайте про ШИМ
Вот: калькулятор для АВРок поможет с инициализацией таймеров.
В этом то и проблема. Мне нужно 8-битный ШИМ (256 отчетов на период).mattheus писал(а):..., вопрос только в его "разрешении" (т.е. дискретизации).
Если можно это место подробней. В CodeVision AVR я не нашел такой опции. Можно только задать размер стека.Нужно еще отключить сохранение переменных в стеке при вызове прерывания (для экономии времени).
256 * 100 кГц = 25,6 МГц.Serge_6989 писал(а):Мне нужно 8-битный ШИМ (256 отчетов на период).
Используется #pragma savereg-. Во встроенном Help CodeVisionAVR найдите раздел "The Preprocessor" и скрольтесь до #pragma.Serge_6989 писал(а):Если можно это место подробней. В CodeVision AVR я не нашел такой опции. Можно только задать размер стека.Нужно еще отключить сохранение переменных в стеке при вызове прерывания (для экономии времени).
Код: Выделить всё
The automatic saving and restoring of registers affected by the interrupt handler, can be turned on or off using the #pragma savereg directive.
Example:
/* Turn registers saving off */
#pragma savereg-
/* interrupt handler */
interrupt [1] void my_irq(void) {
/* now save only the registers that are
affected by the routines in the interrupt
handler, for example R30, R31 and SREG */
#asm
push r30
push r31
in r30,SREG
push r30
#endasm
/* place the C code here */
/* now restore SREG, R31 and R30 */
#asm
pop r30
out SREG,r30
pop r31
pop r30
#endasm
}
/* re-enable register saving for the other interrupts */
#pragma savereg+
The default state is automatic saving of registers during interrupts.
The #pragma savereg directive is maintained only for compatibility with versions of the compiler prior to V1.24.1. This directive is not recommended for new projects.
Код: Выделить всё
// Timer/Counter 1 initialization
// Clock source: System Clock
// Clock value: 16000,000 kHz
// Mode: Fast PWM top=ICR1
// OC1A output: Non-Inv.
// OC1B output: Non-Inv.
// Noise Canceler: Off
// Input Capture on Falling Edge
// Timer 1 Overflow Interrupt: Off
// Input Capture Interrupt: Off
// Compare A Match Interrupt: Off
// Compare B Match Interrupt: Off
TCCR1A=0xA2;
TCCR1B=0x19;
TCNT1=0x00;
ICR1=160;
OCR1A=0x00;
OCR1B=0x00;
Код: Выделить всё
// Timer/Counter 1 initialization
// Clock source: 64MHz PCK
// Clock value: 64000,000 kHz
// Mode: PWMA & B top=OCR1C
// OC1A output: Non-Inv., /OC1A connected
// OC1B output: Non-Inv., /OC1B connected
// Timer1 Overflow Interrupt: Off
// Compare A Match Interrupt: Off
// Compare B Match Interrupt: Off
// Enable the PLL
PLLCSR=0x02;
// Wait for the PLL to lock
while ((PLLCSR & 1)==0);
// Enable the 64MHz clock
PLLCSR|=0x04;
TCCR1=0x51;
GTCCR=0x50;
TCNT1=0x00;
OCR1A=0x00;
OCR1B=0x00;
OCR1C=0xFF;