News:

;) This forum is the property of Proton software developers

Main Menu

Procedure using PORT

Started by joesaliba, Jan 23, 2022, 01:37 PM

Previous topic - Next topic

joesaliba

Thank Les for that.

I had to use 4 Break to exit my meta macro but working fine now.

I am measuring 4 RC inputs and now I have a solution that if a signal is removed from the unit I am preparing it does not freeze the code.

Also, I am going to add a solution that if the user is going to only use three channels, this is automatically selected at switch on, by scanning the channels and omit the inputs that are not in use.

@david At this point it is not so much important for me to preserve the 14 channel 20ms frame rate. But yes, it would be interesting to be able to.

top204

#21
If the pins used for the input of the routine are known and fixed, you can still use a procedure, but the parameter will tell the code inside what code to run for a certain pin:

Proc TestProc(pPin As Byte), Word
    Dim wTimer1 As TMR1L.Word

    wTimer1 = 0   
    If pPin = Pin_C1 Then                ' Is the routine using PORTC.1
        Repeat: Until PORTC.1 = 0    
        Repeat: Until PORTC.1 = 1    
        T1CONbits_TMR1ON = 1        
        Repeat: Until PORTC.1 = 0 
        T1CONbits_TMR1ON = 0 
   
    ElseIf pPin = Pin_C2 Then            ' Is the routine using PORTC.2
        Repeat: Until PORTC.2 = 0    
        Repeat: Until PORTC.2 = 1    
        T1CONbits_TMR1ON = 1        
        Repeat: Until PORTC.2 = 0
        T1CONbits_TMR1ON = 0
    EndIf
   
    Result = wTimer1
EndProc

Then to call the procedure, use: TestProc(Pin_C1) or TestProc(Pin_C2), and the code inside will perform the routine using the PORTC.1 pin or the PORTC.2 pin. There will be an initial delay of a few 10s of ns as the comparisons choose the correct code block, but the block itself will run fast. It will take more flash memory, but that is the price to pay for faster code.

david

Hi Joe,
Originally I used the same logic and code that you had-

"I wait for the high pulse because if I enter this routine when the pulse is already high I can take a false reading, i.e., only measure half pulse."

I think it's redundant as it only applies to a single channel of the initial frame after plugging in and besides - I think you should use a simple filter for all intervals so that glitches can be ignored.

If pulse<1000 then pulse=1000
If pulse>2000then pulse=2000   (or whatever values you want to set)

Of course you also need to ensure the rx goes in to a known state if the craft goes out of range.  I did an excellent PWM speed control but discovered at the last moment that if I lost contact with the craft it maintained the last PWM duty cycle.  I had to use Tmr0 to make a about a half second timer such that if no pulses were received in that time the duty cycle was set to zero.    Good luck with the project.

Cheers,
David

joesaliba

Thanks Les, another good idea that I will try out.

David, I already have some redundancy similar to what you have.

When at my PC I will send you what I added so the code does not freeze at start up if Tx is not turned ON, so PPM signal stays low.

Practically, at the beginning of the routine, before the: -

Timer1 = 43535
Start Timer1
Repeat
    If PIR0.0 = 1 then break
Until PORTC.0 = 1

I load Timer1 with 65535 - 22000, (20000 is how long a complete PPM pulse is), so it is 43535 and check the overflow flag if pulse stays low.

This happen before I take the actual Timer reading.

Then clear Timer1, and take actual pulse reading if PIR0.0 did not overflow.

The time lost in this particular application is insignificant for me.

Does the PWM speed controller is for a brushed or brushless motor?

Regards

Joe

david

Hi Joe,
Thanks for the extra details of your code.  That appears to do the same job as my use of Tmr0 to detect the loss of signal for a given time.

The speed controller was for brushed model boat motors running at 4kHz PWM.  It had high and low throttle calibration and a highly averaged low battery sensing that cut power to 1/4 and allowed you to limp back.  I used a single low Rds ON FET, a 5V regulator and a 12F683 8 pin DIP.  Running current was around 15A but starting was getting up to near 60A.

A brushless ESC is just not worth making -I couldn't buy the 6 FETs for the price I could buy a finished 30A ESC

Cheers,
David

joesaliba

That's nice David,

I once begin an ECU for my homebuilt turbine but time.....

Joe

midali

Most actual RC transmitters have a fail safe active, any idea to detect the lost signal ? About ESC for brushed I made a speed controller with automatically throttle calibration ends . If help , I post my code in next days when I'll be home .

david

Hi Midali,
The failsafe is often set up with the tx but only the rx can decide if the signal has been lost and apply the pre-configured channel settings.  Not all rxs offer this failsafe feature and it's always important to know what the rx will do when the link is lost, particularly the throttle channel.  Joe and I have been discussing our different ways to detect a signal loss.

Your throttle calibration sounds a bit more sophisticated than mine - perhaps more like a brushless ESC.  I'm using a small tact switch to go in to initial set up mode, detecting max throttle and min throttle with an LED for confirmation.  Values are stored in EEPROM and recalled when next started up.  I also added a bit of throttle averaging to give a slight sense of inertia and avoid snap throttle changes.

Cheers,
David