adc controlled PWM output???

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 2 and 3.

Moderators: Benj, Mods

adc controlled PWM output???

Postby boa279 » Mon Sep 28, 2009 5:35 pm

Hello,

I've never been successful using the PWM component and was hoping to get some help. First a little background on the project:

I've finished working on a automatic transmission controller (this is a different transmission than the computer was intended for)and everything works great except one thing. There is a solenoid that needs to be pulsed rather than "on all the time" because it generates a lot of heat and will cook itself. The old transmission solenoid was designed for continuous use..the new one was not. SOOoOOooO, Id like to take the "on all the time" signal generated from the old computer and output a variable pulse signal in the realm of 1-10Hz (controllable with an ADC). I'm not even sure if that's possible with the PWM component as it has no connections. I would really, really appreciate if someone could draw me up a flowcode that would suit this project. I have version 3 and 4 for PIC. Id also like to use the smallest PIC possible but have plenty of 16f88's on hand. THANKS YOU!!!!
boa279
Flowcode V4 User
 
Posts: 38
Joined: Mon Sep 15, 2008 11:47 pm
Has thanked: 0 time
Have thanks: 0 time

Advertisement

Re: adc controlled PWM output???

Postby boa279 » Tue Sep 29, 2009 7:07 am

Id actually like to see it adjustable from 1-100Hz first...Im being told that the plunger in the solenoid probably cant move faster than in this area. I have try and read the Hz in a car with this transmission to get the exact number. Anyone?
boa279
Flowcode V4 User
 
Posts: 38
Joined: Mon Sep 15, 2008 11:47 pm
Has thanked: 0 time
Have thanks: 0 time

Re: adc controlled PWM output???

Postby Benj » Tue Sep 29, 2009 9:08 am

Hello

The PWM component is more designed for high frequency applications like audio and motor control.

I have implemented something like your solenoid control for stepper motors and it seems to work really well.

Basically you need to automatically switch off the coil after a certain amount of time. To do this you can detect when the coil needs to be activated eg wait for a switch press, start a timer interrupt going, activate the coil, wait for the timer interrupt to count up to a specific value to get your on period, then switch off the coil and the timer interrupt, then repeat.

Hope this helps.
Regards Ben Rowland - Matrix Technology Solutions Limited
For access to the Flowcode v4 forum topic - Click here
For access to the Flowcode v5 forum topic - Click here
User avatar
Benj
Matrix Staff
 
Posts: 8276
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix Multimedia Ltd
Has thanked: 1198 times
Have thanks: 1533 times

Re: adc controlled PWM output???

Postby Benj » Tue Sep 29, 2009 11:20 am

Hello

Can you get a scope onto the current controller to measure the frequency and the mark space ratio that is being used.

You could also measure this using a timer interrupt. Eg when the signal is high start the timer and begin counting. When the signal goes low save the count value and begin counting again. When the signal goes high again stop counting and display the two values.
Regards Ben Rowland - Matrix Technology Solutions Limited
For access to the Flowcode v4 forum topic - Click here
For access to the Flowcode v5 forum topic - Click here
User avatar
Benj
Matrix Staff
 
Posts: 8276
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix Multimedia Ltd
Has thanked: 1198 times
Have thanks: 1533 times

Re: adc controlled PWM output???

Postby medelec35 » Wed Sep 30, 2009 8:02 am

boa279.
PWM is pulse width modulation. Basically the frequency stays the same, but the on time is varied hence the on width time. E.g. at 100Hz the pulse could be on for 3ms (milliseconds), and off for 7ms. Duty = (3/(3+7))*100 = 30%
Total time should add up to 1/f = 1/100 = 10ms
So duty is a ratio of on time to off time.
In the above example voltage will be high for 30% of the time and low for 70% of the time.

