adc controlled PWM output???

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

Moderators: Benj, Mods

Post Reply
boa279
Posts: 38
Joined: Mon Sep 15, 2008 11:47 pm
Contact:

adc controlled PWM output???

Post by boa279 »

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
Posts: 38
Joined: Mon Sep 15, 2008 11:47 pm
Contact:

Re: adc controlled PWM output???

Post by boa279 »

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?

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: adc controlled PWM output???

Post by Benj »

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.

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: adc controlled PWM output???

Post by Benj »

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.

medelec35
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 controlled PWM output???

Post by medelec35 »

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
Martin

boa279
Posts: 38
Joined: Mon Sep 15, 2008 11:47 pm
Contact:

Re: adc controlled PWM output???

Post by boa279 »

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
Posts: 38
Joined: Mon Sep 15, 2008 11:47 pm
Contact:

Re: adc controlled PWM output???

Post by boa279 »

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 444 times

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: adc controlled PWM output???

Post by Benj »

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 435 times

boa279
Posts: 38
Joined: Mon Sep 15, 2008 11:47 pm
Contact:

Re: adc controlled PWM output???

Post by boa279 »

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 9692 times

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: adc controlled PWM output???

Post by Benj »

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.

boa279
Posts: 38
Joined: Mon Sep 15, 2008 11:47 pm
Contact:

Re: adc controlled PWM output???

Post by boa279 »

no problem...your the one bearing with me!!! :mrgreen:

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: adc controlled PWM output???

Post by Benj »

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 409 times

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: adc controlled PWM output???

Post by Benj »

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.

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: adc controlled PWM output???

Post by Benj »

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 475 times

boa279
Posts: 38
Joined: Mon Sep 15, 2008 11:47 pm
Contact:

Re: adc controlled PWM output???

Post by boa279 »

works great...THANK YOU FOR YOUR WORK!!!

Post Reply