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.
You have 8 channels of ADC, but no CCP (PWM) module. So, you will need to write software PWM and control that with your 4 inputs. You have a 16-bit and 8-bit timers. I am assuming the inputs will be analog. If digital, then, will they be serial? Are you required to use that chip?
Can you give the equations that describe the relationship of the 4 inputs to the PWM output? What resolution and frequency do you need for the PWM?
EDIT: Are the "four inputs" to be consecutive bits of a port and considered a "nibble"? For example, that would give 16 choices for PWM duty cycle in its simplest form.
This looks like homework and should be moved to that section.
That is a type of PWM, but your professor has defined the high periods, rather than duty cycle. There are 16 high periods from 200 us to 950 us. I would use one of the timers to set a recurring interrupt of at least 1 ms -- probably longer, e.g., >200 ms, is better. Then I would use the other timer to set a pulse width at each interrupt of 200 us to 950 us depending on a read of the port with 4 switches. I would pull the port pin to ground with a resistor of about 10K , then connect to Vcc with the switch. This is, a pin connected to a switch that is "on" will read high (1) and when off will read low (0).
From that point, you need to design and post your schematic and code. Most people here do C, but I do not. I am sure they will chip in once you show your efforts.
I've been working on a PWM code on a PIC16f676 using XC8,mplab so far my code doesn't have any problems but doest upload to the microchip (first time ever using this chip) and the code seems logical it will generate a pulse width any suggestion why it wont upload maybe the connection of my pickit3
#pragma config FOSC = INTOSC
#pragma config WDTE = OFF
#pragma config MCLRE = ON
#pragma config CP = OFF
ansel = 0x00;
trisc=0b001111; // pins rc(0123) are set to be inputs
long i; //32 bits
if(RC0==RC1==RC2==RC3==0) //input 0000
What I would do is setup a 50 us delay (with adjustment for the overhead of a call and return and etc. -- about 4 to 6 us @ 4 MHz). Then read the port nibble used for input and add "4". Thus, 0x00 = 200 us on and so forth. Keep the LED pin on until finished counting down from "port value + 4".
thanks now my program is working but when i try to upload to the micro controller i get the following errors
Target device was not found (could not detect target voltage VDD). You must connect to a target device to use PICkit 3.
Target has invalid calibration data (0x00). }
ive connected VDD to power supply and VSS to ground and still get the error
VDD and VSS are, of course, required. Do you have the correct chip selected in the "Configure" dropdown? ( I use MPLab 8.92,so that may not be the exact wording.) Be sure the clock and data are connected too -- but that's a given.
Oh, you need to tell the programmer to power the target. In MPLab 8.92, that is under Programmer> Settings> Power.
PK3 has very low power capability (20 to 30 mA), so you may need to disconnect any peripherals that would draw more current than that.