Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Help needed - PWM generation using PIC16F676

Status
Not open for further replies.
and can u tell me about the point Pin getting overloaded????


It was just a suggestion.... I have no idea what your circuit looks like..... As usual I am working blind!! All I know there is, there is a good output.


Take a look at these screen shots

A) 5% 5.png

B) 85% 85.png
 
Hi Ian,

Thanks for sharing the pics, But why is it like i am not getting this output when tried on real hardware.

I am using basic hardware as of now is just a basic thing like the one you simulated

But i am not getting the required output. Please help

Regards,
Suresh
 
Now the only difference between you code and mine.. I dont use the XC compiler or MPLABX

Here's mine
Code:
#include<htc.h>
#define _XTAL_FREQ  4000000
__CONFIG(0x31C4);


int OnPulse = 217;
int OffPulse = 38;
char TOG = 0;
int i = 0;
 
void interrupt Interrupt_Service_Subroutine(void)
	{
    	T0IF = 0;
        i += 1;
	TOG = ~TOG;
 
        if(i>=8000)	// two seconds
		{
                i=0;
		}
 
	if(i<=4000) 	// First second 85%
		{
		if(TOG)
			{
			RA5 = 1;
			TMR0 = 217;
			}
 
		else
			{
			RA5 = 0;
			TMR0 = 38;
			}
		}
 
        if(i>4000)    // Second second 5%
		{
		if(TOG)		
			{
			RA5 = 1;
			TMR0 = 13;
			}
		else
			{
			RA5 = 0;
			TMR0 = 242;
			}
		}
	}
 
 
void main()
	{
	int pulse;
	TRISCbits.TRISC3 = 0;
        TRISCbits.TRISC0 = 1;
	TRISAbits.TRISA5 = 0;
	CMCON = 7;
	TMR0 = OnPulse;
	ANSEL = 0x10;
	OPTION_REG = 0;
	T0IE = 1;
	GIE = 1;
        RC3=1;
 
	while(1)
        {
 
        }
   }

You'll notice that the config bits are always set correctly as I use a HEX value..
 
Hi Ian,

Without MPLAB IDE nd xc8 compiler, how to generate hex code for this..

__CONFIG(0x31C4); //I am getting symbol not found if i use this in MPLAB

What to do
 
Hi Ian,

If i try to simulate the code in ISIS, i am not able to see the waveform. Can u tell me the procedure. I have double clicked on PIC16F676 and gave the path to hex file and started simulation but i am not able to see any pulse
 
Hi Ian,

I compiled the same code in MikroC Compiler and guess what everything is working fine... Thanks a Ton for helping me :):):):):)

But can u tell me why the same code failed with MPLABX and XC8 compiler...

I also think its because of the configuration bits, but tell me how

Thanks
Suresh
 
Roman!! The chip doesn't have a CCP module... It was a software implementation..
...

Thank you! I apologise, being lazy and did not check in the datasheet for that PIC and just assumed the OP was using a PWM module.
 
But can u tell me why the same code failed with MPLABX and XC8 compiler...


No Idea.... We ( I mean me and one of my co-workers) Have found several anomalies with MPLABX... I will not upgrade untill all the bugs are out..

You'd think microchip products would be better than 3rd party...
 
You'd think microchip products would be better than 3rd party...

I didnt get this, Also Ian i have few doubts

1) if in PIC16F676 i initialize only RC3 and RA5 pins, what should be the voltage at other pins to which nothing is connected excluding VSS and VDD and
I think it should be 0V approx, but at pin RA4, RA0, RA1 and RA2 i am getting 5V. Please tell me why? how to initialize these pins to 0v

2) I am using RA4 as Solar sense, and the pin will be 0v if solar is present. As soon as i connect solar to RA4 the system is crashing. Is it because initially RA4 was at 5v?


3) Which compiler do u use ? and regarding __CONFIG macro, the compiler asks me to use __PROG_CONFIG. So if i use __PROG_CONFIG(1, 0x31C4) like this is it fine?


Regards,
Suresh
 
Free Hitech C... I haven't started with XC8 yet

If you are not bothered yet about too much power supply.. You don't need to worry about states of the unused pins.... If untouched they are initialised as inputs...

If RA4 is initially an input, and an ADC input at that, you need to be looking at the voltage output of said solar panel... You may need an input resistor or a divider at worst.
 
RA4 is initialized as input and there is no ADC, If Solar is power RA4 gets 0V and if RA4 is not present it gets 5V, so with this as feedback i turn On RA5 pin(which is output) when solar is present and turn off when solar is not present.

I just initialized RA4 as input and it is showing me 5V if i connect to normal hardware debug board which i used yesterday(uploaded picture in this thread yesterday). please tell me how to come back from this situation

Regards,
Suresh
 
If RA4 is an input... Also configured as an ADC (AN3) then you need to check the output voltage of the solar panel, The voltage must never exceed the pic power voltage.

Looking at the ANSEL select you have selected AN4 which is on RC0...
 
Hi Ian,

I am sorry if i confused you, Solar panel used is 200Watt(12V solar panel, 17- 19V at open circuit)
1) RA4 pin is configured as Input pin and as Solar Sense
2) If solar is present the 12V voltage from Solar Panel is cut down using Voltage divider circuits to 4.9V and given to RA4 pin
3) If solar is not present RA4 pin will get 0V
4) If solar is present then we are turning on the RA5 pin in normal charging mode and using PWM at RA5 pin if the charging mode is Trickle
5) If solar is not present RA5 value is set to 0.

I have removed the config settings which u pointed out and replaced them with __PROG_CONFIG(1, 0x31C4); and eventhough now if solar is present the system is not crashing and PWM duty cycle change is working fine with MPLAB IDE and Xc8 Compiler. Thanks once again for the help

__PROG_CONFIG(1, 0x31C4); // Can u tell me what is the meaning on 1 here, Is it an Instance?

Regards,
Suresh
 
Hi Ian,

Thanks and i know about that, I was just asking you the need of 1st parameter in __PROG_CONFIG( ),

As you see i have set the 1st parameter to '1', So is it an instance?

Regards,
Suresh
 
ok, so '1' as first argument is fine? if i dont give anything its returning an error, also i cannot use __CONFIG as it is not supported now by XC8 compiler
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top