![]() | ![]() | ![]() |
| | |||||||
| Electronic Projects Design/Ideas/Reviews Are you building an electronic project or want to? Maybe you need some assistance? Come and submit your electronic questions here and let our experienced members find a solution. |
| | LinkBack | Thread Tools | Display Modes |
| | (permalink) |
| Hi There! I'm hoping to be able to get a PIC16F690 (which comes with Microchip's PicKit2) to give a PWM output which varies according to an Analogue input. Unfortunately the kit's instructions assume some level of competence with electronics and whilst I'm really keen to learn, I'm totally lost at the moment! Can anyone help with some pointers which would get me going in the right direction? The basic parameters are: Analogue input Some kind of look-up table which I can change the values in and then re-flash the PIC A PWM output with a 15-20Hz period. I gather that I can't pre or postscale the clock to give that kind of low frequency output and will need to make some kind of delay loop to give a less accurate frequency, but it should be fine for my purposes. Any help would be hugely appreciated! Cheers! Alex | |
| |
| | (permalink) |
| You should read the PDF for the PIC16F690 it contains an ADC which can be used for just that purpose.
__________________ "Because I be what I be. I would tell you what you want to know if I could, mum, but I be a cat, and no cat anywhere ever gave anyone a straight answer, har har." | |
| |
| | (permalink) | |
| Quote:
For instance, suppose you want to have PWM at 15 Hz with 256 degrees of resolution. Set up an interrupt routine to be called 15*256 times a second. Inside the routine do: Code: counter = (counter+1) % 256; if (counter >= threshold) set output pin = 0 else set output pin = 1 | ||
| |
| | (permalink) |
| Have a look at the 3rd post in this thread. It reads the ADC and then does software PWM to drive a servo. It should be easy to modify it to do what you need. Mike. | |
| |
| | (permalink) |
| Awesome, cheers guys Will have a play tonight | |
| |
| | (permalink) | |
| Oh dear. I tried copying and pasting the code into the MPLab thing and just changed the include thing to say pic16f690 but it didn't seem to like it when I hit build all I know it's a big ask, but would someone be willing to guide me through why it didn't build? Here's what the MPLab came up with: Quote:
Alex | ||
| |
| | (permalink) |
| You can't just change the pic type. What you can do is start with the template supplied by Microchip for the 16F690. You'll find it in "C:\Program Files\Microchip\MPASM Suite\Template\Code". Copy and past this into your project and then copy the adc/pwm code from above. You should now have 2 errors, NOT_RBPU and VCFG0 not defined. By referring to the data sheet you can see that NOT_RBPU is now called NOT_RABPU and VCFG0 has been renamed VCFG and has moved into ADCON0. Some other things have moved around in the ADC control registers and need fixing. You can find the names of the various register bits in the inc file, located at "C:\Program Files\Microchip\MPASM Suite". The attached asm file has the corrections. Mike. P.S. I don't know if this works as I don't have a 16F690 available. Last edited by Pommie; 6th July 2008 at 04:30 PM. | |
| |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
| |
| | ||||
| Title | Starter | Forum | Replies | Latest |
| Using Oscilloscopes | mechie | Electronic Theory | 9 | 29th November 2007 10:49 PM |
| Voltage Clamp | ThirtyTwo | General Electronics Chat | 41 | 11th August 2006 05:05 PM |
| Voltage Clamp | RedCarzRFaster | Micro Controllers | 31 | 9th August 2006 10:57 PM |
| input output code for C# | 20303675 | Electronic Projects Design/Ideas/Reviews | 0 | 17th August 2003 03:33 PM |
| Very confused about setting TRIS to output or input | arlin | Micro Controllers | 4 | 9th June 2003 12:59 PM |