## Re: [Gumstix-users] using robostix pwm outputs sans servo pulses

 Re: [Gumstix-users] using robostix pwm outputs sans servo pulses From: Dave Hylands - 2006-04-17 22:23:26 ```Hi Peter, > > So, if you can tell me what frequency you'd like to generate, I can > > suggest some prescalar/ICRx values which would be appropriate. > > Ah so the prescalar is what I'm missing. Is that just a multiplier? It's a divider. It takes the 16 MHz clock and divides it down by one of the following factors: 1, 8, 64, 256, or 1024. > The signal I'm trying to generate is for a motor controller, the speed > of the motor is determined by the pwm frequency. 'up to 10Khz' > according to the docs, so It'd be nice to be able to set the freqency > anywhere in that range. So, using a prescalar of 1, and ICR set to 1600 would give 10kHz. ICR set to 65536 would give 244 Hz. 16,000,000 counts/sec / 10,000 cycles/sec =3D 1,600 counts/cycle Vary OCRxA between 0 and ICRx to get the appropriate duty cycle. > Did I properly set that pin as an output > using 'i2c-io 0x0b setdir e.3 out' or should I write to the ddre > register? setdir is really just a convenience function for setting the direction of a single pin. The prescalar is the bottom 3 bits in TCCRxB. The servo sample uses 0x1A which puts a binary 010 into the prescalar (which maps to divide by 8). You want to use 001 instead, so use 0x19 instead of 0x1A. A value of 1600 into ICR3 gives you your 10 KHz, and 800 into OCR3A puts it at a 50% duty cycle. Just remember that you need to adjust the OCR registers if you adjust the ICR registers (to maintain the same duty cycle). -- Dave Hylands Vancouver, BC, Canada http://www.DaveHylands.com/ ```

 [Gumstix-users] using robostix pwm outputs sans servo pulses From: Peter Darling - 2006-04-17 21:15:35 ```Hello, I have been struggling a little trying to get a pwm pin on the robostix to output a constant pwm frequency, instead of pulsing it for servos. I use pwm1 for servos, so I'm using robostix's pwm3a pin for this. this is what I'm trying # i2c-load --reset 0x0b run Detected ATMega128 # i2c-io 0x0b setdir e.3 out # i2c-io 0x0b wr icr3 100000 Looking at this, I'm not sure if the timer compare stuff I use on servos is for the pwm frequency timing or the timing of the pulses for the servos. I tinkered with ocr3a a bit.. At any rate, it's not working, can somebody point out what I'm missing? Thanks, peter ```
 Re: [Gumstix-users] using robostix pwm outputs sans servo pulses From: Dave Hylands - 2006-04-17 21:36:14 ```Hi Peter, > I have been struggling a little trying to get a pwm pin on the > robostix to output a constant pwm frequency, instead of pulsing it for > servos. I use pwm1 for servos, so I'm using robostix's pwm3a pin for > this. this is what I'm trying > > # i2c-load --reset 0x0b run > Detected ATMega128 > # i2c-io 0x0b setdir e.3 out > # i2c-io 0x0b wr icr3 100000 icr3 is only a 16 bit register, so the max value you can store in it is 655= 35 > Looking at this, I'm not sure if the timer compare stuff I use on > servos is for the pwm frequency timing or the timing of the pulses for > the servos. I tinkered with ocr3a a bit.. At any rate, it's not > working, can somebody point out what I'm missing? So, we can use the servo script as a basis for what you're trying to do. The servo script uses WGM mode 14 (Fast PWM). For this mode, the ICRx register, combined with the prescalar determines the frequency of the PWM signal, and the OCRxA register would determine the duty cycle of the A output. What's important is that all 3 outputs 3A, 3B, and 3C all have to have the same frequency, but they can each have different duty cycles. You also need to ensure that the pins are configured as outputs, and that an appropriate COM mode is set. So, if you can tell me what frequency you'd like to generate, I can suggest some prescalar/ICRx values which would be appropriate. -- Dave Hylands Vancouver, BC, Canada http://www.DaveHylands.com/ ```
 Re: [Gumstix-users] using robostix pwm outputs sans servo pulses From: Peter Darling - 2006-04-17 21:48:35 ```Hey Dave, On 4/17/06, Dave Hylands wrote: > Hi Peter, > > > I have been struggling a little trying to get a pwm pin on the > > robostix to output a constant pwm frequency, instead of pulsing it for > > servos. I use pwm1 for servos, so I'm using robostix's pwm3a pin for > > this. this is what I'm trying > > > > # i2c-load --reset 0x0b run > > Detected ATMega128 > > # i2c-io 0x0b setdir e.3 out > > # i2c-io 0x0b wr icr3 100000 > > icr3 is only a 16 bit register, so the max value you can store in it is 6= 5535 > > > Looking at this, I'm not sure if the timer compare stuff I use on > > servos is for the pwm frequency timing or the timing of the pulses for > > the servos. I tinkered with ocr3a a bit.. At any rate, it's not > > working, can somebody point out what I'm missing? > > So, we can use the servo script as a basis for what you're trying to do. > > The servo script uses WGM mode 14 (Fast PWM). For this mode, the ICRx > register, combined with the prescalar determines the frequency of the > PWM signal, and the OCRxA register would determine the duty cycle of > the A output. > > What's important is that all 3 outputs 3A, 3B, and 3C all have to have > the same frequency, but they can each have different duty cycles. > > You also need to ensure that the pins are configured as outputs, and > that an appropriate COM mode is set. > > So, if you can tell me what frequency you'd like to generate, I can > suggest some prescalar/ICRx values which would be appropriate. Ah so the prescalar is what I'm missing. Is that just a multiplier? The signal I'm trying to generate is for a motor controller, the speed of the motor is determined by the pwm frequency. 'up to 10Khz' according to the docs, so It'd be nice to be able to set the freqency anywhere in that range. Did I properly set that pin as an output using 'i2c-io 0x0b setdir e.3 out' or should I write to the ddre register? Thanks for your help, as usual. -- Peter Darling pdarling@... ```
 Re: [Gumstix-users] using robostix pwm outputs sans servo pulses From: Dave Hylands - 2006-04-17 22:23:26 ```Hi Peter, > > So, if you can tell me what frequency you'd like to generate, I can > > suggest some prescalar/ICRx values which would be appropriate. > > Ah so the prescalar is what I'm missing. Is that just a multiplier? It's a divider. It takes the 16 MHz clock and divides it down by one of the following factors: 1, 8, 64, 256, or 1024. > The signal I'm trying to generate is for a motor controller, the speed > of the motor is determined by the pwm frequency. 'up to 10Khz' > according to the docs, so It'd be nice to be able to set the freqency > anywhere in that range. So, using a prescalar of 1, and ICR set to 1600 would give 10kHz. ICR set to 65536 would give 244 Hz. 16,000,000 counts/sec / 10,000 cycles/sec =3D 1,600 counts/cycle Vary OCRxA between 0 and ICRx to get the appropriate duty cycle. > Did I properly set that pin as an output > using 'i2c-io 0x0b setdir e.3 out' or should I write to the ddre > register? setdir is really just a convenience function for setting the direction of a single pin. The prescalar is the bottom 3 bits in TCCRxB. The servo sample uses 0x1A which puts a binary 010 into the prescalar (which maps to divide by 8). You want to use 001 instead, so use 0x19 instead of 0x1A. A value of 1600 into ICR3 gives you your 10 KHz, and 800 into OCR3A puts it at a 50% duty cycle. Just remember that you need to adjust the OCR registers if you adjust the ICR registers (to maintain the same duty cycle). -- Dave Hylands Vancouver, BC, Canada http://www.DaveHylands.com/ ```
 Re: [Gumstix-users] using robostix pwm outputs sans servo pulses From: Peter Darling - 2006-04-17 22:57:44 ```On 4/17/06, Dave Hylands wrote: > Hi Peter, > > > > So, if you can tell me what frequency you'd like to generate, I can > > > suggest some prescalar/ICRx values which would be appropriate. > > > > Ah so the prescalar is what I'm missing. Is that just a multiplier? > > It's a divider. It takes the 16 MHz clock and divides it down by one > of the following factors: > 1, 8, 64, 256, or 1024. > > > The signal I'm trying to generate is for a motor controller, the speed > > of the motor is determined by the pwm frequency. 'up to 10Khz' > > according to the docs, so It'd be nice to be able to set the freqency > > anywhere in that range. > > So, using a prescalar of 1, and ICR set to 1600 would give 10kHz. ICR > set to 65536 would give 244 Hz. > > 16,000,000 counts/sec / 10,000 cycles/sec =3D 1,600 counts/cycle > > Vary OCRxA between 0 and ICRx to get the appropriate duty cycle. > > > Did I properly set that pin as an output > > using 'i2c-io 0x0b setdir e.3 out' or should I write to the ddre > > register? > > setdir is really just a convenience function for setting the direction > of a single pin. > > The prescalar is the bottom 3 bits in TCCRxB. The servo sample uses > 0x1A which puts a binary 010 into the prescalar (which maps to divide > by 8). You want to use 001 instead, so use 0x19 instead of 0x1A. > > A value of 1600 into ICR3 gives you your 10 KHz, and 800 into OCR3A > puts it at a 50% duty cycle. Just remember that you need to adjust the > OCR registers if you adjust the ICR registers (to maintain the same > duty cycle). Thanks dave, I'll tinker with that tonight. I appreciate the breakdown. -- Peter Darling pdarling@... ```