Log in

View Full Version : GeneratePWMS


Neal Turett
21-02-2004, 14:42
I'm trying to read in a PWM. How do I do this?

On the edubot, they have the "setup who control pwms" function that changes the pwm_mask variable in the tx_data struct, but what does this do for me? This variable exists in the FRC code, so I can change it there, but I don't understand how this gets me input since there is no place for pwm inputs in the rx_data structure.

WCS V
21-02-2004, 14:46
Why do you want to use a pwm as an input?

Neal Turett
21-02-2004, 16:55
some sensors allow I2C input or PWM input, and we don't have access to the I2C

steven114
21-02-2004, 18:44
I believe that there are a few #define statements in one of the header file that change PWMs 13-16 to either IFI_PWM or USER_CCP. That might be what you're looking for...

Astronouth7303
21-02-2004, 20:13
I believe that there are a few #define statements in one of the header file that change PWMs 13-16 to either IFI_PWM or USER_CCP. That might be what you're looking for...

No, that's not it. The Setup_PWM_Output_Type() function is to set up the specifics of the PWM signal. if you don't use IFI_PWM for all 4, you have to set it up yourself (see comment in the default code). this is done in User_Initialization().

steven114
21-02-2004, 20:30
No, that's not it. The Setup_PWM_Output_Type() function is to set up the specifics of the PWM signal. if you don't use IFI_PWM for all 4, you have to set it up yourself (see comment in the default code). this is done in User_Initialization().

I think that that's what I was talking about, sorry, I didn't have the code in front of me...

Neal Turett
23-02-2004, 23:26
Thanks guys. I found a way to do it. Took some experimenting, but here it is:

Run the sensor output into digital inputs 2 and 3. Have interupt on 2 for the rising edge and one for the falling edge. The first starts the timer, the second reads it out and scales it.

I haven't actually tried this - I'll probably fool with it post-build season, but I was just thinking ahead since my team doesn't let me touch the bot. Something about building it....

Jay Lundy
24-02-2004, 00:56
Thanks guys. I found a way to do it. Took some experimenting, but here it is:

Run the sensor output into digital inputs 2 and 3. Have interupt on 2 for the rising edge and one for the falling edge. The first starts the timer, the second reads it out and scales it.

I haven't actually tried this - I'll probably fool with it post-build season, but I was just thinking ahead since my team doesn't let me touch the bot. Something about building it.... You don't have to do it like that. Dig I/O pins 3-6 are interrupt on change, so just plug it into dig io pin 3 and when RBIF triggers check to see that it is indeed pin 3 that changed (since 3-6 all trigger the same flag). You can sense both rising and falling edges on the same pin.

Kevin Watson
24-02-2004, 01:05
You don't have to do it like that. Dig I/O pins 3-6 are interrupt on change, so just plug it into dig io pin 3 and when RBIF triggers check to see that it is indeed pin 3 that changed (since 3-6 all trigger the same flag). You can sense both rising and falling edges on the same pin.Just FYI, interrupts 1 and 2 can also exhibit this behavior if you flip the INTEDGx bit in the interrupt handler. As a starting point, I'd suggest using the code in receiver.c/.h because it pretty much does exactly what you need to do (pulse width discrimination). I'm not sure if it's usable (IFI may have wired-in a output buffer on the CCP pins), but you might also look into using the CCP Capture mode to do this.

-Kevin