Oh and just in case anyone is looking for a working example in the future:
Rich (BB code):/* 38khz pwm on RA1 with 50% duty cycle. Timer 2 is is 52 decimal Prescaler is 1 Duty cycle value is 106 decimal */ #include <htc.h> #define _XTAL_FREQ 8000000 //__CONFIG (FOSC_INTOSC & BOREN_OFF & WDTE_OFF & PWRTE_OFF & MCLRE_OFF & CP_OFF & LVP_OFF & LPBOR_OFF & BORV_HI & WRT_OFF); #pragma config FOSC = INTOSC // Oscillator Selection bits (INTOSC oscillator: CLKIN function disabled) #pragma config BOREN = OFF // Brown-out Reset Enable (Brown-out Reset disabled) #pragma config WDTE = OFF // Watchdog Timer Enable (WDT disabled) #pragma config PWRTE = OFF // Power-up Timer Enable bit (PWRT disabled) #pragma config MCLRE = ON // MCLR Pin Function Select bit (MCLR pin function is digital input, MCLR internally tied to VDD) #pragma config CP = OFF // Code Protection bit (Program memory code protection is disabled) #pragma config LVP = ON // Low-Voltage Programming Enable (Low-voltage programming enabled) #pragma config LPBOR = OFF // Brown-out Reset Selection bits (BOR disabled) #pragma config BORV = LO // Brown-out Reset Voltage Selection (Brown-out Reset Voltage (Vbor), low trip point selected.) #pragma config WRT = OFF // Flash Memory Self-Write Protection (Write protection off) void InitPWM(); void main() { PORTA = 0b00000000; TRISA = 0b00000000; ANSELA = 0b00000000; CLC1CON = 0b00000000; CWG1CON0 = 0b00000000; InitPWM(); while(1) { } } void InitPWM() { PWM2CON = 0b00000000; // Clear PWM1CON PR2 = 0b00110100; // Configure the Timer2 period - decimal 52 PWM2CON = 0b11000000; //Enable PWM Module, Module Output PWM2DCH = 0b00000000; // Clear duty cycle registers PWM2DCL = 0b00000000; TMR2IF = 0; //Clear the timer 2 interrupt flag T2CON = 0b00000000; //Set prescaler to 1 TMR2ON = 1; //Enable timer 2 TRISA=0b00000000; = //Enable the pwm pin output //Set duty cycle to 106 PWM2DCH = 0b00011010; PWM2DCL = 0b10000000; return; }
I have use code from Mr Setanta to generate PWM on PIC10F322.
But it seems this code is not working.. !
I have read the datasheet and followed the same process as described but still no outcome.
Is this code working?? Do i have to set anymore Registers ? BIts ??
Anyone with working code for PIC10F322.. Please help.