After further playing.
I can't make it "Lock".
Tried all 4 channels, tried 255/256 RES.
Incidently, 255 does work better. It's not the way I thought I wrote it. But...
That way 0 is always off, and 255 is always on.
<br>
After further playing.
I can't make it "Lock".
Tried all 4 channels, tried 255/256 RES.
Incidently, 255 does work better. It's not the way I thought I wrote it. But...
That way 0 is always off, and 255 is always on.
<br>
DT
Darrel,
If using an LED its hard to make it lock. I think its either related to the power supply I'm using, or some other factor within the circuit as it does it on several loco's. I have a 0.1uf spread accros the power pins of the PIC, and power rails in a bid to decouple the supply. I've also tried changing the 1K base resistor between the NPn and PIC output as I though that the driver circuit may be drawing more than the 25ma the port can take, but that made no difference
Is the PWM outout a square wave, sawtooth or just spikes that are increased in frequency? I would like to stick with PWM as there is less heat to dissapate in the circuit and it provides far better slow starts than varible voltage type controllers. Maybe I should look at using a PIC with hardware PWM, like the 16F690 ??
Definately Squarewave. This is about a third of the way on the POT.
Well, before you change pics. Can you give this program a quick try.
It's just a single channel, no interrupts. It runs at about 3.8khz
It should give an indication whether the higher frequencies of hardware PWM will help or not.Code:@ __CONFIG _HS_OSC & _WDT_ON & _PWRTE_ON & _MCLRE_OFF DEFINE OSC 20 CLEAR ANSEL=%00110001 CMCON=7 TRISA=%11111111 'set PORTA as all input TRISC=%00000001 'set PORTC as all output apart from RC0 PWM1 VAR PORTC.2 DutyCycle1 VAR WORD GoDone VAR ADCON0.1 ADCON1 = %00110000 ADCON0 = %00000011 while GoDone : wend Main: if ADRESH > 1 then high PWM1 DutyCycle1 = ADRESH GoDone = 1 pauseUS DutyCycle1 low PWM1 pauseUS 255 - DutyCycle1 while GoDone : wend else low PWM1 GoDone = 1 while GoDone : wend endif goto Main
DT
as long as the POT impedance meet the maximum recommended.. it shouldn't be much of a problem.
What happen to your supply when you plug your loco directly?
Now, If you add 1 or more?
Now do the same but add your transistor to drive them.. what happen?
i got my few motor here, i'll do some test later.
Steve
It's not a bug, it's a random feature.
There's no problem, only learning opportunities.
Well well well... running 3 different Motor type from 500mA to 10A @12Vdc.. and a pretty messed up breadboard + Jumperit works
2 channel PWM... all square...
3 pwm ... still the same, life is good
BUT... when you add ADCIN 4, DutyVar4... somethings goes bad....
Do one test with anything matched with ADCIN 4... something go really bad... where it comes from... i don't know for now.
Same thing happen if you do something with DutyVar4...
scratch scratch scratch
Last edited by mister_e; - 17th February 2007 at 19:26.
Steve
It's not a bug, it's a random feature.
There's no problem, only learning opportunities.
Everything just fine using...
GO GO GO FIGURE ITCode:@ __CONFIG _HS_OSC & _WDT_ON & _PWRTE_ON & _MCLRE_OFF ANSEL = %00010111 ; - dt suggested value DEFINE OSC 20 CMCON=7 TRISA=%11111111 'set PORTA as all input TRISC=%00000001 'set PORTC as all output apart from RC0 DEFINE ADC_BITS 8 ' ADCIN resolution (Bits) DEFINE ADC_CLOCK 2 ' ADC clock source (Fosc/32) DEFINE ADC_SAMPLEUS 11 ' ADC sampling time (uSec) INCLUDE "DT_INTS-14.bas" ; Base Interrupt System INCLUDE "SPWM_INT.bas" ; Software PWM module DEFINE SPWM_FREQ 150 ; SPWM Frequency DEFINE SPWM_RES 255 ; SPWM Resolution DutyVar VAR byte[4] ASM SPWM_LIST macro ; Define Pin's to use for SPWM SPWM_PIN PORTC, 2, _DutyVar ; and the associated DutyCycle variables SPWM_PIN PORTC, 5, _DutyVar+1 ; Notice the underscore before variables SPWM_PIN PORTC, 4, _DutyVar+2 SPWM_PIN PORTC, 3, _DutyVar+3 endm SPWM_INIT SPWM_LIST ; Initialize the Pins ENDASM ASM INT_LIST macro ; IntSource, Label, Type, ResetFlag? INT_Handler TMR1_INT, SPWMhandler, ASM, yes endm INT_CREATE ; Creates the interrupt processor ENDASM @ INT_ENABLE TMR1_INT ; enable Timer 1 interrupts ;_____________________________________________________________________________ Main: ADCIN 0, DUTYVAR[0] ADCIN 1, DUTYVAR[1] ADCIN 2, DUTYVAR[2] ADCIN 4, DUTYVAR[3] GOTO Main![]()
Steve
It's not a bug, it's a random feature.
There's no problem, only learning opportunities.
Interesting..... works fine, no drop out or locking up after 20 or so tests. However the noise from the armature when starting is very loud and high pitched, with harmonics as you increase the throttle.
I tried reming out the last two channels as Steve suggested with the original code and I still experienced problems... but this new code works.
Malc,
it's little bit more than rem ADCIN line. i'll place all the changes i made in RED
Now for the noise, to me, as i'm not a motor pro, there's something normal in that. Your motor have a comfort zone in which he can operate. So if you're under that (let's call it threshold, lower possible voltage or else), for sure he will yell. It has to fight the inertia.. (OK OK probably not the right term... but it's how i understandCode:@ __CONFIG _HS_OSC & _WDT_ON & _PWRTE_ON & _MCLRE_OFF ANSEL = %00010111 ; - dt suggested value DEFINE OSC 20 CMCON=7 TRISA=%11111111 'set PORTA as all input TRISC=%00000001 'set PORTC as all output apart from RC0 DEFINE ADC_BITS 8 ' ADCIN resolution (Bits) DEFINE ADC_CLOCK 2 ' ADC clock source (Fosc/32) DEFINE ADC_SAMPLEUS 11 ' ADC sampling time (uSec) INCLUDE "DT_INTS-14.bas" ; Base Interrupt System INCLUDE "SPWM_INT.bas" ; Software PWM module DEFINE SPWM_FREQ 150 ; SPWM Frequency DEFINE SPWM_RES 255 ; SPWM Resolution DutyVar VAR byte[4] ASM SPWM_LIST macro ; Define Pin's to use for SPWM SPWM_PIN PORTC, 2, _DutyVar ; and the associated DutyCycle variables SPWM_PIN PORTC, 5, _DutyVar+1 ; Notice the underscore before variables SPWM_PIN PORTC, 4, _DutyVar+2 SPWM_PIN PORTC, 3, _DutyVar+3 endm SPWM_INIT SPWM_LIST ; Initialize the Pins ENDASM ASM INT_LIST macro ; IntSource, Label, Type, ResetFlag? INT_Handler TMR1_INT, SPWMhandler, ASM, yes endm INT_CREATE ; Creates the interrupt processor ENDASM @ INT_ENABLE TMR1_INT ; enable Timer 1 interrupts ;_____________________________________________________________________________ Main: ADCIN 0, DUTYVAR[0] ADCIN 1, DUTYVAR[1] ADCIN 2, DUTYVAR[2] ADCIN 4, DUTYVAR[3] GOTO Main)
Now, is this louder using PWM or not? this is why i asked for a variable supply before.
If it's better, we could still redesign the whole thing... same thing if you find a PWM frequency which reduce the noise.
Time for few tests on your side... even if you use few battery in serie![]()
Last edited by mister_e; - 17th February 2007 at 20:56.
Steve
It's not a bug, it's a random feature.
There's no problem, only learning opportunities.
Guys,
Firstly may I say that I admire both DT and Steve's skills in programming, and want to thank you both for staying with this. - I'm feeling way out of my depth here, and all I can do is test the code you offer, and report back.
Ok power supply:
240v primary - 12-0-12 secondry 500mA transformer. Rectified using 4 x 1N4004 diodes, regulated via 7812, 7912 1A regulators, with 1000uf capacitors to give smoothed +12 and -12v supply. Then a 7805 is used off the +12v to give +5 line. 0v taken from the centre tap. Actual voltages measured are +4.94v, +11.84 and -11.86.
+5v used for the PIC, +12v used for the motor supply - 0v commoned to both
Code.
I compiled Darrels code, and no matter what I tried I couldn't replicate the latching or drop out (ie the loco would just stop and not respond) when advancing and retarding the 10K lin pot in quick succession. However even with a 4 Mhz xtal the whine from the motor was loud
Compiling Steves code I got the low growl rather than a whine, but it was a lot less noticable than DT's original code. But advancing and retarding the pot as before still caused the lock up / drop outs.
Voltage measurements:
When advancing and retarding the pot quickly between min and max the voltage drop on the +5v line to the pic was less than 0.03v (4.94 - 4.93 was read), so its not enough to cause the PIC to stop running. The drop on the +12v line was a little more, but not drastic, with the lowest reading being 10.56, so the peak drop of around 1.4v.
To varify that it is the PIC that is locking up and not the output stage, I placed an LED on the output of the PIC, and this would stay illuminated when a lock up occured, even when the loco was removed. I also removed the connection between the PIC and the base of the NPN tranny to see if the LED would go out and it had no affect, so it would appear that the driver side isn't causing the issue.
Hope this feedback helps.
Last edited by malc-c; - 17th February 2007 at 21:45.
I feel so embarrased... but I think the problem of the drop outs etc is down to the powersupply.
To rule the PSU out I've just used the previously described PSU to power the 12v driver circuit, but used a 5v regulated switch mode wall PSU for the PIC. This was running at 5.12v. I had to common up the ground lines to get the loco to move, which also caused a bit of pulsing in the armature even with the pot at zero, but I couldn't get the lock up or drop out no matter what I tried.
So a re-think on the design of the PSU is in order.
Bookmarks