In your post you were talking about adjusting frequency. If you adjust frequency then you’re on and off times should be equal, however since is a repetitive pulse then duty will be 50%
So these are two different things.
Do you want to have adjustable PWM at a set frequency, or adjustable frequency?
My guess is you would need to determine a set frequency and have a variable duty. That is the way LED’s for instance are dimmed. Frequency is set fast enough to eliminate flickering
If you're hardware is not working as expected, try looking here first:
viewtopic.php?f=26&t=6936

If you find any posts that are useful, please click on the 'thumbs up' icon next to Quote button on that post.
User avatar
medelec35
Valued Contributor
Valued Contributor
 
Posts: 5085
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire
Has thanked: 1263 times
Have thanks: 1470 times

Re: adc controlled PWM output???

Postby boa279 » Wed Sep 30, 2009 9:55 am

I have a meter that's capable of measuring Hz and duty cycle but I'm away from the car at the moment. I understand what pulse width modulation is and how it works in motors but not how its utilized in flowcode. Here is some info Ive found but cant confirm until I get back home (a week or so)

Apparently the duty cycle is somewhere in the 95% range...I guess anything less will cause slipping in the transmission and burn cluctches.

[quote="medelec35"]
In your post you were talking about adjusting frequency. If you adjust frequency then you’re on and off times should be equal, however since is a repetitive pulse then duty will be 50%
So these are two different things.

Maybe I'm not understanding this...In my mind I can have a 90% duty cycle that occurs once a second or 100 times a second..Is this not correct? I can change the frequency at which a single duty cycle occurs whether its 50/50 or 90/10 right? So just for example's sake lets say I measure it at 40Hz....I should be able to produce a 20/80 or 40/60 or 97/3 duty cycle which cycles at 40hz?? If this is incorrect I'm totally lost.

I will play with the timer interrupt idea (never messed with that either) and see what I can come up with before I get back home :mrgreen: THANKS for the help everyone
boa279
Flowcode V4 User
 
Posts: 38
Joined: Mon Sep 15, 2008 11:47 pm
Has thanked: 0 time
Have thanks: 0 time

Re: adc controlled PWM output???

Postby boa279 » Thu Oct 01, 2009 9:42 am

Ok, here is what I came up with. For some reason the math does not work out when the ADC is below 31 (byte) and posts negative numbers (on freq setup). Should work fine but maybe its a bug. I also noticed that the LCD position is off by one...Im not sure if anyone else got this? For example when the cursor is moved to (12,0) it actually print on 13,0 ...just something I noticed different than version 3. I also understand that the frequency is not exact because Im not taking into account the time to complete the instructions in between on and off cycles but It does not have to be perfect. I would really appreciate any help (in particular a reason why Im getting the negative numbers on the adc during freq setup) or perhaps someone can modify this to work a little better. Tell me what you think!

EDIT:: THIS IS FOR FLOWCODE 4
Attachments
duty cycle.fcf
(15.98 KiB) Downloaded 196 times
boa279
Flowcode V4 User
 
Posts: 38
Joined: Mon Sep 15, 2008 11:47 pm
Has thanked: 0 time
Have thanks: 0 time

Re: adc controlled PWM output???

Postby Benj » Thu Oct 01, 2009 1:18 pm

Hello

Your program was doing strange things because you were trying to do a lot of floating point calculations using integer variables. I have ammended your program so that it now uses the floating point functions. Note this may have increased the compiled program size significantly.

If the calculation icon that I added is not working correctly then let me know. It could be that your version of Flowcode will need updating to allow certain float functions to work correctly.
Attachments
duty cycle.fcf
(16.93 KiB) Downloaded 190 times
Regards Ben Rowland - Matrix Technology Solutions Limited
For access to the Flowcode v4 forum topic - Click here
For access to the Flowcode v5 forum topic - Click here
User avatar
Benj
Matrix Staff
 
Posts: 8276
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix Multimedia Ltd
Has thanked: 1198 times
Have thanks: 1533 times

Re: adc controlled PWM output???

Postby boa279 » Thu Oct 01, 2009 2:15 pm

Benj wrote:Hello

