Doubt in PWM technique.........

Status
Not open for further replies.

vinodhembedded

Junior Member level 2
Joined
Jul 29, 2013
Messages
22
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Visit site
Activity points
147
Doubt in PWM technique......... help

Hi friends...
I was seeing this program in a website.. actaully my doubt is , why
we need to disable analog comparator in ths program??
what is the use of CMCON??
why they defined CMCON = 0x07???
ALso tel what wil happen if we didnt declare sbit??
is it necessary?

below is the program.. go through it...

thanks in advance





Lab 9: Pulse Width Modulation Copyright @ Rajendra Bhatt, 2010. Description: CCP module generating PWM MCU: PIC16F628A Oscillator: XT, 4.0 MHz, MCLR Enabled */

sbit UP at RB0_bit;
sbit DOWN at RB1_bit;

unsigned short new_DC, current_DC;

void debounce()
{ Delay_ms(300);
}
void main()
{
CMCON = 0x07; // Disable comparators
PORTB = 0x00;
TRISB = 0b00000011; // RB0, RB1 input, RB3 (PWM1) output
PWM1_Init(5000); // PWM module initialization (5KHz)
new_DC = 0; // Initial value of variable Duty Cycle
current_DC = 0;
PWM1_Start(); // Start PWM1 module with Zero DC
PWM1_Set_Duty(current_DC);
do {
if (!UP)
{ // If the button connected to RB0 is pressed
debounce();
if (new_DC < 250) // Don't go above 250
new_DC = new_DC + 25 ; // increment Duty Cycle by 25
}
if (!DOWN)
{ // If the button connected to RB1 is pressed debounce();
if (new_DC !=0) // Don't go below 0
new_DC= new_DC - 25 ; // Decrement Duty Cycle by 25
}
if (current_DC != new_DC)
{
current_DC = new_DC ;
PWM1_Set_Duty(current_DC); // Change the current DC to new value } }
while(1);
}
 
Last edited:

Re: Doubt in PWM technique......... help

Hello there,

Hello,

The PORT pins are multiplexed with comparator an voltage reference functions.
The operation of thes pins are selected by control bits in the CMCON.
(Comparator Control register) register and the VRCO (Voltage Reference Control register) register.
When selected as a comparator input, these pins will read as ‘0’s.

So, you need to turn comparators off and enable pins for I/O functions:
CMCON = 0x07;

Port A comparator module:

Unlike the 16F84, the 16F628 Port A pins (A0, A1, A2, A3) default to comparator inputs on power up. The comparator mode control register CMCON controls the comparator input and output multiplexers, and will also turn OFF the onboard comparator module to allow Port A pins to be used as normal I/O-pins.

An external or internal reference can be used depending on the comparator operating mode. The analog signal present on VIN- is compared to the signal at VIN+, and the digital output of the comparator is adjusted as shown below picture.

Best regards,
 

Attachments

  • comparator.gif
    3.5 KB · Views: 121
Re: Doubt in PWM technique......... help

hi..

Only PORT A with analog pins will be connected to comparators ??
 
Last edited:

Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…