|
|
View previous topic :: View next topic |
Author |
Message |
george Guest
|
help finding info |
Posted: Sun Feb 22, 2004 7:54 pm |
|
|
where can i find some information on the fastest swittiching times for the pins on a port for a 16F877a? I have been looking but cant find this information.
i have been trying to sample a PWM signal at 1 khz and modify it (increase or decrease the pulses) as needed and can only get marginal results at around 300hz. i really need to solve this problem or im in trouble with a project i am working on.
i am reading the pwm on port C and outputting the results on other port c pins, if i were to output the modified signal on a different port would that help? i will keep looking for info, but if anyone has any ideas please let me know.
i will attach a code snippet that is the main program on that pic.
thanks,
while(true){
if (input(pin_c4)){ count++; // is the (+) pwm sig on?
delay_us(delay_neg); // if delay needed, lower voltage
output_bit(pin_c0,1); // turns on (+) FET
while (input(pin_c4)) {} // just a loop while pwm on
delay_us(delay_pos); // if delay needed, higher voltage
output_bit(pin_c0,0); // FET off
}
if (input(pin_c5)){ count++; // is the (-) pwm sig on?
delay_us(delay_neg); // if delay needed, lower voltage
output_bit(pin_c2,1); // turns on (-) FET
while (input(pin_c2)) {} // just a loop while pwm on
delay_us(delay_pos); // if delay needed, higher voltage
output_bit(pin_c2,0); // FET off
}
if (count > 60){ // check every 60 pulses
x = input(pin_c1);
if (x && (delay_neg)) delay_neg--;
if (x && (delay_neg == 0)) delay_pos++;
if ((x==0) && (delay_pos)) delay_pos--;
if ((x==0) && (delay_pos == 0) delay_neg++;
count = 0; // reset counter
if(input(pin_d0) && input(pin_d1){
output_bit(pin_c1,0);
output_bit(pin_c2,0);
reset_cpu();
}
}
}
} |
|
|
george Guest
|
|
Posted: Sun Feb 22, 2004 9:41 pm |
|
|
i am reading the docs on the microchip site, it looks like if i read the pwm on port c and output on say port b that i will get better response as there will be no wait time for the pins to stabilize after a read (i didnt know this)
is this correct or an i barking up the wrong tree. |
|
|
jds-pic2 Guest
|
|
Posted: Sun Feb 22, 2004 10:01 pm |
|
|
george wrote: | where can i find some information on the fastest swittiching times for the pins |
george,
forget the PIC and the SW for a second.
tell us a little about your input circuit -- where it's coming from, how long the leads are, how noisy it is, whether it's buffered, what value pullups/downs are employed, and so forth.
tell us a little about your output circuit -- where it's going to, how long the leads are, what input capacitance is being driven, whether it's buffered, what value pullups/downs are employed, and so forth.
jds-pic |
|
|
george Guest
|
|
Posted: Sun Feb 22, 2004 11:04 pm |
|
|
ok, here goes,
The circuit is seperating the PWM of a sine wave into two channels one for the positive 1/2 cycle and one for the negative 1/2 cycle. The two signals going to the pic are alternating active for a 1/2 cycle each. The signal is sent to the pic directly from a 74hc00, via a short 7 inch 50ohm coax line. The signal at the pic input is a clean signal and well defined with minimal noise (almost un detectable). I am not using any pull ups, just the signal from the 74hc00 stright to the pic port c. At the output I have a hex inverter to supply the inverter section. so it shouldnt be loading down the pic output.
as for the capactance, i dont have a clue, this is a project I am making on a perf board with point to point wireing.
This is a final term project and in theory it should work fine, but the pic isnt acting as I was hopeing. I hope I can find get this working, I have spent quite alot of time in the design of this project and do not have the time for a redesign with another pic.
at the output of the pic the waveform is shakey and a bit unstable and goes to hell at above 300hz for the pwm. I was thinking when i get the time to work on it again i would move the output to a different port so I am not reading then writing immediatly to the same port. If you have an idea please let me know, because i spent like 12 hours trouble shooting and modifing my design the other day and now this :(
thanks in advance. |
|
|
george Guest
|
|
Posted: Tue Feb 24, 2004 7:17 pm |
|
|
guys, someone must have an idea of what i should do with this problem. will pullups and moving the output to a different port allow me to monitor/modify a pwm signal of 2khz?
i know the processor is fast enough, 20mhz crystal gives 5 mhz internal clock and with the clock cycles of the instructions taken into account it shouldnt be a problem.
i still cant find the max speed of switching the port pins. please if you know tell me.
thanks |
|
|
pat
Joined: 07 Sep 2003 Posts: 40 Location: Adelaide, Australia
|
|
Posted: Tue Feb 24, 2004 9:30 pm |
|
|
Have you tried using ?
Why are you resetting the cpu every 60 counts?
Surely this is not a rise time issue with the PIC. Is the core function you are trying to achieve to modify the duty cycle of an input signal? ie you're not trying to change its frequency. Sorry but I've read your post and don't fully understand what you're trying to do.
Have you thought about using interrupts? Not that you want to sit in an interrupt waiting for your signal to change state ie Code: | while (input (pin_x)); | but you may be able to set some flags that you use in the main loop.
I used interrupts to clamp the frequency of a 50% duty cycle square wave, to remove a speed limiter in my car. I set the flag disable_speed_limiter in the main loop based on the clamp frequency of the signal. You might get something useful from this:
Code: | #int_ext
void pulse_isr (void) {
if (dist_rising == true) {
/* Reproduce pulses on dist out signal - Fet off = high */
if (!disable_speed_limiter) output_low (dist_out);
/* Interrupt due to rising edge */
ext_int_edge (H_TO_L);
dist_rising = false;
/* Reset timer 1 */
set_timer1 (0);
timer_1_rollover = false;
/* Count number of distance pulses */
pulse_a++;
pulse_b++;
}
else {
/* Reproduce pulses on dist out signal - Fet on = low */
if (!disable_speed_limiter) output_high (dist_out);
/* Interrupt due to falling edge */
ext_int_edge (L_TO_H);
dist_rising = true;
/* Measure distance pulse width */
if (timer_1_rollover) {
/* Set speed to minimum as pulse width too wide, ie speed < 1.34 km/h */
pulse_width = 0xFFFF;
}
else {
pulse_width = get_timer1 ();
/* Prevent timer 1 rollover before next rising edge */
set_timer1 (0);
}
}
} |
|
|
|
george Guest
|
|
Posted: Wed Feb 25, 2004 11:57 am |
|
|
sorry if i wasnt clear on describing what I am trying to do,
I am making an inverter system to convert a dc supply into a 60hz sine wave output. In the pic I am sampling a pwm signal that is being generated by comparing a 60hz sine wave with a 1-2khz triangle wave to produce a pwm in another section of the circuit.
This pwm signal is being used to drive a bank of FETs connected to a transformer to produce a 60hz sine wave at the output.
The reason I am using the pic is to increase and decrease the width of the pwm signal to allow adjustment of the output voltage with variations of the load via a feedback circuit.
the reset_cpu() is only called when a push button is pressed to stop / reset the system, otherwise it is not called and the loop continues.
I havent worked on this for 3 or 4 days, and when I get to work on it again I am going to move the inputs and outputs to different ports and install pull up resistors.
thank you so much for your reply pat, how fast was your system running in the pwm code you used? |
|
|
Neutone
Joined: 08 Sep 2003 Posts: 839 Location: Houston
|
|
Posted: Wed Feb 25, 2004 12:50 pm |
|
|
If you want a push button to reset your PIC simply wire it from MCLR to ground through that switch. Pressing the switch will cause a reset. No need to do this in code. |
|
|
george Guest
|
|
Posted: Wed Feb 25, 2004 1:06 pm |
|
|
I would have done that , but the reset button is not connected to that pic directly, it is actually connected to a second pic and I am shutting the system down (opening relays etc) on the second pic then sending a message to the first pic that is doing the pwm to reset. so I am doing the software reset.
thanks |
|
|
pat
Joined: 07 Sep 2003 Posts: 40 Location: Adelaide, Australia
|
|
Posted: Wed Feb 25, 2004 4:47 pm |
|
|
George, I understand what you're trying to do now, thanks for the clarificatin.
I've only tested my circuit down to a pulse width of about 1.8ms, which is about 283Hz, and this about the freq at which your problem begins.
However, I can see no reason whatsoever that it wouldn't work at much higher frequencies, becuase the largest number of instructions executed in my ISR is about 30, and I'm only running at 4MHz, ie I'll spend 30us + ISR overhead (another 30 instructions?), lets say, total of 60us in the ISR. So in my application, in theory, I could run up to around 5kHz, and even then, I could probably optimise my ISR to run a bit faster.
Remember all I'm doing is reproducing a signal input on port B to another output bit on port B, up to a certain frequency, then I use the a timer interrupt routine to take over the output signal which clamps the signal to that max freq.
Did you check if you're using fast_io?
Have you thought of using a timer interrupt to implement at least one of your pos or neg time delays? It might even be possible to use a single timer to do both, or else you could user timer_0 for pos, and timer_1 for neg, possibly eliminating the need to increment/decrement those counters in the main loop.
Good luck,
Pat |
|
|
george Guest
|
|
Posted: Wed Feb 25, 2004 9:55 pm |
|
|
thanks to those that answered me.
I think I figgured it out, I looked at the code that ccs produces for the code on the pic, and i calculated that it would take a maximum of 20us to execute the raw code, the shortest pulse in my system will be 53us.
so the pic will handle the speed,
I guess that I need to put in the pull ups and move the O/P to a different port then the I/P
I believe that the port can be toggled on and off within 53 us, I guess that I will find out next week when I get back at it. |
|
|
|
|
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
|