View previous topic :: View next topic |
Author |
Message |
ICeZer0
Joined: 14 Apr 2016 Posts: 4
|
PIC18F4455 RPM Interrupt |
Posted: Thu Apr 14, 2016 2:17 pm |
|
|
Hi all,
I have looked through the forums and I think my issue is unique enough. I am using the PIC18 to implement a PID controller to match the desired voltage of a battery. The PID requires constant monitoring of the ADC set at 100ms on timer3. Now I have implemented a RPM method on timer1 but since the RPM method needs to count it interferes with my program and causes the PID not to work. I had the RPM method on a 50ms interrupt, I think this is happening because of the do while loop not sure how to fix it. How can I make the timers not mess with each other?
Thanks!
Code: |
void HallEffect()
{
start_Measurement();
do
{
delay_ms(1000);
}while(!meas_done);
disable_interrupts(INT_TIMER1);
disable_interrupts(INT_EXT);
theRPM = sensor_pulses * 60;
sensor_pulses = 0;
printf(lcd_putc,"rpm = %ld\n", theRPM);
theRPM = 0;
}
void start_Measurement()
{
meas_done = false;
loops = 20; //50ms * 20 = 1000ms
set_timer1(0);
enable_interrupts(INT_TIMER1);
enable_interrupts(INT_EXT); //interrupt every pulse from senor
}
|
|
|
![](templates/subSilver/images/spacer.gif) |
temtronic
Joined: 01 Jul 2010 Posts: 9177 Location: Greensville,Ontario
|
|
Posted: Thu Apr 14, 2016 3:14 pm |
|
|
Ok, I'm lost ..
just WHERE or HOW do you get a rotational measurement from a battery ?
Really you need to properly explain what you're trying to accomplish , inputs, outputs,rates,frequecny, tc.
At first I thought you were building a battery charger but RPM has mescratching my head.
I do like a challenge though !
Jay |
|
![](templates/subSilver/images/spacer.gif) |
ICeZer0
Joined: 14 Apr 2016 Posts: 4
|
|
Posted: Thu Apr 14, 2016 3:23 pm |
|
|
haha sorry I guess that is really confusing!
So we have an alternator connected to a stationary bicycle trainer then we are turning the alternator to produce a voltage to charge the battery. The system also has the capability to provide a resistive ride for the user. The PIC is sending a PWM signal to the generator; the duty cycle depends on the error from the PID controller. The error is calculated by sensing the ADC difference from the generator and the battery level. Everything is working on the project but I wanted to display on our GUI the distanced pedaled by calculating the RPM. The only free timer I have left is timer1. Hope that clears things up
Last edited by ICeZer0 on Thu Apr 14, 2016 7:18 pm; edited 1 time in total |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Apr 14, 2016 3:35 pm |
|
|
Quote: | I had the RPM method on a 50ms interrupt
enable_interrupts(INT_TIMER1);
enable_interrupts(INT_EXT); //interrupt every pulse from senor
|
Post your interrupt routines. Post the frequency of the incoming signal
on the External interrupt pin. |
|
![](templates/subSilver/images/spacer.gif) |
ICeZer0
Joined: 14 Apr 2016 Posts: 4
|
|
Posted: Thu Apr 14, 2016 7:14 pm |
|
|
.
Last edited by ICeZer0 on Sat Apr 23, 2016 8:33 am; edited 1 time in total |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Apr 14, 2016 10:22 pm |
|
|
Your complaint is that you have to sit in this loop:
Quote: | do
{
delay_ms(1000);
}while(!meas_done);
|
The thread you referenced suggests two methods. Why not use the CCP
method ? You don't have to wait in a loop with that method. |
|
![](templates/subSilver/images/spacer.gif) |
ICeZer0
Joined: 14 Apr 2016 Posts: 4
|
|
Posted: Fri Apr 15, 2016 5:45 am |
|
|
Doesn't the receive buffer for the RS-232 use Timer0? I didnt use CCP2 because of that. Can you explain a little more how I would set this up with CCP2? I know it can capture input, but measuring time in PIC C I am not clear on how it works. What method to use, how to start the time, how to end the timer. |
|
![](templates/subSilver/images/spacer.gif) |
temtronic
Joined: 01 Jul 2010 Posts: 9177 Location: Greensville,Ontario
|
|
Posted: Fri Apr 15, 2016 7:40 am |
|
|
Try searching the forum for 'tachometer' or 'rpm', several code examples here. Quite a common 'theme'.
Jay |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
![](templates/subSilver/images/spacer.gif) |
|