kodi.sudar
Member level 5
- Joined
- Dec 21, 2009
- Messages
- 92
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1,286
- Location
- india
- Activity points
- 1,849
I have tried with a timer toggling the output at 1KHz with the PLL on (60MHz, 1/4 PCLK), when I turned if off I git 1/5 of the frequency (200Hz)
Use this code and measure the frequency in P0.22
Code:#include <LPC213x.h> int main(void) { /* P0.22: MAT0.0 (Match output for Timer 0 channel 0) */ PINSEL0 = 0x00000000; /* binary: 00000000_00000000_00000000_00000000 */ IO0DIR = 0x80000000; /* binary: 10000000_00000000_00000000_00000000 */ PINSEL1 = 0x00003000; /* binary: 00000000_00000000_00110000_00000000 */ PINSEL2 = 0x00000000; /* binary: 00000000_00000000_00000000_00000000 */ IO1DIR = 0x00000000; /* binary: 00000000_00000000_00000000_00000000 */ /****************************************************************************** Timer0 (32bit) ******************************************************************************* Counter Enabled, Counter Reset=0 Timer mode: count on rising edge of PCLK Counter clk: 4 KHz, Counts every: 250 us (calculated with peripheral clock: 15MHz) MCR0.0 : reset, on compare match MAT0.0 : On compare match Toggle bit/output */ PCONP = (PCONP & 0x001817BE) | (1UL<<1); /* Enable peripheral clock for Timer0 (default is enabled) */ T0CTCR = 0x00; /* binary: 00000000 */ T0TC = 0x00000000; /* decimal 0 */ T0PR = 0x00000EA5; /* decimal 3749 */ T0MCR = 0x0002; /* binary: 00000000_00000010 */ T0MR0 = 0x00000001; /* decimal 1 */ T0MR1 = 0x00000000; /* decimal 0 */ T0MR2 = 0x00000000; /* decimal 0 */ T0MR3 = 0x00000000; /* decimal 0 */ T0CCR = 0x0000; /* binary: 00000000_00000000 */ T0EMR = 0x0031; /* binary: 00000000_00110001 */ T0TCR = 0x01; /* binary: 00000001 */ while(1) { } }
I have tried with a timer toggling the output at 1KHz with the PLL on (60MHz, 1/4 PCLK), when I turned if off I git 1/5 of the frequency (200Hz)
Use this code and measure the frequency in P0.22
Code:#include <LPC213x.h> int main(void) { /* P0.22: MAT0.0 (Match output for Timer 0 channel 0) */ PINSEL0 = 0x00000000; /* binary: 00000000_00000000_00000000_00000000 */ IO0DIR = 0x80000000; /* binary: 10000000_00000000_00000000_00000000 */ PINSEL1 = 0x00003000; /* binary: 00000000_00000000_00110000_00000000 */ PINSEL2 = 0x00000000; /* binary: 00000000_00000000_00000000_00000000 */ IO1DIR = 0x00000000; /* binary: 00000000_00000000_00000000_00000000 */ /****************************************************************************** Timer0 (32bit) ******************************************************************************* Counter Enabled, Counter Reset=0 Timer mode: count on rising edge of PCLK Counter clk: 4 KHz, Counts every: 250 us (calculated with peripheral clock: 15MHz) MCR0.0 : reset, on compare match MAT0.0 : On compare match Toggle bit/output */ PCONP = (PCONP & 0x001817BE) | (1UL<<1); /* Enable peripheral clock for Timer0 (default is enabled) */ T0CTCR = 0x00; /* binary: 00000000 */ T0TC = 0x00000000; /* decimal 0 */ T0PR = 0x00000EA5; /* decimal 3749 */ T0MCR = 0x0002; /* binary: 00000000_00000010 */ T0MR0 = 0x00000001; /* decimal 1 */ T0MR1 = 0x00000000; /* decimal 0 */ T0MR2 = 0x00000000; /* decimal 0 */ T0MR3 = 0x00000000; /* decimal 0 */ T0CCR = 0x0000; /* binary: 00000000_00000000 */ T0EMR = 0x0031; /* binary: 00000000_00110001 */ T0TCR = 0x01; /* binary: 00000001 */ while(1) { } }
Yes i saved the startup.s and recompiled it several times.Around 200Hz?
Are you using real hardware or simulation?
Have you changed the crystal to 12MHz from the default 10Mhz in the LPC2138 properties in proteus?
If you get 200Hz from the PIN then the core does indeed run at 12MHz
- - - Updated - - -
Do you save the startup after the change and recompile?
zip the project file and upload it
[COLOR="#FF0000"]PLL_SETUP EQU 0[/COLOR]
PLLCFG_Val EQU 0x00000024
The latest uvision 4.6 cant open the file, I get an error "Can't open project fie timer.uvproj"
- - - Updated - - -
I have opened the startup.s file you have included in a text editor, the PLL is not enabled
Code:[COLOR="#FF0000"]PLL_SETUP EQU 0[/COLOR] PLLCFG_Val EQU 0x00000024
when you check the PLL checkbox in the wizard this becomes 1
PWMMR2 = 0x0000004C;
PWMMR4 = 0x0000004A;
#include <LPC213x.h>
#include <math.h>
void input();
void adc_ini();
void adc_data();
void calculation();
void pwm();
void motor();
unsigned long val,adc_val;
float y,s,v,m;
float angle,b;
int main(void)
{
input();
pwm();
while(1)
{
adc_ini();
adc_data();
calculation();
}
}
void input(void)
{
PINSEL0 = 0x00028000; /* binary: 00000000_00000010_10000000_00000000 */
IO0DIR = 0x80000000; /* binary: 10000000_00000000_00000000_00000000 */
PINSEL1 = 0x01000000; /* binary: 00000001_00000000_00000000_00000000 */
PINSEL2 = 0x00000000; /* binary: 00000000_00000000_00000000_00000000 */
IO1DIR = 0x00000000; /* binary: 00000000_00000000_00000000_00000000 */
}
void adc_ini(void)
{
PCONP = (PCONP & 0x001817BE) | (1UL<<12); /* Enable peripheral clock for ADC0 (default is enabled) */
AD0INTEN = 0x00000000; /* binary: 00000000_00000000_00000000_00000000 */
AD0CR = 0x01200002; /* binary: 00000001_00100000_00000000_00000010 */
}
void adc_data(void)
{
while((AD0DR & 0x80000000)==0); //until bit 31 is high (DONE)
val = AD0DR; //read a/d data register
adc_val = ((val >> 6) & 0x3FF); // Extract AD result
}
void calculation(void)
{
/* angle calculation */
m=(3.3/1023);/*3.3/1023 for adc conversion*/
y=1.65;/*offset voltage */
s=0.8;/*sensitivity 800mv/g*/
b=57.295;/* pi/180 for radian to degree conversion */
/* formula tetha= arcsin( (vout - voffset)/sensitivity) */
v=asin(((adc_val*m)-y)/s);
angle=v*b;
motor();
}
void pwm(void)
{
PCONP = (PCONP & 0x001817BE) | (1UL<<5); /* Enable peripheral clock for PWM0 (default is enabled) */
PWMTC = 0x00000000; /* decimal 0 */
PWMPR = 0x0000003B; /* decimal 59 */
PWMMCR = 0x00000002; /* binary: 00000000_00000000_00000000_00000010 */
PWMMR0 = 0x000003E8; /* decimal 1000 */
PWMMR2 = 0x0000004B;
PWMMR4 = 0x0000004B;
PWMPCR = 0x00001400; /* binary: 00000000_00000000_00010100_00000000 */
PWMTCR = 0x09; /* binary: 00001001 */
}
void motor(void)
{
if(8.0>= angle <18.0)
{
PWMLER = 0x0000014;
PWMMR2 = 0x0000004C;
PWMMR4 = 0x0000004A;
}
else
{
PWMLER = 0x0000014;
PWMMR2 = 0x0000004B;
PWMMR4 = 0x0000004B;
}
}
if(8.0>= angle <18.0)
{
PWMLER = 0x0000014;
PWMMR2 = 0x0000004C;
PWMMR4 = 0x0000004A;
}
For me it is showing deselected .
View attachment 85214
if(8.0>= angle <18.0)
if ((angle<=8.0) && (angle<18.0))
But is is deselected, you said that the frequency doesn't change when you enable the PLL and I asked you to attach the code and in that PLL was not enabled, you were supposed to have it enabled in the project you have provided.
- - - Updated - - -
i executed the code which you have uploaded , i tried both by enabling PLL and by disabling. PFA snapshot of that
- - - Updated - - -
That condition doesn't seem right to me or at least is not clear enough, use
although it doesn't make sense, if angle is less than 8 is there any chance that it will not be less than 18 too?Code:if ((angle<=8.0) && (angle<18.0))
Also set the PWMLER after writing the new PWMMR values
sorry the angle should be between the range of 8.0 and 18.
it should be greater than 8 and less than 18
Getting the same frequency with PLL on or off doesn't make sense, I'm not sure what you are doing wrong but works fine for me.
But is is deselected, you said that the frequency doesn't change when you enable the PLL and I asked you to attach the code and in that PLL was not enabled, you were supposed to have it enabled in the project you have provided.
- - - Updated - - -
i executed the code which you have uploaded , i tried both by enabling PLL and by disabling. PFA snapshot of that
View attachment 85220
- - - Updated - - -
sorry the angle should be between the range of 8.0 and 18.
it should be greater than 8 and less than 18
The condition works well when i set the condition using adc value
but it fails to work when i assign using angle which is calculated using formula.Code:if ((adc_val>=0x0000022B) && (adc_val<0x0000024D)) { PWMMR2 = 0x0000004C; PWMMR4 = 0x0000004A; PWMLER = 0x0000014;
Is there any thing wrong with the above condition ?Code:if ((angle >= 7.996409) && (angle < 18.20971)) { PWMMR2 = 0x0000004C; PWMMR4 = 0x0000004A; PWMLER = 0x0000014; }
It works great in keil when i executed and checked by step one line ,But it fails to work in proteus simulation .
yes that is what i am thinking . let me check with the setting again.The pll settings for a new project are like the ones I showed in post #16 , they give 60MHz, how can you be getting a different frequency?
Can you zip your file and upload it ?yes that is what i am thinking . let me check with the setting again.
This is a project using the default startup that gives 60MHz
still its confusing . i dont find any change in proteus output
It works great in keil when i executed and checked by step one line ,But it fails to work in proteus simulation .
Are you sure you are using the correct AXF/HEX file in the simulator?
Have you tried using my AXF file from the zip file, it should give 1ms
- - - Updated - - -
This may be related to a wrong AXF/HEX file or there is a problem with you proteus
The AXF and HEX were generated with the same compile, the result will be the same.
Maybe you should consider updating your uvision to the latest version
I tried using your main.c as well as startup.s file by changing pll but gives the same output. but your hex file gives different output. Let me try with newer version of keil.
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?