ADC & PWM example please
- acestu
- Posts: 1720
- Joined: Thu Dec 01, 2011 9:36 pm
- Location: Macclesfield UK
- Has thanked: 783 times
- Been thanked: 223 times
- Contact:
ADC & PWM example please
Hi,
Could anybody post an example of ADC & PWM please, such as a potentiometer controlling the brightness of an LED, that would
be brilliant as a starter....
Thanks In Advance
Acestu
Could anybody post an example of ADC & PWM please, such as a potentiometer controlling the brightness of an LED, that would
be brilliant as a starter....
Thanks In Advance
Acestu
Laptop Mac Book Pro i7 retina El Capitan //// Tower/Intel i7-Windows 7 64 Bit, Toshiba i5 Laptop Windows 10
Computers are like air conditioners. They work fine until you start opening windows.
Computers are like air conditioners. They work fine until you start opening windows.
-
- Matrix Staff
- Posts: 9520
- Joined: Sat May 05, 2007 2:27 pm
- Location: Northamptonshire, UK
- Has thanked: 2585 times
- Been thanked: 3815 times
- Contact:
Re: ADC & PWM example please
can you give us more details please.
E'g what version of Flowcode are you using?
If its Flowcode 5 Demo then goto:
http://www.matrixmultimedia.com/lc_index.php?p=18
Download: Flowcode v5 Examples - All
Then within:
Components\PWM & Analogue Output Folder
there are examples using PWM component and bit banging using timer interrupt.
Martin
E'g what version of Flowcode are you using?
If its Flowcode 5 Demo then goto:
http://www.matrixmultimedia.com/lc_index.php?p=18
Download: Flowcode v5 Examples - All
Then within:
Components\PWM & Analogue Output Folder
there are examples using PWM component and bit banging using timer interrupt.
Martin
Martin
- acestu
- Posts: 1720
- Joined: Thu Dec 01, 2011 9:36 pm
- Location: Macclesfield UK
- Has thanked: 783 times
- Been thanked: 223 times
- Contact:
Re: ADC & PWM example please
Hi Martin,
I have flowcode 4, at the moment and I am hoping to purchase a Flowcode 5 bundle on the 22nd of this month, I found a
pwm example on youtube but it isn't connected to anything, just a pot altering the brightness of an LED would be great.
Thanks
Acestu
I have flowcode 4, at the moment and I am hoping to purchase a Flowcode 5 bundle on the 22nd of this month, I found a
pwm example on youtube but it isn't connected to anything, just a pot altering the brightness of an LED would be great.
Thanks
Acestu
Laptop Mac Book Pro i7 retina El Capitan //// Tower/Intel i7-Windows 7 64 Bit, Toshiba i5 Laptop Windows 10
Computers are like air conditioners. They work fine until you start opening windows.
Computers are like air conditioners. They work fine until you start opening windows.
- Enamul
- Posts: 1772
- Joined: Mon Mar 05, 2012 11:34 pm
- Location: Nottingham, UK
- Has thanked: 271 times
- Been thanked: 814 times
- Contact:
Re: ADC & PWM example please
Hi,
This program will change the brightness of LED depending on ADC value. I am using PIC16f877a and PWM1..so LED has to be connected to RC2.
This program will change the brightness of LED depending on ADC value. I am using PIC16f877a and PWM1..so LED has to be connected to RC2.
- Attachments
-
- ADC Controlled LED PWM 16F877A.fcf
- (6.5 KiB) Downloaded 781 times
- acestu
- Posts: 1720
- Joined: Thu Dec 01, 2011 9:36 pm
- Location: Macclesfield UK
- Has thanked: 783 times
- Been thanked: 223 times
- Contact:
Re: ADC & PWM example please
Thanks Enamul,
I am going to have a look at this now.
Acestu
I am going to have a look at this now.
Acestu
Laptop Mac Book Pro i7 retina El Capitan //// Tower/Intel i7-Windows 7 64 Bit, Toshiba i5 Laptop Windows 10
Computers are like air conditioners. They work fine until you start opening windows.
Computers are like air conditioners. They work fine until you start opening windows.
- acestu
- Posts: 1720
- Joined: Thu Dec 01, 2011 9:36 pm
- Location: Macclesfield UK
- Has thanked: 783 times
- Been thanked: 223 times
- Contact:
Re: ADC & PWM example please
Hi Enamul,
When I run the simulation, the duty cycle changes when you alter the pot, but the LED does not light,
Am I doing somthing wrong ?
thanks
Stuart
When I run the simulation, the duty cycle changes when you alter the pot, but the LED does not light,
Am I doing somthing wrong ?
thanks
Stuart
Laptop Mac Book Pro i7 retina El Capitan //// Tower/Intel i7-Windows 7 64 Bit, Toshiba i5 Laptop Windows 10
Computers are like air conditioners. They work fine until you start opening windows.
Computers are like air conditioners. They work fine until you start opening windows.
- Enamul
- Posts: 1772
- Joined: Mon Mar 05, 2012 11:34 pm
- Location: Nottingham, UK
- Has thanked: 271 times
- Been thanked: 814 times
- Contact:
Re: ADC & PWM example please
Hi Stuart,
It will run in hardware but doesn't simulate..take care about ADC channel as AN1 is used not AN0.
It will run in hardware but doesn't simulate..take care about ADC channel as AN1 is used not AN0.
- acestu
- Posts: 1720
- Joined: Thu Dec 01, 2011 9:36 pm
- Location: Macclesfield UK
- Has thanked: 783 times
- Been thanked: 223 times
- Contact:
Re: ADC & PWM example please
Thanks Enamul,
I was just wondering about the pot, I take it that you use a linear pot rotary or slider but what resistance ?
thanks
Acestu
I was just wondering about the pot, I take it that you use a linear pot rotary or slider but what resistance ?
thanks
Acestu
Laptop Mac Book Pro i7 retina El Capitan //// Tower/Intel i7-Windows 7 64 Bit, Toshiba i5 Laptop Windows 10
Computers are like air conditioners. They work fine until you start opening windows.
Computers are like air conditioners. They work fine until you start opening windows.
- Enamul
- Posts: 1772
- Joined: Mon Mar 05, 2012 11:34 pm
- Location: Nottingham, UK
- Has thanked: 271 times
- Been thanked: 814 times
- Contact:
Re: ADC & PWM example please
Hi,
In hardware, you can simply use any pot linear or non-linear..if you want to have smooth intensity variation you have to use linear pot. 10K ohm pot should be nice to use.
In hardware, you can simply use any pot linear or non-linear..if you want to have smooth intensity variation you have to use linear pot. 10K ohm pot should be nice to use.
- acestu
- Posts: 1720
- Joined: Thu Dec 01, 2011 9:36 pm
- Location: Macclesfield UK
- Has thanked: 783 times
- Been thanked: 223 times
- Contact:
Re: ADC & PWM example please
Thanks Enamul,
I will try this on the breadboard now...
Acestu
I will try this on the breadboard now...
Acestu
Laptop Mac Book Pro i7 retina El Capitan //// Tower/Intel i7-Windows 7 64 Bit, Toshiba i5 Laptop Windows 10
Computers are like air conditioners. They work fine until you start opening windows.
Computers are like air conditioners. They work fine until you start opening windows.
- acestu
- Posts: 1720
- Joined: Thu Dec 01, 2011 9:36 pm
- Location: Macclesfield UK
- Has thanked: 783 times
- Been thanked: 223 times
- Contact:
Re: ADC & PWM example please
Hi Enamul,
I have put the circuit togethor on a breadboard, I had to use a 16f877 though because that is all I have,
when i powr it up though the brightness of the LED is controlled by the first few millimeteres on the pot
and is really difficult to control, the crystal is the same, have you any idea why this is so ?
thanks
Acestu
I have put the circuit togethor on a breadboard, I had to use a 16f877 though because that is all I have,
when i powr it up though the brightness of the LED is controlled by the first few millimeteres on the pot
and is really difficult to control, the crystal is the same, have you any idea why this is so ?
thanks
Acestu
Laptop Mac Book Pro i7 retina El Capitan //// Tower/Intel i7-Windows 7 64 Bit, Toshiba i5 Laptop Windows 10
Computers are like air conditioners. They work fine until you start opening windows.
Computers are like air conditioners. They work fine until you start opening windows.
-
- Matrix Staff
- Posts: 9520
- Joined: Sat May 05, 2007 2:27 pm
- Location: Northamptonshire, UK
- Has thanked: 2585 times
- Been thanked: 3815 times
- Contact:
Re: ADC & PWM example please
Hi Acestu,
If you would like to post the flowchart you used, then that can be checked out to see if there is anything that's been overlooked.
Martin.
If you would like to post the flowchart you used, then that can be checked out to see if there is anything that's been overlooked.
Martin.
Martin
- acestu
- Posts: 1720
- Joined: Thu Dec 01, 2011 9:36 pm
- Location: Macclesfield UK
- Has thanked: 783 times
- Been thanked: 223 times
- Contact:
Re: ADC & PWM example please
Hi Martin,
The flowchart is the one above that Enamul posted for me, all I have done is changed the pic to a 16F870.
thanks
Acestu
The flowchart is the one above that Enamul posted for me, all I have done is changed the pic to a 16F870.
thanks
Acestu
Laptop Mac Book Pro i7 retina El Capitan //// Tower/Intel i7-Windows 7 64 Bit, Toshiba i5 Laptop Windows 10
Computers are like air conditioners. They work fine until you start opening windows.
Computers are like air conditioners. They work fine until you start opening windows.
-
- Matrix Staff
- Posts: 9520
- Joined: Sat May 05, 2007 2:27 pm
- Location: Northamptonshire, UK
- Has thanked: 2585 times
- Been thanked: 3815 times
- Contact:
Re: ADC & PWM example please
Hi Acestu,
I would suggest you do a 1Hz LED flash test so you can confirm hardware is running at the correct Speed.
E.g
Loop while 1
1>C1
delay 500ms
0>C1
delay 500ms
If that is ok then if you have a multimeter then measure voltage between pin 3 and GND. Make sure there is a full range (0 to 5V) as your turning pot.
Finally measure dc voltage across Pin 13 & GND. Meter should read average DC, so should vary from 0 to approx 5V.
I would suggest you do a 1Hz LED flash test so you can confirm hardware is running at the correct Speed.
E.g
Loop while 1
1>C1
delay 500ms
0>C1
delay 500ms
If that is ok then if you have a multimeter then measure voltage between pin 3 and GND. Make sure there is a full range (0 to 5V) as your turning pot.
Finally measure dc voltage across Pin 13 & GND. Meter should read average DC, so should vary from 0 to approx 5V.
Martin
- Enamul
- Posts: 1772
- Joined: Mon Mar 05, 2012 11:34 pm
- Location: Nottingham, UK
- Has thanked: 271 times
- Been thanked: 814 times
- Contact:
Re: ADC & PWM example please
Hi Stuart,
Sorry I can't reply immediately. I wasn't in desk. I think you want to say you are using PIC16f870 that you have not 16f877a. What is the value of crystal you are using on the bread board?
Can you test one simple think like if you turn the pot can you get the voltage in wiper from 0V to 5V? Another basic thing you might have done but just to become certain, did you put series current limiting resistor with LED?
Sorry I can't reply immediately. I wasn't in desk. I think you want to say you are using PIC16f870 that you have not 16f877a. What is the value of crystal you are using on the bread board?
Can you test one simple think like if you turn the pot can you get the voltage in wiper from 0V to 5V? Another basic thing you might have done but just to become certain, did you put series current limiting resistor with LED?
- acestu
- Posts: 1720
- Joined: Thu Dec 01, 2011 9:36 pm
- Location: Macclesfield UK
- Has thanked: 783 times
- Been thanked: 223 times
- Contact:
Re: ADC & PWM example please
Hi Martin, Enamul,
Firstly, it's ok Enamul, I don't expect you to respond straight away, i'm just glad that you answer my posts.
I will try what you said Martin, and yes Enamul I am using a resistor with the LED is this correct ?
p.s. my crystal is 19.---- as per flowcode setting
Thanks Guys
Firstly, it's ok Enamul, I don't expect you to respond straight away, i'm just glad that you answer my posts.
I will try what you said Martin, and yes Enamul I am using a resistor with the LED is this correct ?
p.s. my crystal is 19.---- as per flowcode setting
Thanks Guys
Laptop Mac Book Pro i7 retina El Capitan //// Tower/Intel i7-Windows 7 64 Bit, Toshiba i5 Laptop Windows 10
Computers are like air conditioners. They work fine until you start opening windows.
Computers are like air conditioners. They work fine until you start opening windows.
- acestu
- Posts: 1720
- Joined: Thu Dec 01, 2011 9:36 pm
- Location: Macclesfield UK
- Has thanked: 783 times
- Been thanked: 223 times
- Contact:
Re: ADC & PWM example please
Hi again,
I have measured the voltage between the wiper (pin 3) and ground and I am getting 0 to 4.99 volts
the LED lights between 0 and 1.88 volts
How do I do the 1HZ test? , do I go into MPLAB and just write that little program or can I do it in Flowcode ?
thanks
Acestu
I have measured the voltage between the wiper (pin 3) and ground and I am getting 0 to 4.99 volts
the LED lights between 0 and 1.88 volts
How do I do the 1HZ test? , do I go into MPLAB and just write that little program or can I do it in Flowcode ?
thanks
Acestu
Laptop Mac Book Pro i7 retina El Capitan //// Tower/Intel i7-Windows 7 64 Bit, Toshiba i5 Laptop Windows 10
Computers are like air conditioners. They work fine until you start opening windows.
Computers are like air conditioners. They work fine until you start opening windows.
- Enamul
- Posts: 1772
- Joined: Mon Mar 05, 2012 11:34 pm
- Location: Nottingham, UK
- Has thanked: 271 times
- Been thanked: 814 times
- Contact:
Re: ADC & PWM example please
Yes..that's fine. You have to use resistor. That's why I was asking. I think you mean 19.66MHz which is ok.I will try what you said Martin, and yes Enamul I am using a resistor with the LED is this correct ?
The attached program is flasher LED program. If you see using the attached program LED ON and OFF every 1 sec..in that case your configuration setting is OK and crystal is OK and chip is OK. Just an easy way to test whether these basic stuffs are ok or not.
- Attachments
-
- Flasher_LED.fcf
- (4.5 KiB) Downloaded 349 times
- acestu
- Posts: 1720
- Joined: Thu Dec 01, 2011 9:36 pm
- Location: Macclesfield UK
- Has thanked: 783 times
- Been thanked: 223 times
- Contact:
Re: ADC & PWM example please
Hi Enamul,
When I program the chip with the 1HZ code the LED that I moved to B0 just stays on all the time ?
Any ideas ?
thanks
Acestu
When I program the chip with the 1HZ code the LED that I moved to B0 just stays on all the time ?
Any ideas ?
thanks
Acestu
Laptop Mac Book Pro i7 retina El Capitan //// Tower/Intel i7-Windows 7 64 Bit, Toshiba i5 Laptop Windows 10
Computers are like air conditioners. They work fine until you start opening windows.
Computers are like air conditioners. They work fine until you start opening windows.
- Enamul
- Posts: 1772
- Joined: Mon Mar 05, 2012 11:34 pm
- Location: Nottingham, UK
- Has thanked: 271 times
- Been thanked: 814 times
- Contact:
Re: ADC & PWM example please
Hi,
Do you have any other chip to try? It might have that chip has problem..
Do you have any other chip to try? It might have that chip has problem..
- acestu
- Posts: 1720
- Joined: Thu Dec 01, 2011 9:36 pm
- Location: Macclesfield UK
- Has thanked: 783 times
- Been thanked: 223 times
- Contact:
Re: ADC & PWM example please
Ok Enamul, I will have a look and see if I have another.
thanks
Acestu
thanks
Acestu
Laptop Mac Book Pro i7 retina El Capitan //// Tower/Intel i7-Windows 7 64 Bit, Toshiba i5 Laptop Windows 10
Computers are like air conditioners. They work fine until you start opening windows.
Computers are like air conditioners. They work fine until you start opening windows.
- acestu
- Posts: 1720
- Joined: Thu Dec 01, 2011 9:36 pm
- Location: Macclesfield UK
- Has thanked: 783 times
- Been thanked: 223 times
- Contact:
Re: ADC & PWM example please
Ok I found another chip and same thing happens,
Does it matter which side of the LED the resister goes ?
Should the LED be on all the time even when I Erase the program from chip memory
I must be doing something really silly somewhere !
thanks
Acestu
Does it matter which side of the LED the resister goes ?
Should the LED be on all the time even when I Erase the program from chip memory
I must be doing something really silly somewhere !
thanks
Acestu
Laptop Mac Book Pro i7 retina El Capitan //// Tower/Intel i7-Windows 7 64 Bit, Toshiba i5 Laptop Windows 10
Computers are like air conditioners. They work fine until you start opening windows.
Computers are like air conditioners. They work fine until you start opening windows.
- acestu
- Posts: 1720
- Joined: Thu Dec 01, 2011 9:36 pm
- Location: Macclesfield UK
- Has thanked: 783 times
- Been thanked: 223 times
- Contact:
Re: ADC & PWM example please
OMG, how stupid am I, I have just seen that connections used on the chip are white in the diagram, and there are 2 x vss connections
I only had 1 of them connected, when I connected the second one and re programmed LED flasher code it worked, so I am going to try
the other code now......
Thanks
Acestu
I only had 1 of them connected, when I connected the second one and re programmed LED flasher code it worked, so I am going to try
the other code now......
Thanks
Acestu
Laptop Mac Book Pro i7 retina El Capitan //// Tower/Intel i7-Windows 7 64 Bit, Toshiba i5 Laptop Windows 10
Computers are like air conditioners. They work fine until you start opening windows.
Computers are like air conditioners. They work fine until you start opening windows.
- acestu
- Posts: 1720
- Joined: Thu Dec 01, 2011 9:36 pm
- Location: Macclesfield UK
- Has thanked: 783 times
- Been thanked: 223 times
- Contact:
Re: ADC & PWM example please
Guess what ?
It works, brilliant thanks guys,
could I just ask 2 more question though please,
Is this method used in domestic house light switch dimmers ?
When using PWM to control DC motors are they driven directly from the micro or does it have to be amplified somehow ?
Thanks
Acestu
It works, brilliant thanks guys,
could I just ask 2 more question though please,
Is this method used in domestic house light switch dimmers ?
When using PWM to control DC motors are they driven directly from the micro or does it have to be amplified somehow ?
Thanks
Acestu
Laptop Mac Book Pro i7 retina El Capitan //// Tower/Intel i7-Windows 7 64 Bit, Toshiba i5 Laptop Windows 10
Computers are like air conditioners. They work fine until you start opening windows.
Computers are like air conditioners. They work fine until you start opening windows.
- Enamul
- Posts: 1772
- Joined: Mon Mar 05, 2012 11:34 pm
- Location: Nottingham, UK
- Has thanked: 271 times
- Been thanked: 814 times
- Contact:
Re: ADC & PWM example please
Actually most of the dimmer circuit used TRIAC to control power in the LOAD(light) which is triggered by RC circuit in normal household lights and FANs if that is run on AC. so you have to have zero crossing detector and triac control circuit to use this with AC light dimmer..Is this method used in domestic house light switch dimmers ?
When using PWM to control DC motors are they driven directly from the micro or does it have to be amplified somehow ?
But for DC light control you can simply use TRIAC or SSR with transistor as driving circuit.