Your program was doing strange things because you were trying to do a lot of floating point calculations using integer variables. I have ammended your program so that it now uses the floating point functions. Note this may have increased the compiled program size significantly.

If the calculation icon that I added is not working correctly then let me know. It could be that your version of Flowcode will need updating to allow certain float functions to work correctly.



This will not work...attached is a pic of what its telling me and when I continue anyway it goes in an endless loop that wont allow me to stop simulation..have to cntrl alt delete and cancel the flowcode process to break it
Attachments
float.JPG
float.JPG (17.08 KiB) Viewed 2410 times
boa279
Flowcode V4 User
 
Posts: 38
Joined: Mon Sep 15, 2008 11:47 pm
Has thanked: 0 time
Have thanks: 0 time

Re: adc controlled PWM output???

Postby Benj » Thu Oct 01, 2009 3:11 pm

Hello

OK theres a fix coming for the problem you are having. For now I will have to do this another way. Please bear with me.
Regards Ben Rowland - Matrix Technology Solutions Limited
For access to the Flowcode v4 forum topic - Click here
For access to the Flowcode v5 forum topic - Click here
User avatar
Benj
Matrix Staff
 
Posts: 8276
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix Multimedia Ltd
Has thanked: 1198 times
Have thanks: 1533 times

Re: adc controlled PWM output???

Postby boa279 » Thu Oct 01, 2009 3:20 pm

no problem...your the one bearing with me!!! :mrgreen:
boa279
Flowcode V4 User
 
Posts: 38
Joined: Mon Sep 15, 2008 11:47 pm
Has thanked: 0 time
Have thanks: 0 time

Re: adc controlled PWM output???

Postby Benj » Thu Oct 01, 2009 3:27 pm

Hello

Ok this version of the program will not simulate though it should run fine on your hardware. Make sure you define a chip configuration before trying on hardware.

The program I sent before will simulate but it requires some of the fixes that are included in V4.2 of Flowcode, this is why you could not run this correctly before.
Attachments
duty cycle v2.fcf
(17.99 KiB) Downloaded 183 times
Regards Ben Rowland - Matrix Technology Solutions Limited
For access to the Flowcode v4 forum topic - Click here
For access to the Flowcode v5 forum topic - Click here
User avatar
Benj
Matrix Staff
 
Posts: 8276
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix Multimedia Ltd
Has thanked: 1198 times
Have thanks: 1533 times

Re: adc controlled PWM output???

Postby Benj » Thu Oct 01, 2009 3:33 pm

I've just noticed that your output LED is connected to the same pin as the ADC pot. You may want to change this so the program can run correctly.
Regards Ben Rowland - Matrix Technology Solutions Limited
For access to the Flowcode v4 forum topic - Click here
For access to the Flowcode v5 forum topic - Click here
User avatar
Benj
Matrix Staff
 
Posts: 8276
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix Multimedia Ltd
Has thanked: 1198 times
Have thanks: 1533 times

Re: adc controlled PWM output???

Postby Benj » Thu Oct 01, 2009 3:41 pm

Hello

I also noticed you had another divide by 2.55 in the duty cycle setup part of your program so this has also been fixed. I have tested on hardware here and the program is now working correctly.
Attachments
duty cycle v3.fcf
(17.77 KiB) Downloaded 278 times
Regards Ben Rowland - Matrix Technology Solutions Limited
For access to the Flowcode v4 forum topic - Click here
For access to the Flowcode v5 forum topic - Click here
User avatar
Benj
Matrix Staff
 
Posts: 8276
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix Multimedia Ltd
Has thanked: 1198 times
Have thanks: 1533 times

Re: adc controlled PWM output???

Postby boa279 » Thu Oct 01, 2009 6:14 pm

works great...THANK YOU FOR YOUR WORK!!!
boa279
Flowcode V4 User
 
Posts: 38
Joined: Mon Sep 15, 2008 11:47 pm
Has thanked: 0 time
Have thanks: 0 time


Return to Flowcode V2 & V3

Who is online

Users browsing this forum: No registered users and 1 guest