Recommendations - Model Train Controller - Page 3


Closed Thread
Page 3 of 3 FirstFirst 123
Results 81 to 102 of 102
  1. #81
    malc-c's Avatar
    malc-c Guest


    Did you find this post helpful? Yes | No

    Default Seems I'm the only one posting :)

    Ok I think I now understand the settings for ANSEL. Reading the datasheet again
    ANSEL — ANALOG SELECT REGISTER (ADRESS: 91h) (PIC16F676 ONLY)

    ANS7 ANS6 ANS5 ANS4 ANS3 ANS2 ANS1 ANS0
    bit 7 bit 0
    bit 7-0: ANS<7:0>: Analog Select between analog or digital function on pins AN<7:0>, respectively.
    1 = Analog input. Pin is assigned as analog input.(1)
    0 = Digital I/O. Pin is assigned to port or special function.
    So if I wanted all analogue I set ANSEL to 11111111 - all digital 00000000

    Ergo to set AN0, AN1, AN2 and AN4 Ansel should = 00010111, which is exactly what Darrel suggested. However when compiled with this setting the 4th output still runs at full speed with no control.

    Could it be that the issue is with the declaration of the array - as it has [3] and I would assume that there are 4 channels so maybe this should be [4] ??

    Quote Originally Posted by malc-c View Post

    Could it be that the issue is with the declaration of the array - as it has [3] and I would assume that there are 4 channels so maybe this should be [4] ??
    Looked like that was teh cause - I now have 4 working channels... just need to resolve the issue of the PIC locking on at full throttle and I'm done !
    Last edited by malc-c; - 16th February 2007 at 20:47.

  2. #82
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Boy. Try to get some sleep, and people start talking to themselves.

    Looks like the guy you were talking to, helped figure a couple things out though.

    Good catch on the array size. Didn't see that.

    Heard the video. That's just nasty sounding.
    Is it any better yet after the changes?

    I know you were told to change SPWM_RES to 255, but it really should be 256 for 8-bit resolution. Maybe the cause of the "PIC locking on at full throttle". I'll play with it here too and see.
    <br>
    DT

  3. #83
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    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

  4. #84
    malc-c's Avatar
    malc-c Guest


    Did you find this post helpful? Yes | No

    Default

    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 ??

  5. #85
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    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

  6. #86
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    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.

  7. #87
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    Well well well... running 3 different Motor type from 500mA to 10A @12Vdc.. and a pretty messed up breadboard + Jumper it 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.

  8. #88
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    Everything just fine using...
    Code:
    @ __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
    GO GO GO FIGURE IT
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  9. #89
    malc-c's Avatar
    malc-c Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Darrel Taylor View Post

    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
    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.

  10. #90
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    Malc,
    it's little bit more than rem ADCIN line. i'll place all the changes i made in RED

    Code:
    @	__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 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 understand )

    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.

  11. #91
    malc-c's Avatar
    malc-c Guest


    Did you find this post helpful? Yes | No

    Default

    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.

  12. #92
    malc-c's Avatar
    malc-c Guest


    Did you find this post helpful? Yes | No

    Default I think I solved it

    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.

  13. #93
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Grreat!

    One by one, knocking out the problems.

    As for sticking with it, I'll stick with anyone that put's in the effort. Like you.
    Thanks for making it fun.

    Steve,
    Do you hear the whining etc in your motors?
    Just wondering if it's the type of motor that makes a difference.
    <br>
    DT

  14. #94
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    Yeah that's what i thought too, hence why i buy few different model.

    Well, yes i hear some little noise which is more or less louder depending of the model... but there's always some noise when you play around the minimum low-voltage threshold.

    I tried higher PWM frequencies and it may cure some part of the problem on some voltage range and on some motor model. but it's certainly not perfect on ALL motor i have here.

    To me, in this specific case, a better choice could be to use some kind of linear regulation. Something around the following.
    <img src="http://www.picbasic.co.uk/forum/attachment.php?attachmentid=1396&stc=1&d=117175510 5">

    it have some good point and some bad ones. But do you really a 0-100% regulation? mmm

    Malc, don't worry... it's an interesting and funny thread.

    An idea... we could skip the PWM and use some I2C DAC...
    Attached Images Attached Images  
    Last edited by mister_e; - 17th February 2007 at 23:56.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  15. #95
    malc-c's Avatar
    malc-c Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Darrel Taylor View Post
    Grreat!

    One by one, knocking out the problems.

    As for sticking with it, I'll stick with anyone that put's in the effort. Like you.
    Thanks for making it fun.
    Thanks Darrel,

    I'm always willing to put effort in to these projects, and I've learnt a lot over the course of this thread. I just feel a tad embarrased that I didn't try two seperate power supplies earlier and kept pointing the finger at the code...

    Mind you, hopefully the use of your PWM routines in this application may of hi-lighted some areas such as the armature noise, that you may want to look at for future verions.

    As for the motors, I have four 2mm scale locos, two are circa 18 years old with an open frame 5 pole motors, the others are less than a year old and both have small can motors... guess which ones produce the better running... yup the older ones !!

    As a side note, when I tried your last bit of code I was using a 4mhz Xtal, I then tried it with a 20mhz and it was quite painful, for my ears and the motor !!

    Anyway, thanks once again to you and Steve for all your help. To everyone else who's been reading this, sorry if it bored you at times

  16. #96
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,614


    Did you find this post helpful? Yes | No

    Wink a small last trail ???

    Quote Originally Posted by mister_e View Post
    Yeah that's what i thought too, hence why i buy few different model.

    Well, yes i hear some little noise which is more or less louder depending of the model... but there's always some noise when you play around the minimum low-voltage threshold.

    I tried higher PWM frequencies and it may cure some part of the problem on some voltage range and on some motor model. but it's certainly not perfect on ALL motor i have here.

    To me, in this specific case, a better choice could be to use some kind of linear regulation. Something around the following.
    <img src="http://www.picbasic.co.uk/forum/attachment.php?attachmentid=1396&stc=1&d=117175510 5">

    it have some good point and some bad ones. But do you really a 0-100% regulation? mmm

    Malc, don't worry... it's an interesting and funny thread.

    An idea... we could skip the PWM and use some I2C DAC...
    Hi, Steve

    Your design is to try with a low input RC constant in order to produce some kind of trapezoidal wave ... instead of the beautiful square wave.

    the problem lays in the slew-rate ... remember lentz's law ... the motor windings oppose an "electrical inertia" proportionnal to the slew-rate ...

    that will create some dissipation in the ballast ... but make less noise and heat.

    may be some "Mid freq" rectified sinus, used in burst mode could also do the job with minimal issues ( seen on the motor side ... LOL !!! )



    Alain
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  17. #97
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    My motor theory is far far away... and never felt the need to understand it in the past

    interesting... thanks.

    Few interesting points in the followings ...
    http://homepages.which.net/~paul.hil...llersBody.html ok ok it's talking about a starter but anyways..

    http://ww1.microchip.com/downloads/e...tes/00770b.pdf
    Last edited by mister_e; - 18th February 2007 at 17:44.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  18. #98
    malc-c's Avatar
    malc-c Guest


    Did you find this post helpful? Yes | No

    Default Update

    Guys,

    Just thought you might want to see the prototype controler (only two channels)



    The 10K pot and reversing switch is connected via the 6-pin header infront of the power transistors. I've also left room for a small heatsink, but in tests so far these don't get hot enough to warrant one !

    The only problem is I'm still waiting on some 16F676's as I fried the only one i had in the breadboard... (got distracted by a phone call and connected the +12v to the PIC rather than the +5v !!! - it was glowing and had to cut short the call to pull the plug !!) - Tested the output stage and it works fine so can't see any reason for it not to work when the PIC's arrive.

  19. #99
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    The only problem is I'm still waiting on some 16F676's as I fried the only one i had in the breadboard... (got distracted by a phone call and connected the +12v to the PIC rather than the +5v !!

    Looks good! Keep us posted!
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  20. #100
    Join Date
    Jan 2007
    Posts
    24


    Did you find this post helpful? Yes | No

    Red face

    Why not talk to a PIC in the module using I2C?? After all, the track is two wires.

    You could modulate this on top of a standing DC voltage then control a motor using hard coded addresses on the loco module PCB and an H bridge driven by the PWM from the PIC.

    Just a thought. I tried it and it worked fine. Be careful of the need to filter the I2C signals HEAVILY but not so much that you lose them.

  21. #101
    malc-c's Avatar
    malc-c Guest


    Did you find this post helpful? Yes | No

    Default

    Interesting concept, sort of a cross between modern DCC and traditional control. However, its not practical in this instance as the contoller is for a club layout and would mean that every member would have to have the same system installed on their own layaouts at home. Also with the scale, fiting modules to small loco's is a pain in the ***

  22. #102
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,614


    Did you find this post helpful? Yes | No

    Wink Food for Brain ...

    Hi Malc,

    I Had my father home this week-end ...

    We talked about supplies and it seems the today's "must" is to use switching supply during speed transitions ( or accelerations ) and DC during constant speed running ( of course for noize !!! ) ...

    That meets one of Sougata's threads about signal generation with a Pic ... and opens interesting reflexion and work about what output stage to use !!!

    new challenge for Darrel !!! ( He Looooooves !!!! )

    Alain
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

Similar Threads

  1. Microstepper controller
    By aratti in forum Schematics
    Replies: 14
    Last Post: - 3rd January 2015, 16:52
  2. problem with the GSM controller
    By Dariolo in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 30th May 2009, 20:33
  3. Replies: 2
    Last Post: - 14th July 2008, 22:11
  4. Model Train controller - revisited
    By malc-c in forum mel PIC BASIC Pro
    Replies: 32
    Last Post: - 8th May 2007, 09:40
  5. Dedicated LCD Controller question
    By chuckles in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 27th February 2006, 14:44

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts