Skip to main content
marcosarti29
Associate III
Feb 2, 2007 5:46 AM UTC
Question

Frequency of PWM: very un-precise!?

Posted on February 02, 2007 at 06:46

Frequency of PWM: very un-precise!?

This topic has been closed for replies.

4 replies

marcosarti29
Associate III
Jan 22, 2007 10:08 AM UTC
Posted on January 22, 2007 at 11:08

Hi,

I use ST7lite19F with internal oscillator at 8MHz.

I use initial re-calibration with:

MCCSR = 0x00;

EECSR = 0x00;

RCCR = ((EEPROM[0] & 0xFF00) >> 8);

I use PWM with clock at 32MHz:

ATCSR = 0x1A; /* fcounter = 32 MHz, OVFIE */

ATR = 2496;

With this setting my fPWM is fCOUNTER /(4096-2496) = 32MHz/1600 = 20KHz.

Problem: when I go to measure the real frequency I found variable value, 18KHz to 33KHz ??!!! :o

It's normal? :(

pjr
Associate
Jan 24, 2007 11:26 AM UTC
Posted on January 24, 2007 at 12:26

To me this code:

RCCR = ((EEPROM[0] & 0xFF00) >> 8);

sets RCCR to 0. The eeprom holds bytes, so 8 bits of eedata & 0xFF00 = 0.

What are you setting the DCRx register(s) to?

pjr

marcosarti29
Associate III
Jan 29, 2007 5:04 AM UTC
Posted on January 29, 2007 at 06:04

Thanks for your reply!

Why RCCR is '0'?

The DCRx start to ATR and it's go at 4096 for slowly start.

Thanks

marcosarti29
Associate III
Feb 2, 2007 5:46 AM UTC
Posted on February 02, 2007 at 06:46

Perhaps I have found!

I have mapped the EEPROM:

MY_EEPROM = NO_INIT 0x1000 TO 0x107F;

with:

NV_VAR INTO MY_EEPROM;

and defined it in main.c :

#pragma DATA_SEG NV_VAR

RAM_EXTERN unsigned int far EEPROM[0x40];

When I read the EEPROM with the command:

MCCSR = 0x00;

EECSR = 0x00; /* E2 in lettura */

RCCR = ((EEPROM[0] & 0xFF00) >> 8);

is possible that I read the least bit of RCCR?

Thanks for help!