Hi,
When you say 100ms ... What precision do you need? Are multiples of 20ms or 10ms ok?
If yes, then run a control loop, timer driven with this timing.
Klaus
Since you've not said what you want to do with the motors and solenoids, we can't evaluate what your real accuracy or timing should be.
void Movement(){
TRISD = 0x00;
PORTD = 0x00;
PORTD=0b11111111; //activate the solenoid on port D
Delay_ms(50);
PORTD=0b00000000; //stops it
}
void Movement2(){
TrisC = 0x00;
PortC = 0x00;
PORTC=0b00000110; //activate the solenoid on port C
Delay_ms(50);
PORTC=0b00000000;
}
void Tetarta(const unsigned long Delay,int metra){
int i;
const unsigned long Tetarto=DelayPBms;
metra=metra*4;
for(i = 0; i < metra; i++){
Delay_ms(Tetarto);
Movement();
}}
void Ogdoa(const unsigned long Delay,int metra){
int i;
metra=metra*4;
const unsigned long Ogdoo=DelayPBms/2;
for(i = 0; i < metra; i++){
Delay_ms(Ogdoo);
Movement2();
}}
void main(void)
{
const unsigned long DPBms=60000/Tempo;
Tetarta(DPBms,4); Ogdoa(DPBms,4); //Here is where i want to call these
// two functions to start loops same time on port D and C
}
PORTC=0b00000110; // practically
PORTD=0b11111111; // same time activating two ports
Delay_ms(50);
PORTD=0b00000000;
PORTC=0b00000000;
Delay_ms(50);
PORTC=0b00000110;
Delay_ms(50);
PORTC=0b00000000;
Delay_ms(50);
PORTC=0b00000110;
PORTD=0b11111111;
Delay_ms(50);
PORTD=0b00000000;
PORTC=0b00000000;
//etc. (thats very bad way)
Klaus i think generally you can with posix threads but my pic doesnt support that, so if i dont find schedule events working as i want and cant run two functions then i will just do it manually like :
It is simply possible to activate/deactivate all desired outputs within 10us. For a motor or solenoid I call this "at the same time"will activate ports the same times
* read in all used inputs and store it in variables. ( just to get synchronised input infirmation)
...now process data like:
* if key1 is pressed: mot1 = 100
* if key2 is pressed AND mot2 = 0 then mot2 =150
* if mot2 = 1 Then valve1=50...
...here only prepare the output port data
* if mot1>0 then: motPort=1, decrement mot1
* if mot2>0 then: motPort=2, decrement mot2
* if valve1>0 then: valvePort=1, decrement valve1
...
Output all prepared port data to the ports
RETI
typedef struct _task_ {
unsigned short period;
unsigned short _tmp_countdown;
boolean (*proc)(void);
} task;
task T[10];
void add_task(unsigned short period, boolean (*proc)(void)){
add proc function to the T[] array and set _tmp_countdown to period
}
while(1){
...
while(ticks){
disable_interrupt_tmrX
ticks--;
enable_interrupt_tmrX
for every T[]{
if(T[i].proc && --T[i]._tmp_countdown == 0){
T[i]._tmp_countdown = T[i].period;
if( (*(T[i].proc))() == 0)
T[i].proc = NULL;//drop this proc
}
}
}
bool proc_led1(void){
PORTA ^= 4;//toggle led on RA3
}
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?