News:

;) This forum is the property of Proton software developers

Main Menu

How to Handle a PWM Pulse Train Into a Pic?

Started by Craig, Feb 22, 2026, 02:39 PM

Previous topic - Next topic

Craig

My Daughters Treadmill sends a PWM signal from a Pic16F877 into a Pic12C508A, The Pic12C508A has Died so I have put the signal from the Pic16F877 into a new Pic16F886 running at 20Mhz Xtal, this seems to give me the best results using the COUNTER Command in Positron. If I look at the signal on a Logic Analyzer (Set For - PWM and Timing) when it starts it gives 5 Pulses {Rising Edge to Rising Edge} then a 3.2 Second delay with 3 Pulses then a 1.6 Second delay with 3 Pulses this is for a BASIC Start at the slowest speed. If I start using the WALK Speed it gives 5 Pulses then a 3.2 Second delay with 9 Pulses then a 2.6 Second delay with 9 Pulses. This changes as the Speed Selection changes from Walk to Jog to Run and So on but, the Start Command Always remains at 5 Pulses to show a Start Treadmill PWM.pdf .

The first problem I am having is that the sequence of numbers on the COUNTER Command in Positron Changes If I do a basic start and look at the Data on a Serial Terminal program. The first time I do a start it will give say 1110110000... the next time I do the same start it will give 1010110100.. etc and so on for the First 5 Pulses and does the same with the other Pulse strings, If I look on my Logic Analyzer at the same time {The Logic Analyzer always looks the same and gives the Pulse train correctly each time}. I have gone from a 18F27Q10 device running at 64 MHz And CDIV = 1:1 (Too Fast) then to trying it at 4Mhz And CDIV = 4:1 which is (too slow) then I decided to use the 16F886 @ 20Mhz which seems to be fairly close but, still seems to be out?

My second question is how ho I handle this PWM Pulse Train Sequence coming into my PIC? Should I push it through a Op Amp and then Into the ADC on the Pic to see the desired speed that I need to Drive the motor at or should I try and decipher the pulse train to see the desired speed that I need to Drive the motor at ?

The Problem with the Speeds as they get higher like JOG and RUN they are Pulsing with Very Similar PWM Pulse trains in other words they are very similar {The PWM Train and Delays between the Pulse Trains}

Any help is very much appreciated!

Craig   


     

Stephen Moss

Looking the PDF you provided unless the changes are too small to see it looks it is the number of pulses rather then the width of the pulses that changes, more pulses = more speed. It also appears that there is a start period that consists of 5 pulses then a fairly consistent 3.2 second gap, after that the size of the "dead time" gap between groups of pulses appears to relatively constant but decreases proportionally as the number of pulses increases.

My guess would be that the reason for that is that the groups of pulses are part of a frame that is a fixed time period, I think that if you were to measure the time between the first falling edge of one group of pulses to the first falling edge of the next group you would find that the time is fairly consistent between groups (frame length). Therefore the more pulses you have in each frame as the speed increases the less dead time there is between groups of pulses.

If that is the case, then instead of counting the pulses you could try counting the length of the dead time between groups of pulses, although I am not sure how you would synchronise that. Alternatively you could try using a resistor and capacitor to smooth it to a DC voltage and read it with the ADC, more pulses = lower voltage.

However, I think the reason you may be getting different values from the Counter command are...
  • The time length of the command does exceeds that of the frame length and
  • When the Counter command is being executed is not being synchronised to the start of each frame.

Thus between then you could be missing some pulses at the beginning of one frame and catching some pulses from the beginning of the next frame. You could try to better synchronise it by sending the signal to two pins, one to count and the other has IOC.
Use the pin with IOC to find the start of each frame, disable the IOC (if not running the Counter command in your ISR), initiate the Counter command to get a pulse count for the current frame, then (if applicable) re-enable the IOC pin to find the next frame.