This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Timer 2 Used as a Baud Rate Generator

I am porting code from 87C576 to 87c591 chip. On the 576 chip they used timer 2 as the baud rate generator for serial 0. The 591 chip has many differences due to the CAN capability that was added. Here is the way the 576 chip was set up.

#define SCON_INIT 0x50 /* SERIAL CONTROL REGISTER */ /* BIT 0 = 0 RI END REC FLAG */ /* BIT 1 = 0 TI END XMIT FLAG */ /* BIT 2 = 0 RB8 9 TH BIT REC */ /* BIT 3 = 0 TB8 9 TH BIT XMIT */ /* BIT 4 = 1 REN REC DISABLED */ /* BIT 5 = 0 SM2 MULTI DISABLED */ /* BIT 6 = 1 SM1 SEL MODE */ /* BIT 7 = 0 SM0 SEL MODE */
#define TMOD_INIT 0x11 /* TIMER MODE CONTROL REGISTER /* BIT 0 = 1 M0 TIMER 0 MODE */ /* BIT 1 = 0 M1 SELECT */ /* BIT 2 = 0 C/T0 CLOCK CONTROL */ /* BIT 3 = 0 GATE TR0/INT0 CONTROL */ /* BIT 4 = 1 M0 TIMER 1 MODE */ /* BIT 5 = 0 M1 SELECT */ /* BIT 6 = 0 C/T1 CLOCK CONTROL */ /* BIT 7 = 0 GATE TR0/INT0 CONTROL */
#define TCON_INIT 0x50 /* TIMER CONTROL REGISTER */ /* BIT 0 = 0 IT0 EXT 0 DETECT MODE */ /* BIT 1 = 0 IE0 EXT INT 0 FLAG */ /* BIT 2 = 0 IT1 EXT 1 DETECT MODE */ /* BIT 3 = 0 IE1 EXT INT 1 FLAG */ /* BIT 4 = 1 TR0 START/STOP */ /* BIT 5 = 0 TF0 TIMER 0 INT FLAG */ /* BIT 6 = 1 TR1 START/STOP */ /* BIT 7 = 0 TF1 TIMER 1 INT FLAG */

#define T2CON_INIT 0x34 /* TIMER 2 CONTROL REGISTER */ /* BIT 0 = 0 CP/RL2 CAPTURE/RELOAD FLAG */ /* BIT 1 = 0 C/T2 TIMER/COUNTER SEL */ /* BIT 2 = 1 TR2 START/STOP */ /* BIT 3 = 0 EXEN2 TIMER ENABLE FLAG */ /* BIT 4 = 1 TLCK TRANSMIT CLOCK FLAG */ /* BIT 5 = 1 RCLK RECEIVE CLOCK FLAG */ /* BIT 6 = 0 EXF2 TIMER 2 EXT FLAG */ /* BIT 7 = 0 TF2 TIMER OVERFLOW FLAG */

Here is how Timer 2 is initialized to act as the baud rate generator.

/* Timer 2 setup as baud rate generator */
RCAP2L = TL2 = LOW_BYTE(BAUD_COUNT);
RCAP2H = TH2 = HIGH_BYTE(BAUD_COUNT);

Looking at the data sheet for the 591, it is not clear at all if the same setup can be used.
Timer 1 and 0 are being used for other things.

Does anyone know if Timer 2 in the 591 can be used in the same way.

steve

Parents
  • 14.3.6 BAUD RATE IN MODE 1 AND 3
    In these modes the baud rate is variable and can be
    generated alternatively by a baud rate generator or by
    Timer 1.
    14.3.7 USING THE INTERNAL BAUD RATE GENERATOR
    In Modes 1 and 3, the P8xC591 can use an internal baud
    rate generator for the serial port. To enable this feature, bit
    SPS (bit 7 of Special Function Register S0PSH) must be
    set. Bit SMOD1 (PCON.7) controls a divide-by-2 circuit
    which affect the input and output clock signal of the baud
    rate generator. After reset the divide-by-2 circuit is active
    and the resulting overflow output clock will be divided by 2.
    The input clock of the baud rate generator is fCLK.
    The baud rate generator consists of its own free running
    upward counting 12-bit timer. On overflow of this timer
    (next count step after counter value FFFH) there is an
    automatic 12-bit reload from the registers S0PSL and
    S0PSH. The lower 8 bits of the timer are reloaded from
    S0PSL, while the upper four bits are reloaded from bit 0 to
    3 of register S0PSH. The baud rate timer is reloaded by
    writing to S0PSH.

Reply
  • 14.3.6 BAUD RATE IN MODE 1 AND 3
    In these modes the baud rate is variable and can be
    generated alternatively by a baud rate generator or by
    Timer 1.
    14.3.7 USING THE INTERNAL BAUD RATE GENERATOR
    In Modes 1 and 3, the P8xC591 can use an internal baud
    rate generator for the serial port. To enable this feature, bit
    SPS (bit 7 of Special Function Register S0PSH) must be
    set. Bit SMOD1 (PCON.7) controls a divide-by-2 circuit
    which affect the input and output clock signal of the baud
    rate generator. After reset the divide-by-2 circuit is active
    and the resulting overflow output clock will be divided by 2.
    The input clock of the baud rate generator is fCLK.
    The baud rate generator consists of its own free running
    upward counting 12-bit timer. On overflow of this timer
    (next count step after counter value FFFH) there is an
    automatic 12-bit reload from the registers S0PSL and
    S0PSH. The lower 8 bits of the timer are reloaded from
    S0PSL, while the upper four bits are reloaded from bit 0 to
    3 of register S0PSH. The baud rate timer is reloaded by
    writing to S0PSH.

Children
No data