CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

PIC18F4455 RPM Interrupt

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
ICeZer0



Joined: 14 Apr 2016
Posts: 4

View user's profile Send private message

PIC18F4455 RPM Interrupt
PostPosted: Thu Apr 14, 2016 2:17 pm     Reply with quote

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
}
temtronic



Joined: 01 Jul 2010
Posts: 9178
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Thu Apr 14, 2016 3:14 pm     Reply with quote

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
ICeZer0



Joined: 14 Apr 2016
Posts: 4

View user's profile Send private message

PostPosted: Thu Apr 14, 2016 3:23 pm     Reply with quote

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
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Apr 14, 2016 3:35 pm     Reply with quote

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.
ICeZer0



Joined: 14 Apr 2016
Posts: 4

View user's profile Send private message

PostPosted: Thu Apr 14, 2016 7:14 pm     Reply with quote

Shocked.

Last edited by ICeZer0 on Sat Apr 23, 2016 8:33 am; edited 1 time in total
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Apr 14, 2016 10:22 pm     Reply with quote

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.
ICeZer0



Joined: 14 Apr 2016
Posts: 4

View user's profile Send private message

PostPosted: Fri Apr 15, 2016 5:45 am     Reply with quote

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.
temtronic



Joined: 01 Jul 2010
Posts: 9178
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Fri Apr 15, 2016 7:40 am     Reply with quote

Try searching the forum for 'tachometer' or 'rpm', several code examples here. Quite a common 'theme'.

Jay
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Apr 15, 2016 12:42 pm     Reply with quote

Quote:
Can you explain a little more how I would set this up with CCP2?

Here are some threads on frequency measurement for 16F and 18F PICs:
http://www.ccsinfo.com/forum/viewtopic.php?t=29963
http://www.ccsinfo.com/forum/viewtopic.php?t=41172
http://www.ccsinfo.com/forum/viewtopic.php?t=33153
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group