1 2 Previous Next 20 Replies Latest reply on Aug 21, 2017 12:08 PM by DaBr_1233126

    ADC to PWM


      Hello All!




      I have a need to generate a PWM signal with an adjustable duty cycle controlled via a 10K POT.   Having a bunch of 8 pin CY8C4014SXI-420 chips laying around I decided to try using them for this project.  Just enough room for Analog Input and PWM Output.


      I am attaching my project which 'should' work.  Of course it doesn't....


      I am using the CSD_ADC component and feeding it's output to the compare of the PWM component.  I started from an example I think i found in the component docs.  I have increased a couple of the delays to try getting it to work, but still a no go.


      When debugging, I basically get only 1 value from the ADC (0x19FE) with it connected as shown.  I get basically a 0x01 when the pin is disconnected from the resister.  With my multimeter, I am reading about 1.2V at the pin when connected, no matter the POT setting.  (Sweep arm of pot is verified working and voltage is changing when disconnected from PSoC...)


      I have tried 3 different chips, so I don't think the issue is hardware.


      Anyone have ideas?



        • 1. Re: ADC to PWM

          Here is an example that checks for 3 levels using the PSOC 5lp.  It should give you some ideals.

          • 2. Re: ADC to PWM

            So are you saying that the CSD_ADC component doesn't work?  This is being used to control brightness of an LED panel.  (120 White LEDs used to view an X-Ray)  I really need it to be adjustable thru the whole range...

            • 3. Re: ADC to PWM

              Unfortunately, not able to open your attached project due to "incorrect format" errors upon execution;


              That said, if you are getting only one value from the ADC: Either you are not running the ADC multiple times, you are not sampling correctly, or there is a hardware issue for your voltage not changing. Here is an attachd datasheet for the CSD ADC that might be useful to double-check: http://www.cypress.com/file/185806/download

              • 4. Re: ADC to PWM

                According to the CSD ADC Sheet: Place a 1 M-ohm resistor in series between your ADC pin and the voltage you want to measure; The CSD-ADC will pull its input pin to 1.2 volts for calculating the voltage at the external end of the 1M-ohm based on the given 1 M-ohm series resistance and 1.2 volt node for the ADC.

                • 5. Re: ADC to PWM

                  So I checked my '1M' resister and it wasn't....  I replaced it and it is mostly working now.


                  There is ALOT of jitter on this thing.  Watching the PWM on an oscope I see the it going all over.  I will try adding some averaging next and see if it fixes it some.  It is really bad on low values...


                  BTW - My circuit and code all came from your reference datasheet.

                  • 6. Re: ADC to PWM

                    So in debugging, I am seeing a very consistant output from the ADC.  Put my view of the PWM shows it jumping around alot.  At low PWM duty cycles it is ALOT of jumping around.  Came someone check my setup here and tell me how to improve it?


                    I have similar code running on a CyBLE module that isn't doing this at all.

                    • 7. Re: ADC to PWM

                      Under the ADC component, there is a setting to change: Sample time, sample averaging, and resolution. All three of those settings should help with getting better results. Plus, averaging the results in software doesn't seem to be working for your case :)


                      Let me if modifying the adc component settings works out for you (.cysch file)

                      • 8. Re: ADC to PWM

                        I am not sure that the ADC is now the issue.  While debugging, I am watching a test variable, and it is staying fairly constant.  It is the PWM that is maybe acting up.   Also, the CSD_ADC component does not have any setting for sample time and sample averaging.  It is very basic!


                        I am very disappointed in this part (CY8C4014SXI-420) really.  I have used several other parts and not had the issues that this one does.  I wish cypress made parts with a newer core in them but the same low pin count.  I might have to change to the CY8C4245PVI-482 to get this project done.  I use those in several test fixtures for other projects and have never had an issue with them.  I worry about using them in this project due to the amount of stuff that gets pulled into the fan that will be blowing on this from outside the device.  SOIC8 pins are a lot further apart so less chance of shorting pins, and also much easier assembly.  Once my design is completed I will probably only make a hundred of these.

                        • 9. Re: ADC to PWM

                          Also, are you having problems with BOTH attachments?  I have downloaded them both and they work fine for me.  (I downloaded them to a different laptop to make sure wasn't something on this one....)

                          • 10. Re: ADC to PWM

                            Fyi: The peripherals run even while the debugger has the CPU halted, so there might be hardware things happening when you try to debug :)


                            For example: Trying to use low power modes while debugging will cause the debugger to crash or for the device to fail to enter low power mode.


                            I've been using the CYBLE-022001-00 module, and it is working great so far (some odd code architecture, but still smooth-running). I have not tried the other devices you mention however.

                            • 11. Re: ADC to PWM

                              Yeah, I think I was having trouble with both formats. My guess is the IDE you are using has some tweaks in it or something :/


                              Here's the error I'm seeing:


                              Unable to open the project "C:\Product\PSoC Creator\Example Projects\Debugging\Design02.cydsn\Design02.cyprj": The data was not formatted correctly: The version value 'CyDesigner.Common.ProjMgmt.Model.CyPrjMgmtFolderSerialize' for type '3' is an unknown version.. This could mean that the data was corrupted or that it was created by an unsupported software version.


                              Obviously, I can still read the sources file main.c :) 

                              • 12. Re: ADC to PWM

                                Are you using PSoC Creater 4.1?

                                • 13. Re: ADC to PWM

                                  Yes, that is a great module!  I use it and and the CYBLE-014008-00 Module in several of my designs.  I am hoping that the PSoC 6 BLE ends up as a module also.  It has some very interesting potential!!!

                                  • 14. Re: ADC to PWM

                                    I'm currently using PSoC 4.0, maybe the version update is not backwards compatible? I'll have to try it with 4.1 and see if that works

                                    1 2 Previous Next