First I tried to convert digital to analog using resistors, and many digital bits, but I find it such a waste of binary bits this way.
Then I had the idea to charge a capacitor by giving it impulses from the PIC using only one bit.
This is what I did:
I did not calculate any of the resistor/capacitor, I just approximated...
And this is the code in MikroC
So all it does is to try to mimic the analog input 0.
But this was just a test, I plan to use the analog generated to change the power of a stepper mottor. At low RPM I plan to give lower power, and increase the power as I increase the RPM.
I don't have an assciloscope to see exactly the output of the generated analog, but measuring with a voltmeter it seems pretty good.
Is is good enough for changing the power of a stepper motor ?
By the way, I plan to connect the analog output to a transistor that will be connected to the stepper motor driver, I don't plan to connct it directly (in case you are thinking about that)...
PS. The microcontroller is running at 20 MHz
Then I had the idea to charge a capacitor by giving it impulses from the PIC using only one bit.
This is what I did:
I did not calculate any of the resistor/capacitor, I just approximated...
And this is the code in MikroC
Rich (BB code):
void main() {
unsigned int adc0 = 0;
unsigned int adc1 = 0;
ADCON0 = 0x80;
TRISA = 0xFF;
PORTD = 0;
TRISD = 0;
do {
adc0 = Adc_Read(0);
adc1 = Adc_Read(1);
if (adc0 > adc1)
PORTD.F4 = 1;
else
PORTD.F4 = 0;
} while (1);
}
But this was just a test, I plan to use the analog generated to change the power of a stepper mottor. At low RPM I plan to give lower power, and increase the power as I increase the RPM.
I don't have an assciloscope to see exactly the output of the generated analog, but measuring with a voltmeter it seems pretty good.
Is is good enough for changing the power of a stepper motor ?
By the way, I plan to connect the analog output to a transistor that will be connected to the stepper motor driver, I don't plan to connct it directly (in case you are thinking about that)...
PS. The microcontroller is running at 20 MHz
Attachments
-
20.6 KB Views: 353
Last edited: