Discussion in "8051 Discussion Forum" started by    shaik    Aug 3, 2010.
Tue Aug 03 2010, 07:40 pm
#1
hello all,

I am working with AT89C51CC01 for getting PWM signal.
The following program is from atteched document (PCA_Program.pdf).
The PWM code like this

void main()
{
CMOD = 0x02; // Setup PCA timer (without interrupt enable) Internal clock, fosc/4

CL = 0x00;
CH = 0x00;

CCAP1L = 0x40; // Set the initial value same as CCAP0H
CCAP1H = 0x40; // 75% Duty Cycle
CCAPM1 = 0x42; // Setup PCA module 1 in PWM mode.

CR = 1; // Start PCA Timer.

while (1)
{}
}
In this code i set Module 1 as output of PWM so o/p pin is p1.4
But this program not gives o/p on this pin.

The PCA support Capture, Timer, HSO, PWM and WDT.
Can i set any pin to any of this PCA mode?

Last week i check this same program n it was working, but today when i test this once again then it´s not working, i don´t understand wht is the probelm?

Another question is i m using AT89STK-06 board.
I want to give input from POT(R12) [see the Page: 4 in AT89STK-06-Demo-Board.pdf] another atteched file.
how can i do this?

please give ur suggestion for my problem.
Thanks in advance.



Wed Aug 04 2010, 12:09 am
#2
I have no idea why you created a new thread... anyways, your code is fine. you have to look for problem why its not working what did you do with your board last time and figure out if it had affected your board.

R12 is connected to P1.7 ADC input. you can configure that port as analog input. setup register for analog and read voltage level.
 shaik like this.
Wed Aug 04 2010, 07:39 pm
#3
thanks ajay,
I last time run software timer program, and after that it´s not supporting only PWM
program, other program i check it´s working but not PWM.

The code for software timer is as follows.

void PCA_ISR() interrupt 6 using 1
{
unsigned int temp;
IE = IE & 0xBF; // Stop Interrupts
CCF0 = 0; // Clear Int flag
temp = CCAP0L | (CCAP0H << 8); // The following four lines
temp += 0x4E20; // of code increase the
CCAP0L = temp; // compare value in CCAP0
CCAP0H = temp >> 8; // by 20000, effectively
// refreshing the timer.
IE = IE | 0x40; // Start interrupts
}
void main()
{
CMOD = 0x01; // Setup PCA timer mode.
CH = 0x00; // Init values
CL = 0x00;
CCAP0L = 0x20; // Set compare limit
CCAP0H = 0x4E;
CCAPM0 = 0x49; // Set Modules zero for 16bit Timer mode.
IE = 0xC0; // Enable Interrupts
CR = 1; // Start PCA timer
while(1)
{}
}

there is also not problem in board,bcoz i check other program of High speed output mode it´s working, but only PWM not working.
please help me for this problem.

p1.7 is used for Watchdog (module 4 PCA).
i read the datasheet but there nothing like p1.7 pin ise used for analog input from pot.

Do u have any idea or program for how check all pins of controller r working or not?
if yes then pls tell me or send me program.

please help for this problem.
Thanks in advance.


[ Edited Wed Aug 04 2010, 08:03 pm ]
Thu Aug 05 2010, 01:22 pm
#4
hello ajay,
sorry for 2nd msg but previous msg was too big so i write another one.

I want to test pins of microcontroller.
For this can i write p1.0=1, p1.1=0,p1.2=1 and so on?

what is the o/p of this following sample program which u send me before.

#include <reg51.h> //

void main()
{
TMOD = 0x20;
SCON = 0x50;
TH1 = 0xFD; //considering normal 8051 running at 11.0592Mhz
TL1 = 0xFD;
TR1 = 1;
while(1){
SBUF = 'A';
while(!TI);
TI = 0;
}
}

thanks in advance.
Thu Aug 05 2010, 06:00 pm
#5
hello Ajay,
sorry for 3rd msg, but please read all msg n reply me

For program i am working with PCA.
I think that is the problem of Refreshing PCA.

Can u know how can i refresh or each time writing 0 value to used pin?
Bcoz today i make program which is as follows

void main()
{
P1_0 = 1;
P1_1 = 0;
P1_2 = 1;
P1_3 = 0;
P1_4 = 1;
P1_5 = 0;
P1_6 = 1;
P1_7 = 0;

P0_0 = 1;

P2_1 = 1;

P3_2 = 1;

while (1)
{}
}

after testing this i make one another program which is as follows.
Same program of last week

void main()
{
CMOD = 0x02; // Setup PCA timer

CL = 0x00;
CH = 0x00;

CCAP1L = 0x40;
CCAP1H = 0x40;

CCAPM1 = 0x42;

CR = 1; // Start PCA Timer.

while (1)
{}
}
this gives correct o/p.
but after this i run the following program.

