Bean (Hitt Consulting) said...
Russ,
Thanks, I hope it helps you get started. That's the whole purpose of these forums.
The PWM that the BS2 generates is NOT intended for motor control.
If you have ever looked at the PWM on a scope you will see what I mean. I looks like a bunch of random pulses. These pulses "average out" to whatever PWM value you have specified.
But motors don't handle these random pulses, they want a single pulse with a duty cycle of whatever PWM value to have specified.
That's why I specifically made this project so it could be used for motor control. If you look at the output of the SX on a scope you will see a nice pulse of varying duty cycle.
It takes 20 bytes to set all 16 PWM outputs, at 2400 baud that's 240 characters a second. That's 12 times a second. So you can change the PWM values a maximum of 12 times a second.
The project may be able to run at a higher baud rate, but because of the "fudge factor" caused by the interrupt, I didn't want to push it, and risk getting invalid data.
I'm thinking about expanding this project to make each output programmable to be PWM OR Servo control (0.5 to 1.5mSec pulse every 20mSec). That would be sweet...
Bean.
In your code PWM_SERVO16.SXB, in the main routine if I change the Serial input code from
FOR Count=0 TO 15
GetSerialChar
PWM_Values(Count)=SerialData
NEXT
to
FOR Count=0 TO 3
GetSerialChar
PWM_Values(Count)=SerialData
NEXT
----
to use it for just 4 servos or DC motors or make the 3 a 7 for say 8 units. Will that effectively allow me higher update rates because I am sending less data per update.
You said with 16 channels and a 4 byte header, thats 20 bytes at 240 chars per second allows about 12 updates per second, with 4 channels, it would be 8 bytes or 12 bytes which theoretically would allow 30 or 20 updates per second if needed. Your initialization code set the servo values to 0 so they never will be changed and those unused channels will be ignored.
have I figured this right?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
cheers ... brian riley, n1bq, underhiull center, vermont
Brian,
I see no reason why that wouldn't work.
Of course the "proper" thing would be to modify the interrupt routine to only handle thoses channels, but that will require you to modify the serial "adjusted" rate to account for less time being spent in the interrupt routine.
Let us know if/how it works.
Bean.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
"SX-Video·Module" Now available from Parallax for only $28.95
Bean (Hitt Consulting) said...
Brian,
I see no reason why that wouldn't work.
Of course the "proper" thing would be to modify the interrupt routine to only handle thoses channels, but that will require you to modify the serial "adjusted" rate to account for less time being spent in the interrupt routine.
Let us know if/how it works.
Bean.
Well my proposed modification was crafted in that way for exactly that reason, i.e., not mucking with the ISR. "If it ain't broke, don't fix it!"
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
cheers ... brian riley, n1bq, underhiull center, vermont
Only problem is servos use a dead zone, meaning if it gets close enough, it stops. This is to prevent the servo from oscillating around its target position. So squeezing extra precision in the controller will not result in greater positional accuracy beyond the dead zone the servo implements.
Paul,
The original code allowed only 50 steps between 0.5ms and 1.5ms pulses.
What is the positional resolution of a servo ? How "wide" is the dead zone (in ms) ?
Maybe 50 steps isn't that bad ???
Bean.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
"SX-Video·Module" Now available from Parallax for only $28.95
From the information I can gather, the typical dead band of a servo is 3 to 5 degrees. Power servos used in aircraft surface control have a programmable dead band, but it is mainly used to synchronize ganged servos from fighting each other. Assuming the servo has a travel of 180 degrees (like the one Parallax sells), this corresponds to 1/60th to 1/36th of the servo's travel. So with a driver having 1/50th of a travel resolution, there is only room for 0.6 degrees improvement, assuming the Parallax servo has a dead band of 3 degrees. This hardly seems worth the effort of trying to further optimize the driver.
<edit> The number you asked for would be 16.67 to 27.78 uS dead band width. </edit>
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔ ·1+1=10
Post Edited (Paul Baker) : 8/22/2005 8:50:16 PM GMT
Bean,
1. Can this chip be addressable so it can be used for more than 16 pwm outputs, say i want 32 or 48 etc.?
2. Could you explain or give an example by pic using led's in a matrix?
3. The other thing that would be nice is the ability to change PWM!
Kevin
I have a theory that i haven't tried yet and that is that the red, green and blue may have to have thier own pwm frequency to be able to generate true rgb color mixing. I want to setup 3 555 circuits with squarewave output to test my theory. After having my color cube setup and hooked to a sound to light controller that i changed over to control led's color mixing is fabulous and when you think of the audio frequencies the circuit allows·each 3·led's to have it's own frequency range of audio. I know this is a audio modulated·signal and not pwm and that could be a whole new way of looking at color mixing is by·something that would match a audio·modulated signal.
If you try to mix colors from the computer through one of Al Williams pwm chips you can't match the color from the led's to the color pallette·of the computer.·I setup a program in visual basic to controll the chip and·of coarse the computer generates perfect color and there may be know way of perfectly matching that. I am open for ideas!
If a person wanted to use 3 SX chips one for each color he could set the pwm for that color. I can't find anywhere on the internet that lists the best pwm frequency to use for color mixing. This is the only forum that i have found with some interest in led lighting.
Kevin
Post Edited (DigitalDj) : 8/25/2005 6:22:05 PM GMT
Very interesting! PWM Over 100hz but they list that anything less than 1000 causes more heat. They are also listing that you can up the current another·43%(my calculation)·with pwm. I had read that this was possible but no figures were given for small leds.
Thanks,
Kevin
Post Edited (DigitalDj) : 8/25/2005 8:59:36 PM GMT
Bean...if you do make the board...would you be posting how to get it? this topic is a very interesting one, and although it has become very long to follow up...if you do have the time....you should do it....just let us know where we could get it from.
thanks for your imput
ps
can a bs2 run optocouplers out of the 8 out pins to drive a section of (let's say 8-12 ) leds per outpin ?
is there an email for you so that the question be better-phrased?
I think there is a few of us interested in your pwm chip but i know i still need some questions answered!
Maybe i burn up the threads to much but i am very driven to get all the information that i can and search out all of my possibilities. I recently got bad news on a chip that i spent some time on and multiple phone calls to the manufacturer to use for sound to light control in the fact that in program mode it would only generate 7 colors, that was not enough for me. So now i am looking for other alternatives and·the information that i have got from other members has been great.
I think we have a great community here and i hope i can be a part of it. I have followed Parallax for a long time even when my electronics hobby has shifted to other interests. I plan on buying some chips and boards from Parallax when i figure out what i am going to do on the circuit i want to make.
Let me know more about your chip and what plans you have in the future for other circuits pertaining to pwm. I was interested in doing some beta testing for you but you never got back with me.
Kevin,
I'm working on a Video Overlay module right now. That is taking pretty much 100% of my time.
I plan to make an SX module that will control 64 RGB leds (8x8 matrix) with 16 levels of pwm each (4096 colors).
In a couple weeks I should have the overlay project mostly completed and I can start on the pwm module.
Bean.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
"SX-Video·Module" Now available from Parallax for only $28.95
Bean,
I would be interested if you make it addressable. If it's not addrssable than it's not going to work for me. The other suggestion is make it compatible for multiples of 3 for rgb.
I am thinking of making my color cubes smart cubes with the sx on board and then addressing each cube. I am also thinking of instead of having the cube as one cube but as 8 mini cubes inside. This would be a total of 24 led's·with 8 cubes for a total of 32 mini cubes on each side of my jukebox and would allow me to do patterns. I will control the cubes by usb from the computer using Visual basic or C++ for the main program and matlab to write the code as a plugin for the main program to do the patterns.
Bean (Hitt Consulting) said...
Brian,
True dat [noparse];)[/noparse]
But if you could simplify the ISR you could run it more often and get more resolution from the servos.
Bean.
I have been poring over the code. Two questions:
(1) Do you think that if i removed one bank of outputs from the ISR, say RC, leaving 8 outputs in RB , I could get this thing to update at 4800 or 9600 baud for the serial?
(2) Is there anything 'sacred' about the 'attention code' being "!PWM"??? Could it be shortened to "!P" or even "!"
I am al ittle confused at the math for the PWM ISR, 50 MHz clock ==> 20 nanosec , 1:4 prescaler, RETURNW 250, could you lay out the calculations ... I have gone over it and I know I am missing something.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
cheers ... brian riley, n1bq, underhill center, vermont
Brian,
You may be able to increase the baudrate with out changing the ISR, I just like to be conservative.
1) Yes, but you will have to recalculate the overhead caused the the (now shorter) ISR routine and use that to calculate the adjusted baud rate. Just make sure the ISR is called at least a few times within each serial bit.
2) No, but you want it something that won't be confuse with data. Two character should be okay.
About the math:
interrupt frequency = clock / (returnint * prescaler)
interrupt frequency = 50MHz/(250* 4) = 50KHz
now it takes 256 interrupts for 1 complete PWM cycle.
So 50KHz / 256 = 195.3125 PWM cycles per second
Bean.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
"SX-Video·Module" Now available from Parallax for only $28.95
Bean (Hitt Consulting) said...
Brian,
You may be able to increase the baudrate with out changing the ISR, I just like to be conservative.
1) Yes, but you will have to recalculate the overhead caused the the (now shorter) ISR routine and use that to calculate the adjusted baud rate. Just make sure the ISR is called at least a few times within each serial bit.
2) No, but you want it something that won't be confuse with data. Two character should be okay.
About the math:
interrupt frequency = clock / (returnint * prescaler)
interrupt frequency = 50MHz/(250* 4) = 50KHz
now it takes 256 interrupts for 1 complete PWM cycle.
So 50KHz / 256 = 195.3125 PWM cycles per second
Bean.
OK I am with you so far .... except, where do you come up with "it takes 256 interrupts for 1 complete PWM cycle" ?//
Is that the convenience of the value of a one byte counter?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
cheers ... brian riley, n1bq, underhill center, vermont
Brian,
Lets say you have a PWM value of 255. That means that the output will be high for 255 interrupts, then low for 1 interrupt.
If the PWM value is 1 then the output will be high for 1 interrupt and low for 255 interrupts.
So it takes 256 interrupt for the PWM to complete 1 "cycle". The is called the PWM frequency. If the PWM frequency was too low (like 10 Hz) and you were driving LEDs, you would see them flickering.
Bean.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
"SX-Video·Module" Now available from Parallax for only $28.95
Bean (Hitt Consulting) said...
Brian,
Lets say you have a PWM value of 255. That means that the output will be high for 255 interrupts, then low for 1 interrupt.
If the PWM value is 1 then the output will be high for 1 interrupt and low for 255 interrupts.
So it takes 256 interrupt for the PWM to complete 1 "cycle". The is called the PWM frequency. If the PWM frequency was too low (like 10 Hz) and you were driving LEDs, you would see them flickering.
Bean.
D'uh!!! .. Maybe if it stood up and smacked me in the face. yeah, I understand that. I just wasn't looking at it ight. Now I am.
OK, one more question that I hope isn't equally obvious. As I see it the difference is between "PWM" and "Servo" modes in your PWM is that PWM is just endless pulses of a certain width 0-255 counts out of every 256 interrupts, and Servo is pulses between 1 and 2 milliseconds every 20 milliseconds (about 1024 interrupts) Do I have that right?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
cheers ... brian riley, n1bq, underhill center, vermont
Hello all, I was just wondering if any one had any further developemnts using Bean's code or the SX chips for controling rgb leds.
thanks,
Matthew
Oh yeah, this may be a little base, but say I wanted to conrol this set up with a bs2, can I just serout the data to the SX? Doesn't the SX need to ping the bs2 with a serout before it can serin? I may not have a full grasp of the serout/in functions...
Bean can you give a example of what a line of code would look like to control the outputs on your 16 output pwm program. I know how to send out the serial port i just don't know what your program needs to recieve.
I think this would be great for RGB path or landscape·lights. I've wanted to do this for sometime. The path lights could change color and do patterns. With 16 outputs you could have·multiple of 5rgb lights.
1. Is there enough memory left on the chip to add routines to this?
2. The other thing would be to make it addressable to be able to use more chips, is that possible?
3. Can i use my serial to usb programming kit with this program?
Thanks,
Kevin
Post Edited (DigitalDj) : 4/17/2006 3:57:10 AM GMT
Mattew & Kevin, · There is a BS2 test file on the original post. · Basically you just send "!PWM" then a byte for each PWM channel. · If you had variables for each LED you might send something like...
Kevin said...
1. Is there enough memory left on the chip to add routines to this?
2. The other thing would be to make it addressable to be able to use more chips, is that possible?
3. Can i use my serial to usb programming kit with this program?
· 1. The PWM code takes very little room. Of course it depends on what routines you want to add, there is alot of space left. · 2.·That is possible, you would have to transmit some kind of ID byte. · 3.·As long as it is 2400 baud, it·should work.
I'm currently using a dual digital Potentiometer and a 556 to drive two H-bridges with PWM.
This would be both cheaper and more flexible than my current solution.
Got to try it out and I'm also interesten in a PCB...
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Living on the planet Earth might be expensive but it includes a free trip around the sun every year...
Experience level:
[noparse][[/noparse] ] Let's connect the motor to pin 1, it's a 6V motor so it should be fine.
[noparse][[/noparse] ] OK, I got my resistors hooked up with the LEDs.
[noparse][[/noparse]X] I got the Motor hooked up with the H-bridge and the 555 is supplying the PWM.
[noparse][[/noparse] ] Now, if I can only program the BOE-BOT to interface with he Flux Capacitor.
[noparse][[/noparse] ] I dream in SX28 assembler...
Sorry for not understanding the code needed to control your program.
1. Does each output have a pwm range from 0 to 255?
2. Does the baud need to be in the pwm code SEROUT SPin, 2400, [noparse][[/noparse]"!PWM", R1, G1, B1, R2, G2, B2, R3, G3, B3, R4, G4, B4, R5, G5, B5, 0]
3. Is this the code to output the pins on the SX or what needs to come through the serial input to the SX.
I thought if i was to use the computer and Visual Basic i would need to do· set comport etc. do a
MSComm1.Output = Chr() this is what i used to control Al Williams 8 output chip.
4. Can·your program·be run at 1khz pwm output
I kinda see what your doing with the variables now(duh)!
So i take it that everytime i change a output i still have to tell the other outputs where to stay until a change is made correct?
By chance do you have a variation of the code that would make it a dual H-Bridge controller. I would like to add an introduction to the H-Bridge in my next "Robotics with the BOEBOT" class and am still in the "brain-storming" phase.
The Mark Tilden "dead bug" h-bridge should be a fairly good place to start.
The next step would be to add a chip that provided the PWM and the 2 direction pins. Two PWM pins and 4 direction pins would be the best of course. The h-bridge will also need a PWM transistor added.
If anyone has gone this direction and would like to share what they have done I would like to hear about it. Maybe it would need to go into a new thread, but I thought that I would start by asking Bean in here.
Wow!· Thanks so much guys for all this knowledge, I just read all these posts.· I am interested in increasing the baud rate up to or beyond 9600 and am skeptical of the modification of the baud rate as a means of offseting the interrupt.··Has anyone looked into Ubicom's "Virtual Peripherals" as a means of doing the seral communication?· They say they have "8 slots in the interrupt and the serial port takes 2"· It seems that the other 6 could be used for PWM control, but they don't have an app note for that.· Also their code is in assembly and I'm not there yet.· ASM, ENDASM seem feasible.· See http://www.parallax.com/sx/downloads.asp·for application notes.· I'm still working on this, but I thought maybe someone already had some code?· Even just some serial UART VP code would be great.
Comments
In your code PWM_SERVO16.SXB, in the main routine if I change the Serial input code from
to
----
to use it for just 4 servos or DC motors or make the 3 a 7 for say 8 units. Will that effectively allow me higher update rates because I am sending less data per update.
You said with 16 channels and a 4 byte header, thats 20 bytes at 240 chars per second allows about 12 updates per second, with 4 channels, it would be 8 bytes or 12 bytes which theoretically would allow 30 or 20 updates per second if needed. Your initialization code set the servo values to 0 so they never will be changed and those unused channels will be ignored.
have I figured this right?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
cheers ... brian riley, n1bq, underhiull center, vermont
I see no reason why that wouldn't work.
Of course the "proper" thing would be to modify the interrupt routine to only handle thoses channels, but that will require you to modify the serial "adjusted" rate to account for less time being spent in the interrupt routine.
Let us know if/how it works.
Bean.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
"SX-Video·Module" Now available from Parallax for only $28.95
http://www.parallax.com/detail.asp?product_id=30012
Product web site: www.sxvm.com
"One experiment is worth a thousand theories"
·
Well my proposed modification was crafted in that way for exactly that reason, i.e., not mucking with the ISR. "If it ain't broke, don't fix it!"
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
cheers ... brian riley, n1bq, underhiull center, vermont
True dat [noparse];)[/noparse]
But if you could simplify the ISR you could run it more often and get more resolution from the servos.
Bean.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
"SX-Video·Module" Now available from Parallax for only $28.95
http://www.parallax.com/detail.asp?product_id=30012
Product web site: www.sxvm.com
"One experiment is worth a thousand theories"
·
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
·1+1=10
The original code allowed only 50 steps between 0.5ms and 1.5ms pulses.
What is the positional resolution of a servo ? How "wide" is the dead zone (in ms) ?
Maybe 50 steps isn't that bad ???
Bean.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
"SX-Video·Module" Now available from Parallax for only $28.95
http://www.parallax.com/detail.asp?product_id=30012
Product web site: www.sxvm.com
"One experiment is worth a thousand theories"
·
<edit> The number you asked for would be 16.67 to 27.78 uS dead band width. </edit>
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
·1+1=10
Post Edited (Paul Baker) : 8/22/2005 8:50:16 PM GMT
1. Can this chip be addressable so it can be used for more than 16 pwm outputs, say i want 32 or 48 etc.?
2. Could you explain or give an example by pic using led's in a matrix?
3. The other thing that would be nice is the ability to change PWM!
Kevin
What do you mean by "ability to change PWM" ?
Bean.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
"SX-Video·Module" Now available from Parallax for only $28.95
http://www.parallax.com/detail.asp?product_id=30012
Product web site: www.sxvm.com
"One experiment is worth a thousand theories"
·
I have a theory that i haven't tried yet and that is that the red, green and blue may have to have thier own pwm frequency to be able to generate true rgb color mixing. I want to setup 3 555 circuits with squarewave output to test my theory. After having my color cube setup and hooked to a sound to light controller that i changed over to control led's color mixing is fabulous and when you think of the audio frequencies the circuit allows·each 3·led's to have it's own frequency range of audio. I know this is a audio modulated·signal and not pwm and that could be a whole new way of looking at color mixing is by·something that would match a audio·modulated signal.
If you try to mix colors from the computer through one of Al Williams pwm chips you can't match the color from the led's to the color pallette·of the computer.·I setup a program in visual basic to controll the chip and·of coarse the computer generates perfect color and there may be know way of perfectly matching that. I am open for ideas!
If a person wanted to use 3 SX chips one for each color he could set the pwm for that color. I can't find anywhere on the internet that lists the best pwm frequency to use for color mixing. This is the only forum that i have found with some interest in led lighting.
Kevin
Post Edited (DigitalDj) : 8/25/2005 6:22:05 PM GMT
http://www.lumileds.com/pdfs/AB12.PDF
Chris I.
Thanks,
Kevin
Post Edited (DigitalDj) : 8/25/2005 8:59:36 PM GMT
thanks for your imput
ps
can a bs2 run optocouplers out of the 8 out pins to drive a section of (let's say 8-12 ) leds per outpin ?
is there an email for you so that the question be better-phrased?
I think there is a few of us interested in your pwm chip but i know i still need some questions answered!
Maybe i burn up the threads to much but i am very driven to get all the information that i can and search out all of my possibilities. I recently got bad news on a chip that i spent some time on and multiple phone calls to the manufacturer to use for sound to light control in the fact that in program mode it would only generate 7 colors, that was not enough for me. So now i am looking for other alternatives and·the information that i have got from other members has been great.
I think we have a great community here and i hope i can be a part of it. I have followed Parallax for a long time even when my electronics hobby has shifted to other interests. I plan on buying some chips and boards from Parallax when i figure out what i am going to do on the circuit i want to make.
Let me know more about your chip and what plans you have in the future for other circuits pertaining to pwm. I was interested in doing some beta testing for you but you never got back with me.
Regards,
Kevin
·
I'm working on a Video Overlay module right now. That is taking pretty much 100% of my time.
I plan to make an SX module that will control 64 RGB leds (8x8 matrix) with 16 levels of pwm each (4096 colors).
In a couple weeks I should have the overlay project mostly completed and I can start on the pwm module.
Bean.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
"SX-Video·Module" Now available from Parallax for only $28.95
http://www.parallax.com/detail.asp?product_id=30012
Product web site: www.sxvm.com
"One experiment is worth a thousand theories"
·
I would be interested if you make it addressable. If it's not addrssable than it's not going to work for me. The other suggestion is make it compatible for multiples of 3 for rgb.
I am thinking of making my color cubes smart cubes with the sx on board and then addressing each cube. I am also thinking of instead of having the cube as one cube but as 8 mini cubes inside. This would be a total of 24 led's·with 8 cubes for a total of 32 mini cubes on each side of my jukebox and would allow me to do patterns. I will control the cubes by usb from the computer using Visual basic or C++ for the main program and matlab to write the code as a plugin for the main program to do the patterns.
Kevin
·
I have been poring over the code. Two questions:
(1) Do you think that if i removed one bank of outputs from the ISR, say RC, leaving 8 outputs in RB , I could get this thing to update at 4800 or 9600 baud for the serial?
(2) Is there anything 'sacred' about the 'attention code' being "!PWM"??? Could it be shortened to "!P" or even "!"
I am al ittle confused at the math for the PWM ISR, 50 MHz clock ==> 20 nanosec , 1:4 prescaler, RETURNW 250, could you lay out the calculations ... I have gone over it and I know I am missing something.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
cheers ... brian riley, n1bq, underhill center, vermont
You may be able to increase the baudrate with out changing the ISR, I just like to be conservative.
1) Yes, but you will have to recalculate the overhead caused the the (now shorter) ISR routine and use that to calculate the adjusted baud rate. Just make sure the ISR is called at least a few times within each serial bit.
2) No, but you want it something that won't be confuse with data. Two character should be okay.
About the math:
interrupt frequency = clock / (returnint * prescaler)
interrupt frequency = 50MHz/(250* 4) = 50KHz
now it takes 256 interrupts for 1 complete PWM cycle.
So 50KHz / 256 = 195.3125 PWM cycles per second
Bean.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
"SX-Video·Module" Now available from Parallax for only $28.95
http://www.parallax.com/detail.asp?product_id=30012
Product web site: www.sxvm.com
"One experiment is worth a thousand theories"
·
OK I am with you so far .... except, where do you come up with "it takes 256 interrupts for 1 complete PWM cycle" ?//
Is that the convenience of the value of a one byte counter?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
cheers ... brian riley, n1bq, underhill center, vermont
Lets say you have a PWM value of 255. That means that the output will be high for 255 interrupts, then low for 1 interrupt.
If the PWM value is 1 then the output will be high for 1 interrupt and low for 255 interrupts.
So it takes 256 interrupt for the PWM to complete 1 "cycle". The is called the PWM frequency. If the PWM frequency was too low (like 10 Hz) and you were driving LEDs, you would see them flickering.
Bean.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
"SX-Video·Module" Now available from Parallax for only $28.95
http://www.parallax.com/detail.asp?product_id=30012
Product web site: www.sxvm.com
"One experiment is worth a thousand theories"
·
D'uh!!! .. Maybe if it stood up and smacked me in the face. yeah, I understand that. I just wasn't looking at it ight. Now I am.
OK, one more question that I hope isn't equally obvious. As I see it the difference is between "PWM" and "Servo" modes in your PWM is that PWM is just endless pulses of a certain width 0-255 counts out of every 256 interrupts, and Servo is pulses between 1 and 2 milliseconds every 20 milliseconds (about 1024 interrupts) Do I have that right?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
cheers ... brian riley, n1bq, underhill center, vermont
The "Servo" mode is basically one PWM pulse every 20mSeconds.
Bean.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
"SX-Video·Module" Now available from Parallax for only $28.95
http://www.parallax.com/detail.asp?product_id=30012
Product web site: www.sxvm.com
"One experiment is worth a thousand theories"
·
thanks,
Matthew
Oh yeah, this may be a little base, but say I wanted to conrol this set up with a bs2, can I just serout the data to the SX? Doesn't the SX need to ping the bs2 with a serout before it can serin? I may not have a full grasp of the serout/in functions...
Post Edited (mbmosher) : 4/16/2006 6:39:23 PM GMT
Kevin
I think this would be great for RGB path or landscape·lights. I've wanted to do this for sometime. The path lights could change color and do patterns. With 16 outputs you could have·multiple of 5rgb lights.
1. Is there enough memory left on the chip to add routines to this?
2. The other thing would be to make it addressable to be able to use more chips, is that possible?
3. Can i use my serial to usb programming kit with this program?
Thanks,
Kevin
Post Edited (DigitalDj) : 4/17/2006 3:57:10 AM GMT
· There is a BS2 test file on the original post.
· Basically you just send "!PWM" then a byte for each PWM channel.
· If you had variables for each LED you might send something like...
· 1. The PWM code takes very little room. Of course it depends on what routines you want to add, there is alot of space left.
· 2.·That is possible, you would have to transmit some kind of ID byte.
· 3.·As long as it is 2400 baud, it·should work.
Bean.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
"SX-Video·Module"·available from Parallax for only $28.95 http://www.parallax.com/detail.asp?product_id=30012
"SX-Video OSD module"·available from Parallax for only·$49.95 http://www.parallax.com/detail.asp?product_id=30015
Product web site: www.sxvm.com
Available now! Cheap 4-digit LED display with driver IC·www.hc4led.com
"I reject your reality, and substitute my own." Mythbusters
Post Edited (Bean (Hitt Consulting)) : 4/17/2006 11:25:49 AM GMT
Great job Bean!!!
I'm currently using a dual digital Potentiometer and a 556 to drive two H-bridges with PWM.
This would be both cheaper and more flexible than my current solution.
Got to try it out and I'm also interesten in a PCB...
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Living on the planet Earth might be expensive but it includes a free trip around the sun every year...
Experience level:
[noparse][[/noparse] ] Let's connect the motor to pin 1, it's a 6V motor so it should be fine.
[noparse][[/noparse] ] OK, I got my resistors hooked up with the LEDs.
[noparse][[/noparse]X] I got the Motor hooked up with the H-bridge and the 555 is supplying the PWM.
[noparse][[/noparse] ] Now, if I can only program the BOE-BOT to interface with he Flux Capacitor.
[noparse][[/noparse] ] I dream in SX28 assembler...
/Bamse
Sorry for not understanding the code needed to control your program.
1. Does each output have a pwm range from 0 to 255?
2. Does the baud need to be in the pwm code SEROUT SPin, 2400, [noparse][[/noparse]"!PWM", R1, G1, B1, R2, G2, B2, R3, G3, B3, R4, G4, B4, R5, G5, B5, 0]
3. Is this the code to output the pins on the SX or what needs to come through the serial input to the SX.
I thought if i was to use the computer and Visual Basic i would need to do· set comport etc. do a
MSComm1.Output = Chr() this is what i used to control Al Williams 8 output chip.
4. Can·your program·be run at 1khz pwm output
I kinda see what your doing with the variables now(duh)!
So i take it that everytime i change a output i still have to tell the other outputs where to stay until a change is made correct?
Kevin
By chance do you have a variation of the code that would make it a dual H-Bridge controller. I would like to add an introduction to the H-Bridge in my next "Robotics with the BOEBOT" class and am still in the "brain-storming" phase.
The Mark Tilden "dead bug" h-bridge should be a fairly good place to start.
The next step would be to add a chip that provided the PWM and the 2 direction pins. Two PWM pins and 4 direction pins would be the best of course. The h-bridge will also need a PWM transistor added.
If anyone has gone this direction and would like to share what they have done I would like to hear about it. Maybe it would need to go into a new thread, but I thought that I would start by asking Bean in here.