Electronic Projects, forums and more.

Go Back   Electronic Circuits Projects Diagrams Free > Electronics Forums > Electronic Projects Design/Ideas/Reviews


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.

Reply
 
LinkBack Thread Tools Display Modes
Old 6th September 2007, 10:54 PM   (permalink)
Default Basing a PWM output on an Analogue input

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
turbo-brown is offline  
Old 7th September 2007, 12:52 AM   (permalink)
Default

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."
Sceadwian is offline  
Old 7th September 2007, 02:15 AM   (permalink)
Default

Quote:
Originally Posted by turbo-brown
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.
I don't know what kind of clock dividing possibilities there are for PICs, but if the built-in PWM facility of the PIC is incapable of low frequencies, you can always resort to doing your own PWM without having to sacrifice clock accuracy or doing a lot of busy waiting.

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
This is also called bit-banging PWM.
pc88 is offline  
Old 7th September 2007, 03:54 AM   (permalink)
Default

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.
Pommie is offline  
Old 11th September 2007, 09:13 PM   (permalink)
Default

Awesome, cheers guys

Will have a play tonight
turbo-brown is offline  
Old 11th September 2007, 09:35 PM   (permalink)
Default

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:
Clean: Deleting intermediary and output files.
Clean: Done.
Executing: "C:\Program Files\Microchip\MPASM Suite\MPAsmWin.exe" /q /p16F690 "A2D.asm" /l"A2D.lst" /e"A2D.err"
Error[113] C:\PK2 LESSONS\LPC DEMO BOARD\04 A2D\A2D.ASM 11 : Symbol not previously defined (_CONFIG1)
Error[108] C:\PK2 LESSONS\LPC DEMO BOARD\04 A2D\A2D.ASM 11 : Illegal character (,)
Error[113] C:\PK2 LESSONS\LPC DEMO BOARD\04 A2D\A2D.ASM 12 : Symbol not previously defined (_CONFIG2)
Error[108] C:\PK2 LESSONS\LPC DEMO BOARD\04 A2D\A2D.ASM 12 : Illegal character (,)
Error[118] C:\PK2 LESSONS\LPC DEMO BOARD\04 A2D\A2D.ASM 12 : Overwriting previous address contents (2007)
Error[118] C:\PK2 LESSONS\LPC DEMO BOARD\04 A2D\A2D.ASM 12 : Overwriting previous address contents (2007)
Error[113] C:\PK2 LESSONS\LPC DEMO BOARD\04 A2D\A2D.ASM 24 : Symbol not previously defined (NOT_RBPU)
Error[113] C:\PK2 LESSONS\LPC DEMO BOARD\04 A2D\A2D.ASM 66 : Symbol not previously defined (VCFG0)
Halting build on first failure as requested.
BUILD FAILED: Tue Sep 11 21:30:17 2007
Cheers!

Alex
turbo-brown is offline  
Old 12th September 2007, 02:00 AM   (permalink)
Default

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.
Pommie is offline  
Reply

Bookmarks

Thread Tools
Display Modes



Similar Threads
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



All times are GMT. The time now is 01:50 AM.


Electronic Circuits  |  Learning Electronics
Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.

eXTReMe Tracker