Yahoo Groups archive

Lpc2000

Index last updated: 2026-04-28 23:31 UTC

Thread

Strange behaviour of the VPBDIV register

Strange behaviour of the VPBDIV register

2005-06-10 by gustavo_sagasti

Hi:
I tried the following code:

#include <LPC21XX.h>
#include <stdio.h>

#define OSC_CLOCK_FREQ 14745600
#define CR     0x0D

void
UARTInitialize(unsigned int baud)
{
  U0LCR = 0x83; /* 8 bit, 1 stop bit, no parity, enable DLAB */
  U0DLL = 192;	/* 9600 bps @ Peripheral Clock = 2 * 14745600 MHz */
	
  U0DLM = 0;		
  U0LCR &= ~0x80; /* Disable DLAB */
  PINSEL0 = (PINSEL0 & ~0xF) | 0x5;
  U0FCR = 1;
}

unsigned int
cClkFreq(void)
{
  return (OSC_CLOCK_FREQ * (PLLCON & 1 ? (PLLCFG & 0x1F) + 1 : 1));
}

unsigned int
pClkFreq(void)
{ 
  unsigned int divider=0;
  switch (VPBDIV & 3)
    {
      case 0:
        divider = 4;
        break;
      case 1:
        divider = 1;
        break;
      case 2:
        divider = 2;
        break;	  
    } 
  return cClkFreq() / divider;
}

int putchar(int ch)  
{                  
  if (ch == '\n')  {
    while (!(U0LSR & 0x20));
    U0THR = CR;                      
  }
  while (!(U0LSR & 0x20));
  return (U0THR = ch);
}

int main (void) {
   UARTInitialize(9600);

   printf("Processor  Clock %d\n", cClkFreq());
   printf("Peripheral Clock %d\n", pClkFreq());  
   printf("Peripheral Clock %d\n", pClkFreq());
   printf("Peripheral Clock %d\n", pClkFreq());

  while (1) ;
  return 0;
}

It is compiled with Keil CARM, and the VPB Clock = CPU Clock / 2
The first printf the peripheral clock prints a wrong value, while the 
rest are correct.
Here is the result;
Processor  Clock 58982400
Peripheral Clock 14745600   ????
Peripheral Clock 29491200
Peripheral Clock 29491200

Apparently, the problem is when the VPBDIV register is read. The 
first time it reads as zero, while the rest it reads the correct 
value.

Someone have any idea about this?
Thanks
Gus

Re: [lpc2000] Strange behaviour of the VPBDIV register

2005-06-11 by Robert Adsett

At 10:36 PM 6/10/05 +0000, gustavo_sagasti wrote:
>Apparently, the problem is when the VPBDIV register is read. The
>first time it reads as zero, while the rest it reads the correct
>value.

That's known behaviour.  You have to read VPBDIV twice to be sure of 
getting the correct value.

Robert

" 'Freedom' has no meaning of itself.  There are always restrictions,   be 
they legal, genetic, or physical.  If you don't believe me, try to chew a 
radio signal. "  -- Kelvin Throop, III
http://www.aeolusdevelopment.com/

Re: Strange behaviour of the VPBDIV register

2005-06-11 by gustavo_sagasti

Hi Robert:

It is documented in some place? (Just to aware about other possible 
errors...I was several hours with this problem!!!...)

Thanks!

Gus


--- In lpc2000@yahoogroups.com, Robert Adsett <subscriptions@a...> 
wrote:
> At 10:36 PM 6/10/05 +0000, gustavo_sagasti wrote:
> >Apparently, the problem is when the VPBDIV register is read. The
> >first time it reads as zero, while the rest it reads the correct
> >value.
> 
> That's known behaviour.  You have to read VPBDIV twice to be sure 
of 
> getting the correct value.
> 
> Robert
> 
> " 'Freedom' has no meaning of itself.  There are always 
restrictions,   be 
> they legal, genetic, or physical.  If you don't believe me, try to 
chew a 
> radio signal. "  -- Kelvin Throop, III
> http://www.aeolusdevelopment.com/

Re: Strange behaviour of the VPBDIV register

2005-06-11 by Richard

errata


--- In lpc2000@yahoogroups.com, "gustavo_sagasti"
<gustavo_sagasti@y...> wrote:
Show quoted textHide quoted text
> Hi Robert:
> 
> It is documented in some place? (Just to aware about other possible 
> errors...I was several hours with this problem!!!...)
> 
> Thanks!
> 
> Gus
> 
> 
> --- In lpc2000@yahoogroups.com, Robert Adsett <subscriptions@a...> 
> wrote:
> > At 10:36 PM 6/10/05 +0000, gustavo_sagasti wrote:
> > >Apparently, the problem is when the VPBDIV register is read. The
> > >first time it reads as zero, while the rest it reads the correct
> > >value.
> > 
> > That's known behaviour.  You have to read VPBDIV twice to be sure 
> of 
> > getting the correct value.
> > 
> > Robert
> > 
> > " 'Freedom' has no meaning of itself.  There are always 
> restrictions,   be 
> > they legal, genetic, or physical.  If you don't believe me, try to 
> chew a 
> > radio signal. "  -- Kelvin Throop, III
> > http://www.aeolusdevelopment.com/

Move to quarantaine

This moves the raw source file on disk only. The archive index is not changed automatically, so you still need to run a manual refresh afterward.