Hello again,
I do have another problem....I have generated 2 PWM signals and i have controled 2 DC motors, with 2 different timers. So i can control the motors independently.
Now, after my IR sensor array is done, i tried to put them together, but there are some problems.
I have made a simple program to test the sensors. If i put a white paper in front of the sensor i test, a led from board lights up. If i put a black paper in front of the sensor, the led turns off. I am very please with the response time of the sensor and also with the perturbation that occur when 'neigbour' sensors are emitting.
But, the problem occurs when i want to control motors by reading with sensors black or white. The motors do work, but they do not respect the speed from PWM signal. Sometimes, when i make some modifications in configuration of AD, they change the speed a little bit when different values are red from IR sensor, but the speeds are not OK, they do not follow my PWM signal....
This is the code for my ADC config:
void init_adc()
{
ADCON1bits.FORM = 0;
ADCON1bits.SSRC = 7;
ADCON1bits.ASAM = 1;
ADCON2bits.CSCNA = 1;
// ADCON2bits.CHSP = 0;
ADCON2bits.SMPI = 0;
ADCON3bits.ADRC = 0;
ADCON3bits.ADCS = 31;
ADCSSLbits.CSSL9 = 1;
ADPCFG=0x0000;
//IFS0bits.ADIF = 0;
IPC2bits.ADIP =7;
IEC0bits.ADIE = 1;
ADCON1bits.ADON = 1;
}
void __attribute__((interrupt, no_auto_psv)) _ADCInterrupt(void)
{
ain4Buff[sampleCounter++]=ADCBUF0;
if(sampleCounter==SAMP_BUFF_SIZE)
sampleCounter=0;
if (ADCBUF0>0x0090)
activ=1;
else
activ =0;
IFS0bits.ADIF = 0;
}
When activ==0, the motor should have a speed, and when activ==1 the motor must have another speed....
dsPic30F3014 has 3 timers, timer 2 and timer 3 are used to generate PWM signals via OC channels. I cannot use timer 3 for ADC.
I selected : ADCON1bits.SSRC = 7; as ADC source. In datasheet says from internal counter, it does work with the test i have made with led, but i do not know who is the internal counter....
So, i need some help with this issue. I do not know why the PWM signals are perturbed by the ADC module. Mabye the AD interrupt occurs too often? or... i don't know... please help me...