|
|
View previous topic :: View next topic |
Author |
Message |
Blob
Joined: 02 Jan 2006 Posts: 75 Location: Neeroeteren, Limburg, Belgium
|
ccp take over problem |
Posted: Thu May 12, 2011 6:29 am |
|
|
Hello All,
On my rotating disc project, I came across a new problem.
To summarise: I have a rotating disc with 18 teeth on it.
One of the teeth is slightly different. With a magnetic pick-up and a little circuit I make a square wave of the input signal
In a polling loop I determine the position of the flywheel in relation to the pick-up.
On every position of the flywheel I will have to do different things, reading sensors, setting outputs calculate delays etc.
Now the new problem is as following.
The flywheel will turn one rotation in mode 1 and one in mode 2 than back mode 1, mode 2,...
There is an output that I have to set like a kind of pwm.
According to the rpm and other inputs, it will be activated from 0.25 to 10 ms each 2 rotations.
There are however some restrictions to the pulse.
When the pulse is short it must start at position 16 and it may prolong till position 4.
No problem here, I set my output high at position 16
and use
Code: |
if(mode == 2)
setup_ccp1(CCP_USE_TIMER3 | CCP_COMPARE_CLR_ON_MATCH); |
to clear it.
But when the value of CCP exceeds 120° (from position 16 to 4 = 120°)
The output should be setted before position 16.
In fact the output pulse will first grow to later side of the rotation and when it reaches position 4 it will grow to the earlier side of the rotation.
At high rpm it can even be set in mode 2 and staying high till position 4 in the next mode 2.
To solve this I use CCP the other way around, instead of clearing the output, I will set it.
The problem in using CCP is that I can not have a timer overflow.
So at low rpm I use timer 3 DIV_BY_8, at high rpm DIV_BY_4.
I calculate the duration of 1 rotation.
@ position 4
If my output duration is less than 1 rotation, I will set CCP in mode 1 cycle
like this: Code: |
if(mode == 1)
{
CCP_1 = t_rotation - out_time;
setup_ccp1(CCP_USE_TIMER3 | CCP_COMPARE_SET_ON_MATCH);
}
else
{
setup_ccp1(CCP_OFF);
output_low(output);
}
|
If my output duration is higher that 1 rotation, I set CCP like this:
Code: | if(mode == 2)
{
output_low(output);
CCP_1 = 2*t_rotation - out_time;
setup_ccp1(CCP_USE_TIMER3 | CCP_COMPARE_SET_ON_MATCH);
} |
The take over from ccp - set from mode 1 to mode 2 works fine.
But the take over from ccp-clear at position 16 to ccp_set at position 4 gives an error output at changing point, before and after this point it is ok.
I tried to set a boolean high at position 4 when t_out > 120°.
This disables the ccp at postition 16.
Is there anything to overcome this interference?
Thanks,
BLOB |
|
|
Blob
Joined: 02 Jan 2006 Posts: 75 Location: Neeroeteren, Limburg, Belgium
|
|
Posted: Fri May 13, 2011 2:05 am |
|
|
Got it,
I made a fail safe solid state like structure around the modes to prevent ccps getting mixed up.
Best regards,
Blob |
|
|
|
|
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
|