Recommendations - Model Train Controller - Page 2


Closed Thread
Page 2 of 3 FirstFirst 123 LastLast
Results 41 to 80 of 102
  1. #41
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    skimask,

    Aw rat's, gave you a chance, but you missed it.

    You were supposed to say "BAM".

    Bit Angle Modulation.

    For devices that rely on the "Average Current" resulting from a PWM signal, the PWM signal doesn't need to be exactly symmetrical waveforms based on consecutive ON and OFF cycles.

    With BAM, you only need 8 interrupts per cycle. Each time period is "weighted" by it's bit position in the DutyCycle variable.

    This way, you could turn every pin on a PIC18F8720 (all 67 of them) into PWM (BAM) outputs (at pretty high frequencies).

    And of course, with DT_INTS, it's a piece of cake.
    <br>
    DT

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


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by malc-c View Post
    I assume that using a 100 Hz frequency for the PWM would be ideal... what PIC did you use, and is having an internal clock an issue (I'm using a 12F675 for experimential use)
    Malcolm,

    I was using a 16F877A, I guess it was really comparing Apples to Oranges.

    I figured I better check with a 12F675, but didn't have one handy so I used a 12F683. It was close enough to figure out what was wrong.

    This get's everyone, so I should have seen it right away, but nope.

    CMCON = 7 ; disable the comparators
    ANSEL = 1 ; AN0 is analog, rest digital

    also, You have a PWM output on GPIO.0 ... The same pin as the POT is connected to on AN0. That'll cause problems with the A/D reading.

    Hope you're still interested?

    EDIT: 100hz is no problem. But you'll need a faster crystal/resonator
    INTRC won't cut it.

    HTH,
    DT

  3. #43
    malc-c's Avatar
    malc-c Guest


    Did you find this post helpful? Yes | No

    Default

    Darrel,

    Sorry I missed that... I've remmed out the PWM line fro GPIO.0 and have got a reasonable result, especially for slow speed - The crawling speed of an 18 year old tank loco is really amaizing !!

    Here's the code

    Code:
    DEFINE OSC 20
    CLEAR
    
    DEFINE ADC_BITS 8	' Set number of bits in result
    DEFINE ADC_CLOCK 3	' Set clock source (rc = 3)
    DEFINE ADC_SAMPLEUS 50	' Set sampling time in microseconds
    
    INCLUDE "DT_INTS-14.bas"            ; Base Interrupt System
    INCLUDE "SPWM_INT.bas"              ; Software PWM module
    
    DEFINE SPWM_FREQ  100                ; SPWM Frequency
    DEFINE SPWM_RES   256               ; SPWM Resolution
    
    D var byte
    
    DutyVars   VAR BYTE[3]              ; DutyCycle Variables
      ;DutyVar1 VAR DutyVars[0]          ; group them in an array for easy access
      ;DutyVar2 VAR DutyVars[1]          ; with FOR loops etc.
      DutyVar3 VAR DutyVars[2]
    
    ASM
    SPWM_LIST  macro                    ; Define Pin's to use for SPWM
        ;SPWM_PIN  GPIO, 0, _DutyVar1  ; and the associated DutyCycle variables
        ; SPWM_PIN  GPIO, 1, _DutyVar2  ; Notice the underscore before variables
         SPWM_PIN  GPIO, 2, _DutyVar3
      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, D 
        DutyVar3 = D   
    GOTO Main
    Using a close loop fedback output stage and a 12v regulated supply for the track as per the diagram attached, I get a nice smooth slow speed control. This is using the 12F675 with its internal osc.

    The loco does growl a bit when at really slow speed... and at maximum speed its fine for a goods train, but not an express. I susspect that using a higher track supply voltage will resolve the speed issue (my DVM reads 6.5v across the track at full speed), but wondered if there was anything I could do to reduce the growling at slow speed.

    Please bear in mind that I'm still somewhat new to PICs and programming.. so If I've still overlooked something in the settings then please advise what I did wrong and how to correct it.
    Attached Images Attached Images  

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


    Did you find this post helpful? Yes | No

    Default

    Hmm, I don't see the CMCON and ANSEL in your program.

    There's a R-M-W (Read-Modify-Write) problem when OUTPUTting to a pin set to Analog. It adds a high frequency component to the PWM signal.

    I don't know if that's what is causing the growling or not.

    6.5V at full speed? That doesn't sound right. The current is getting limited somewhere. Maybe if you increased the value of R4 ????
    <br>
    DT

  5. #45
    malc-c's Avatar
    malc-c Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Darrel Taylor View Post
    Hmm, I don't see the CMCON and ANSEL in your program.

    There's a R-M-W (Read-Modify-Write) problem when OUTPUTting to a pin set to Analog. It adds a high frequency component to the PWM signal.
    Would the following be correct
    Code:
    TRISIO.2 = 0   'Set GPIO.2 to output.
    ANSEL.2 = 0    'Set GPIO.2 to digital		
    GPIO.0 = 1      'gpio.0 set to input
    VRCON = 0        ' Voltage reference disabled
    OPTION_REG.7 =    0
    Quote Originally Posted by Darrel Taylor View Post
    6.5V at full speed? That doesn't sound right. The current is getting limited somewhere. Maybe if you increased the value of R4 ????
    I'll try that and see what happens, thanks for the suggestion

  6. #46
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,615


    Did you find this post helpful? Yes | No

    Wink No surprise !!!

    Hi, Malc

    I do not know where you found R4 and D1 ... but your problems come from there.

    No real use for them ... so, back to their drawer will be the best.

    ... or use another Pic pin if you want to do something with the freewheel emf !!!

    a simpler output stage would be welcome ( your NPN Emitter to ground and a series 1 k in the base connection i.e. )

    Alain
    Last edited by Acetronics2; - 15th February 2007 at 13:27.
    ************************************************** ***********************
    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 " !!!
    *****************************************

  7. #47
    malc-c's Avatar
    malc-c Guest


    Did you find this post helpful? Yes | No

    Default

    Alain,

    Thanks for the suggestion... the output circuit was taken from a book and is actually a cloose-loop feedback controller... I just fed the output from the PIC directly to the base of the NPN tranny... but I'll try your suggestions and see if it improves the max speed settings. However in its current state it makes for an excellent branch line controller where slower trains would run...

    To give you some idea of the excellent slow speed the PWM gives have a look at this video I've uploaded http://www.micro-heli.co.uk/controller.avi (9mb DIVx format)

  8. #48
    malc-c's Avatar
    malc-c Guest


    Did you find this post helpful? Yes | No

    Default

    Omitting the feedback section (R4 and 1N4148), and adding a 1K base resistior I now get a good range of speed and excellent slow speed crawling. Just need to resolve the growling in the armature

  9. #49
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,615


    Did you find this post helpful? Yes | No

    Talking Growling

    Hi, Malc,

    The only way is to increase the PWM frequency ( 500 or 1000 Hz might be enough ).
    also Think to the minimum PWM ratio zone to skip ( ~ 10 % )

    you'll find a problem here : some motors do not like high frequencies ( > 3000 Hz ) due to their high inductance ... and might overheat.

    Do you think I could make a test with my Big Boy, die cast "crocodile" or JEP 231 ... or some oldies ???

    Hé,hé ... my father gave its life and brain to our national railway company ...and still builds custom models ( 84 years ...the papy !!! )

    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 " !!!
    *****************************************

  10. #50
    malc-c's Avatar
    malc-c Guest


    Did you find this post helpful? Yes | No

    Default

    Well I've been playing with the values for SPWM frequency and resolution and found the highest setting for the 12F675 using internal osc was around
    Code:
    DEFINE SPWM_FREQ  200                ; SPWM Frequency
    DEFINE SPWM_RES   256               ; SPWM Resolution
    Its not possible to up the resolution without using an external OSC. However I intend to use a different PIC and may opt to use it at is max xtal rating, especially if I use the one PIC to provide all 4 channels. Maybe the higher resolution will reduce the grumbling in the armature... mind you if this was on old 0-6-0 shunter it would look and sound just right

    One thing I did notice is that when using the PWM version the power tranny runs cold, where with the close loop version it warmed up (slightly)

    Anyway, I'm having fun learning

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


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Darrel Taylor View Post
    There's a R-M-W (Read-Modify-Write) problem when OUTPUTting to a pin set to Analog. It adds a high frequency component to the PWM signal.
    That's interesting... whilst I was reading up on the use of your code I could hear this high pitched (estimated 4 - 8 Khz) faint sound like you often hear eminating from a TV... placed my ear near the loco (which is standing still on the track) and its singing away !!

    I presume that this is due to the fact that GPIO.2 is still set to analogue and not digital ??

    What config settings should I use for CMCON and ANSEL to resolve this ?

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


    Did you find this post helpful? Yes | No

    Default

    in theory the right setting have to be
    Code:
    ANSEL=%00110001
    CMCON=7
    GPIO=0
    TRISIO=1
    and later i just change the main loop to...
    Code:
    Main:                               
            ADCIN 0, DUTYVAR3
            GOTO Main
    AND NOW it's working pretty good and smooth... well here...

    For once i found a use of the Left-Justified results... Never thought ADCIN handled it

    Make sure your Pot impedance meet the maximum recommended on.. 2.5 k if my memory serves me well. 10K here (EasyPic 4) still work fine..

    Also, as the ADC results is a 8 bit result, you should change the SPWM_RES to 255.
    Last edited by mister_e; - 15th February 2007 at 18:28.
    Steve

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

  13. #53
    malc-c's Avatar
    malc-c Guest


    Did you find this post helpful? Yes | No

    Default

    Steve, Thanks for your input. I made the changes you suggested and the performance is still great and the growling sound produced by the PWM in the armature appears less noticable. The high pitched sound is still noticable, but nothing appears hot

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


    Did you find this post helpful? Yes | No

    Default

    Unfortunately i don't have anything like that here to test, but Maybe the PWM have to be smooth first...

    what happen if you place a big capacitor (470 & up) in parallel with the motors?

    What happen if you place a capacitor (few uF) on the mosfet gate pin? (transistor base)

    What happen if you use a variable voltage regulator (or PSU)? instead of PWM?
    Steve

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

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


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by mister_e View Post
    Unfortunately i don't have anything like that here to test, but Maybe the PWM have to be smooth first...

    what happen if you place a big capacitor (470 & up) in parallel with the motors?
    Tried both high (1000uf) and low (100uf) - the loco won't move

    Quote Originally Posted by mister_e View Post
    What happen if you place a capacitor (few uF) on the mosfet gate pin? (transistor base)
    Tried, 1uf to 10uf. with a 1uf the growling was less noticable, but the slow speed control became less. Increasing this to 10uf and the loco had almost no ability to crawl.

    Quote Originally Posted by mister_e View Post
    What happen if you use a variable voltage regulator (or PSU)? instead of PWM?
    Don't know as I don't have a varible regulator to hand.. what would be the advantage of using one over using a pot accross the supply with the wiper connected to the base of the NPN tranny ?

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


    Did you find this post helpful? Yes | No

    Default

    what's your actual schematic?

    how much current your motor need?
    Steve

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

  17. #57
    malc-c's Avatar
    malc-c Guest


    Did you find this post helpful? Yes | No

    Default

    Typically these loco's draw around 300mA - 600mA ( a quick test showed mine drawing 380mA with no coaches at full throttle )

    The schematic as it stands is attchaed
    Attached Images Attached Images  

  18. #58
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Saw the video.

    I've seen snails move faster than that, when it's raining.

    Cool.

    Hope someone can figure out the Growl.
    DT

  19. #59
    malc-c's Avatar
    malc-c Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Darrel Taylor View Post
    Saw the video.

    I've seen snails move faster than that, when it's raining.

    Cool.

    Hope someone can figure out the Growl.
    LOL - thanks !

    I'm not too bothered about the noise the PWM makes, but as this will be used on a club lauout, other members might complain...

  20. #60
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,615


    Did you find this post helpful? Yes | No

    Wink Simplify, simplify !!!

    Quote Originally Posted by malc-c View Post
    Typically these loco's draw around 300mA - 600mA ( a quick test showed mine drawing 380mA with no coaches at full throttle )

    The schematic as it stands is attchaed
    Hi, Malc,

    R3 is no use at all here ... short it !!!

    ... but a 1N 540x cathode at the + 12v, anode on the V+ output could be rather useful ...

    Alain

    PS ... for Growling, may be you could try to " unsharpen" the PWM to somewhat with increased rise and fall time ... by inserting a filtering coil in series in the output line ( a LITTLE smoothing capacitor too ??? )
    Last edited by Acetronics2; - 16th February 2007 at 09:56.
    ************************************************** ***********************
    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 " !!!
    *****************************************

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


    Did you find this post helpful? Yes | No

    Default

    Hi,

    Don't have that Diode suggested, have plenty of 1N4148's or 1N4001 to hand, would they do ?

  22. #62
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,615


    Did you find this post helpful? Yes | No

    Wink

    The 4001 will be a bit too weak ... for serious use.

    try to find a 3A rated model ... or use a PNP Darlington with diode Built in !!! like BD678/680

    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 " !!!
    *****************************************

  23. #63
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,615


    Did you find this post helpful? Yes | No

    Default

    Hi, Malc

    Some more food for your brain :

    http://www.manhattancontrols.com/for...wtopic.php?t=4

    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 " !!!
    *****************************************

  24. #64
    malc-c's Avatar
    malc-c Guest


    Did you find this post helpful? Yes | No

    Default More problems :(

    OK I thought, lets move this on and use a PIC capable of providing all 4 seperate PWM outputs. So after consultation via a few PMs with Steve and Darrel I've opted for a 16F676.

    I've used a 20Mhz xtal, with 22pf caps between pins 2 and 3, wiper from 10K pot goes to pin 13 and PWM output on pin 8.

    I've modified the code used for the 12F675, and compiled - no errors or warning, and loaded it into the PIC.
    Code:
    @ __CONFIG _HS_OSC & _WDT_ON & _PWRTE_ON & _MCLRE_OFF 
    
    ANSEL=%00110001
    CMCON=7
    TRISA=%11111111        'set PORTA as all input 
    TRISC=%00000001        'set PORTC as all output apart from RC0
    
    
    DEFINE OSC 20
    CLEAR
    
    DEFINE ADC_BITS 8	' Set number of bits in result
    DEFINE ADC_CLOCK 3	' Set clock source (rc = 3)
    DEFINE ADC_SAMPLEUS 50	' Set sampling time in microseconds
    
    INCLUDE "DT_INTS-14.bas"            ; Base Interrupt System
    INCLUDE "SPWM_INT.bas"              ; Software PWM module
    
    DEFINE SPWM_FREQ  100                ; SPWM Frequency
    DEFINE SPWM_RES   255               ; SPWM Resolution
    
    DutyVars   VAR BYTE[3]              ; DutyCycle Variables
      DutyVar1 VAR DutyVars[0]          ; group them in an array for easy access
      DutyVar2 VAR DutyVars[1]          ; with FOR loops etc.
      DutyVar3 VAR DutyVars[2]
      DutyVar4 VAR DutyVars[3]
    
    ASM
    SPWM_LIST  macro                    ; Define Pin's to use for SPWM
        SPWM_PIN  PORTC, 2, _DutyVar1   ; and the associated DutyCycle variables
        SPWM_PIN  PORTC, 3, _DutyVar2   ; Notice the underscore before variables
        SPWM_PIN  PORTC, 4, _DutyVar3
        SPWM_PIN  PORTC, 5, _DutyVar4
      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, DUTYVAR1
     ADCIN 1, DUTYVAR2
     ADCIN 2, DUTYVAR3
     ADCIN 3, DUTYVAR4
     GOTO Main
    I then tested the code / hardware and I don't get the same performance as I did with the 12F. There is no responce from the loco until the pot is at mid point, at this stage the armature sings with a high pitch noise. Advancing the pot increases the speed, but I don't get anywhere like the slow crawl speeds I got with the 12F. I can also assume that the armature is warming as it smelt a little (carbon smell) after a short run.

    I think its probably down to my poor understanding of Ansel etc.. so an constructive comments would be welcome.

    Oh and I've not changed the driver stage yet as Alain suggested.

    EDIT:: EDIT::
    Changed the Xtal for a 4Mhz and the frequency of the noise has dropped.. but its still there and not the low growl that was produced by the 12F.. so it it a timing issue ??
    Last edited by malc-c; - 16th February 2007 at 13:06.

  25. #65
    malc-c's Avatar
    malc-c Guest


    Did you find this post helpful? Yes | No

    Default

    I've also tried the other channels, and get the same performance and noise from each one. (I've also reduced the frequency down to 100 to make sure I get 4 channels) - and I'm using the int osc to compare it against the 12F

    I've noticed that the growling from the armature has a second resonating sound that I can only describe as the sound you get with a multi-engine prop plane when the engine is slightly out of sync. I can only assume this is due to the PIC having to work hard outputing to 4 channels rather than the 1 on the 12F.

    If all else fails, I'll use a 12F675's to drive each of the 4 controllers... overkill I know, but the performance I was getting with the 12F was just what I was after.

    I'm hoping the issue with the 16F676 is due to a conflict of configuring the ports to the correct analogue / a2d / digital combination, and with your help, will work as good as the 12F !

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


    Did you find this post helpful? Yes | No

    Default

    There's something bad in the schematic indeed. R3 have it's use... but not at the good place. Should be in serie with the transistor base. If you short it, you'll burn the transistor...

    I'm curious.. i'll try to find some 12V motor (1A or more) 'round here today, and test the whole thing. Sure it's possible.

    I'll dig in the transistor datasheet... sure there's something bad in their HFe mathe here....

    Anyways, i'll be back!
    Steve

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

  27. #67
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,615


    Did you find this post helpful? Yes | No

    Lightbulb

    Quote Originally Posted by mister_e View Post
    There's something bad in the schematic indeed. R3 have it's use... but not at the good place. Should be in serie with the transistor base. If you short it, you'll burn the transistor...

    Anyways, i'll be back!
    Hi, Steve

    Did you notice a 1K resistor had magically appeared in series with the trans. base ??? ...

    Strong coffee needed ... Malc is a one not so easy to follow !!!

    The output schematic can be enough for this time ... let's see one problem at a time !!!

    Inserting some PAUSE ( 100-200 ms ) between inputs pollings might do something interesting here ... let's try that first

    Alain
    Last edited by Acetronics2; - 16th February 2007 at 13:50.
    ************************************************** ***********************
    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 " !!!
    *****************************************

  28. #68
    malc-c's Avatar
    malc-c Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Acetronics View Post
    Hi, Steve

    Did you notice a 1K resistor had magically appeared in series with the trans. base ??? ...
    Alain, the 1K base resistor was added way back after you suggested in post #46 that I removed the R4/D1 combo and and a series 1 k in the base connection

    The nearest shematic I have is as detailed in post #57 - apart from the fact that I'm using a 16F676 rather than the 12F675 - the output stage is the same, I've not changed anything since, and wouldn't edit posts to suit...
    Last edited by malc-c; - 16th February 2007 at 14:19.

  29. #69
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Malcolm,

    I've got it running here on a 16F676. But...

    You have a POT input on AN3, which is also the OSC2 for the crystal.

    If I comment out the ADCIN 3, DUTYVAR4 then it seems to run fine.
    But with that statement in there it goes wacko.
    <br>
    Added: ANSEL needs to be changed too, but I'll wait to see where you move the AN3 to.
    DT

  30. #70
    malc-c's Avatar
    malc-c Guest


    Did you find this post helpful? Yes | No

    Default

    Whoops !

    Thanks for spotting my deliberate mistake !!!!

    Thanks for the PM, I've created another copy of the code and downloaded the DT_int 18 file, the following compiles OK but I have to use a different programmer for pics with 18 pins or more and I've never had much luck with 18F2550's and this programmer as Steve will vouch !!

    I'll try some changes for the 16F676 and see how I get on.. Thanks to everyone again for your assistance...

  31. #71
    malc-c's Avatar
    malc-c Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Darrel Taylor View Post
    Malcolm,

    ANSEL needs to be changed too, but I'll wait to see where you move the AN3 to.
    I actually marked it on the datasheet pinout to use AN4 (pin 10) on the 16F676 - I should pay more attention to what I plan !!

  32. #72
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,615


    Did you find this post helpful? Yes | No

    Wink

    Quote Originally Posted by malc-c View Post
    Alain, the 1K base resistor was added way back after you suggested in post #46 that I removed the R4/D1 combo and and a series 1 k in the base connection

    The nearest shematic I have is as detailed in post #57 - apart from the fact that I'm using a 16F676 rather than the 12F675 - the output stage is the same, I've not changed anything since, and wouldn't edit posts to suit...
    We're in sync Malc ... just R3 NOT to be shorted !!! ... but placed in series with the NPN COLLECTOR ...

    MEA Culpa ...

    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 " !!!
    *****************************************

  33. #73
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    AN4, ok.

    Make ANSEL = %00010111
    <br>
    DT

  34. #74
    malc-c's Avatar
    malc-c Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Darrel Taylor View Post
    AN4, ok.

    Make ANSEL = %00010111
    Darrel, can you confirm that I have understood the variables for SPWM_PIN right, and that I'm using the correct channels for a/d, as I only had 2 out of 4 outputs working right, and now made changes I get that high frequency noise from the armature (where as before it was a low growl, even with a 20 Mhz xtal)

    I want to use the following pins on the 16F676 for inputs from 10K pots, and their corresponding PWM outputs

    Pot 1 - Pin 13 - AN0 - controlling output on pin 8 - RC2
    pot 2 - Pin 12 - AN1 - controlling output on pin 5 - RC5
    pot 3 - Pin 11 - AN2 - controlling output on pin 6 - RC4
    pot 4 - Pin 10 - AN4 - controlling output on pin 7 - RC3

    so I've set up SPWM_PIN as
    Code:
    SPWM_LIST  macro                    ; Define Pin's to use for SPWM
        SPWM_PIN  PORTC, 2, _DutyVar1   ; and the associated DutyCycle variables
        SPWM_PIN  PORTC, 5, _DutyVar2   ; Notice the underscore before variables
        SPWM_PIN  PORTC, 4, _DutyVar3
        SPWM_PIN  PORTC, 3, _DutyVar4
    And have the main program as
    Code:
    Main:                               
     ADCIN 0, DUTYVAR1
     ADCIN 1, DUTYVAR2
     ADCIN 2, DUTYVAR3
     ADCIN 4, DUTYVAR4
     GOTO Main
    I'm assuming the value of ANSEL is incorrect as its ommitting that high frequency noise. Given the above info, which I hope is clear, what would be the correct value for ANSEL, or have I made another boo boo in assignig the pins ?

    By the way, prior to the change I had it running really well on CH1 - you thought that on a 12F @ 4mhz the loco was slow.... wait to you see the video for it running on a 16F @ 20 mhz !! - its just amazing !!

  35. #75
    malc-c's Avatar
    malc-c Guest


    Did you find this post helpful? Yes | No

    Default Slow PWM in action

    Darrel,

    Here is that video - http://www.micro-heli.co.uk/controller2.avi

    I've left the audio element in so you guys can hear the growling the loco makes, the downside is that this has made the file 24MB

  36. #76
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,615


    Did you find this post helpful? Yes | No

    Default

    No secret, Malc ...

    PWM freq too low.
    ( may be also a poor quality motor too ... but you can't choose which will be used.)

    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 " !!!
    *****************************************

  37. #77
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by malc-c View Post
    Tried both high (1000uf) and low (100uf) - the loco won't move
    Tried, 1uf to 10uf. with a 1uf the growling was less noticable, but the slow speed control became less. Increasing this to 10uf and the loco had almost no ability to crawl.
    4 - 8 kc whine? have you tried going even smaller? say .1 or .01 uf ? There is an outside chance you are not hearing the direct frequency in those motor coils but rather a beat frequency from the difference between 2 frequencies in which case you may be looking at bypassing RF.<br> I would bypass the motor from each power lead to the case too.
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

  38. #78
    malc-c's Avatar
    malc-c Guest


    Did you find this post helpful? Yes | No

    Default

    Thanks for the suggestion, a tad over my head, but I think I follow your drift.

    Darrel / Steve,
    I've noticed that if I advance the pot fully (thus taking the A/D input pin to supply) and then turn it back down the loco stays at full speed, and the only way to correct this is to disconecct and reconnect the supply. - any suggestions (could this be down to the wrong setting for ANSEL)

  39. #79
    malc-c's Avatar
    malc-c Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Acetronics View Post
    No secret, Malc ...

    PWM freq too low.
    Alain
    The max setting I can use seems to be 190 for freqency, 255 for resolution, with an OSC value of 20

  40. #80
    malc-c's Avatar
    malc-c Guest


    Did you find this post helpful? Yes | No

    Default I have a headacke !

    I've been trying to phathom out what I need to set ANSEL to or whats wrong with the code to get this to work 100%.

    Referring to my post #74, I have three PWM outputs, but when I connect pot 4 to pin 10 and the corresponding output (pin 7 RC3) the loco just shoots off at full speed with no control - Here's the code

    Code:
    @ __CONFIG  _HS_OSC & _WDT_ON & _PWRTE_ON & _MCLRE_OFF 
    
    
         ;ANSEL = %00010111    - dt suggested value
    ANSEL=%00110001     ; original 
    CMCON=7
    TRISA=%11111111        'set PORTA as all input 
    TRISC=%00000001        'set PORTC as all output apart from RC0
    
    
    DEFINE OSC 20
    CLEAR
    
    DEFINE ADC_BITS 8	' Set number of bits in result
    DEFINE ADC_CLOCK 3	' Set clock source (rc = 3)
    DEFINE ADC_SAMPLEUS 50	' Set sampling time in microseconds
    
    INCLUDE "DT_INTS-14.bas"            ; Base Interrupt System
    INCLUDE "SPWM_INT.bas"              ; Software PWM module
    
    DEFINE SPWM_FREQ  190                ; SPWM Frequency
    DEFINE SPWM_RES   255               ; SPWM Resolution
    
    DutyVars   VAR BYTE[3]              ; DutyCycle Variables
      DutyVar1 VAR DutyVars[0]          ; group them in an array for easy access
      DutyVar2 VAR DutyVars[1]          ; with FOR loops etc.
      DutyVar3 VAR DutyVars[2]
      DutyVar4 VAR DutyVars[3]
    
    ASM
    SPWM_LIST  macro                    ; Define Pin's to use for SPWM
        SPWM_PIN  PORTC, 2, _DutyVar1   ; and the associated DutyCycle variables
        SPWM_PIN  PORTC, 5, _DutyVar2   ; Notice the underscore before variables
        SPWM_PIN  PORTC, 4, _DutyVar3
        SPWM_PIN  PORTC, 3, _DutyVar4
      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, DUTYVAR1
     ADCIN 1, DUTYVAR2
     ADCIN 2, DUTYVAR3
     ADCIN 4, DUTYVAR4
     GOTO Main
    Here's hoping someone can point e in the right direction

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