Hello I have programmed my TIMA and I extract a pulses of approximately 1Hz
but with TIMB dont Work,I have used :1-a mr32
2-a mr16
3-other mr16
All are free samples, this is the program:
#include <hidef.h> /* for EnableInterrupts macro */
#include "derivative.h" /* include peripheral declarations */
int i=0;
int j=0;
void pllinit(void);
void init_pwm_timerb(void);
void input_ini(void);
void main(void) {
EnableInterrupts; /* enable interrupts */
/* include your code here */
pllinit();
init_pwm_timerb();
input_ini();
for(; {
__RESET_WATCHDOG(); /* feeds the dog */
} /* loop forever */
/* please make sure that you never leave main */
}
void pllinit(void){
PBWC = 0x80; /* set Auto Bandwidth Control */
PCTL &= ~(0x20); /* turn PLL off to be able to program multiplier */
PPG=0x37; /* multiply X-tal frequency by 3 => X-tal=9.83MHz *3 ~= 30MHz //para mi seria 0x37;
bus frequency 32MHz/10 = 3MHz, VCO range = 7 *///32/9.83=3
PCTL |= 0x20; /* turn on the PLL */
while (~PBWC & 0x40); /* wait for PLL lock */
PCTL |= 0x10; /* use PLL clock */
}
void init_pwm_timerb(void){
//timer que determina la frecuencia del var
TBSC_TSTOP=1;/* Stop the TIMA counter by setting the TIMA stop bit, TSTOP.*/
TBSC_TRST=1;/* Reset the TIMA counter and prescaler by setting the TIMA reset bit, TRST.*/
TBMODH=0b11111111;
TBMODL=0b11111110;/*In the TIMA counter modulo registers (TAMODH–TAMODL), write the value for the required PWM
period.*/
TBCH0H=0b00000000;/* In the TIMA channel x registers (TACHxH–TACHxL), write the value for the required pulse width.*/
TBCH0L=0b11111111;
TBSC_PS0=0;/*INTERNAL BUS CLOCK /64 */
TBSC_PS1=1;//=1*64*65534/8000000=524mseg
TBSC_PS2=1;
TBSC0_MS0B=0;//unbuffered(0;1)/*Write 1:0 (for buffered output compare
// or PWM signals) to the mode select bits, MSxB–MSxA.*/
TBSC0_MS0A=1;
TBSC0_TOV0=1;/* Write 1 to the toggle-on-overflow bit, TOVx.*/
TBSC0_ELS0B=1;
TBSC0_ELS0A=1;
/*WRITE 1:1 (polarity 0 — to set output on
compare) to the edge/level select bits, ELSxB–ELSxA. The output action on compare must
force the output to the complement of the pulse width level.*/
TBSC_TSTOP=0;/*In the TIMA status control register (TASC), clear the TIMA stop bit, TSTOP.*/
TBSC_TOIE=1;/*habilito la interrupcion*/
}
void input_ini(void){
DDRA=0b00000100;/*PTA2 SALIDA*/
}
interrupt 16 void overflow_pwmb(void){
#pragma TRAP_PROC SAVE_REGS
TASC &= ~(0b10000000);/*PONGO EL FLAG NUEVAMENTE A CERO*/
if(i==0){
PTA_PTA2=1;
i=1;}
else {
PTA_PTA2=0;
i=0;}
return ;}
how you can see the program is very simple , I change A for B and the number 16 for 13 for the interrupt but don´t work(tihs make a sine wave of 66kHZ?? for 2 seconds)
The reason can be that the mr`s are samples??
please help mi
Thank you for your time
Hi quimey.
The error is here:
TASC &= ~(0b10000000);/*PONGO EL FLAG NUEVAMENTE A CERO*/
^^^
TBSC is right.
bye