void main()
{
CMOD = 0x02; // Setup PCA timer

CL = 0x00;
CH = 0x00;
CCAP4L = 128;
CCAP4H = 128;
CCAPM4 = 0x42;

CR = 1;

while (1)
{}
}
this program not gives PWM o/p on p1_7 pin, gives other signal but not PWM.

please give ur suggetion for this problem.
Thank u in advance.
Sat Aug 07 2010, 12:45 am
#6
try setting pin as o/p...

make P1_7 = 0; in main function.

>>i read the datasheet but there nothing like p1.7 pin ise used for analog input from pot.
read datasheet carefully. you will see that P1.7 is multiplexed with analog port. so you have to set proper registers to make ADC work. see ADC chapter in datasheet.

>>Do u have any idea or program for how check all pins of controller r working or not?
>>if yes then pls tell me or send me program.
toggle them.. simplest way. put enough delay.
 shaik like this.
Mon Aug 09 2010, 01:20 pm
#7
hello ajay,
Thanks for ur reply.
As per ur suggetion i change program like follows to take give analog i/p from pot.

#include <stdio.h>
#include "reg_c51.h"

#define channel P1_7
#define value_converted P1_4

void main()
{

P1_7 = 0; // set pin for ADC(Analog) i/p
P1_4 = 1; // set pin for ADC(Digital) o/p

// configure channel P1.2 and P1.3 for ADC
ADCF = 0x0C;

// Enable the ADC
ADCON = 0x20;

ADCON &= 0xF8;

// Select channel
ADCON |= channel;

// Start conversion in standard mode
ADCON |= 0x08;

// Wait flag End of conversion
while((ADCON & 0x01)!= 0x01)
{
// Clear the End of conversion flag
ADCON &= 0xEF;

// read the value
value_converted = (ADDH << 2)+(ADDL);
}
while (1)
{}
}
after loading this program in microcontroller then i move pot then it´s changes lines in Osciloscope, but i can not see the analog singnal.(Only line moving when i move pot)

For toggle pin i try like this

toggle p1_7; (But there is no function like toggle).
delay_ms(300);


please help me for this probelm

thank u in advance.


[ Edited Mon Aug 09 2010, 05:52 pm ]
Tue Aug 10 2010, 12:39 am
#8

// read the value
value_converted = (ADDH << 2)+(ADDL);



how can this be possible just think over it.

you are moving a 16bit variable value to a port pin which is 1 bit wide.

I think you mis understood the concept of analog ports. you read analog inputs, then you can move that digital value to a PORT not pin.

when you said 10bit ADC it means after you convert analog input to digital the value will be 10 bit. similarly for 8bit, value will be 8bit wide.

toggle p1_7; (But there is no function like toggle).
delay_ms(300);


Post complete program.
 shaik like this.
Tue Aug 10 2010, 12:49 pm
#9
hello ajay,
thanks for ur information.
I had mis understood the concept. sorry for this.

wht can i do for toggle pin?
See the complete code for Toggle.

#include <stdio.h>
#include "reg_c51.h"

void main()
{
toggle p1_7;
delay_ms(300);

while (1)
{}
}
Yesterday i try to make program for LED blinking. For this i connect LED with board.The code is as follows, but this code gives some error.
I m doing programming in Keil uVision4.

#include <stdio.h>
#include <avr/io.h> // Error :: Can´t open file
#include <util/delay.h> // Error :: Can´t open file
#include "reg_c51.h"

void main()
{
while (1)
{
P1_3 = 1; // Set for LED o/p LED = on
delay_ms(1000); // Error :: Missing function-prototype

P1_3 = 0; // LED = off
delay_ms(1000); // Error :: requires ANSI-style prototype
}
}

I had also try _delay_ms(300), but this function also not working.
how can i give delay function in my code?
please give me ur idea or sugession for thiis problem.

Thanks in advance.





[ Edited Tue Aug 10 2010, 02:59 pm ]
Wed Aug 11 2010, 12:00 am
#10
#include <avr/io.h>
 // Error :: Can´t open file
#include <util/delay.h>
 // Error :: Can´t open file


these headers are for AVR microcontrollers not for 8051. Thats the reason you are getting those errors.

delay_ms(1000);  // Error :: Missing function-prototype

you probably using this function from AVR headers, which is not available for 8051. or you have to define that function yourself to remove this error. You can use a simple for loop to produce some delay.

LED Blinking program and toggle program is same thing. coz You are toggling LED pin to blink LED.
 shaik like this.

Get Social

Information

Powered by e107 Forum System

Downloads

Comments

Michailqfh
Fri Mar 29 2024, 01:53 am
Bobbyerilar
Thu Mar 28 2024, 08:08 am
pb58
Thu Mar 28 2024, 05:54 am
Clarazkafup
Thu Mar 28 2024, 02:24 am
Walterkic
Thu Mar 28 2024, 01:19 am
Davidusawn
Wed Mar 27 2024, 08:30 pm
Richardsop
Tue Mar 26 2024, 10:33 pm
Stevencog
Tue Mar 26 2024, 04:26 pm