Shop OBEX P1 Docs P2 Docs Learn Events
SX48: Need help selecting the proper pins for my project — Parallax Forums

SX48: Need help selecting the proper pins for my project

Capt. QuirkCapt. Quirk Posts: 872
edited 2009-05-24 04:39 in General Discussion
I am building a data logger for my bicycle, and need help with deciding what timer and interrupt options would best suit the project. One pin will track the front wheel, and the other will track my pedal rotations. Between the two·pins, I will need to calculate my final drive gear ratio, mph, and pedal rpm (cadence).

I am having trouble with the timer concepts, mainly the how these pins·should be·used (one clocking pin, two capture pins and a timer output pin).

I was·planning on using a hall sensor for the front wheel and possibly using RB 4 or 5 because of their capture property (seems·similar to·the timers/pin in the propeller) and it seems like the right time to call an interrupt.

But when it comes to the pedal rpm, I have two gear tooth sensors that I can use. At first I was going to use only one to sense the·threaded portion of the pedal (threaded inside the cranks). But it would·only track 360' of pedal rotation, I believe I would need to take several rotations of the front wheel and average the data, in order to get a final drive gear ratio.

Or if I use a gear tooth sensor on the small chain ring (28 tooth) sproket, I could determine rpm and gear ratio in one rotation of the front wheel.

Either way, the pin watching the gear tooth sensor would have to count rotations or teeth between each front wheel rotation and interrupt. And eventually I would also like to track the accelleration of my right and left legs as they mash the pedals, that, I think, would require a capture pin and interrupt to measure? So possibly use pins RB4 and RB5 and activate·a second interrupt (between each gear tooth) after the rest of my code has been tested and works? Or, is it not possible to have two seperate interrupt routines at the same time?


Thanks

Bill M.


Post Edited (Capt. Quirk) : 5/17/2009 12:37:06 AM GMT

Comments

  • RS_JimRS_Jim Posts: 1,771
    edited 2009-05-17 13:13
    Bill,

    I am working on a similar project where I need to read RPM and Accelerameter.· I used a timer interupt and lifted the timer code from Gunther's book modified to store 2 digit BCD value in each byte. I then developed a tac code segement, also running in the interupt, that when it sees the passing pulse, stores a value from the timer and sets a done flag. The main code then looks for the done flag and when it finds it retreves the value of the timer stored by the tac and compairs it with the previous time.· Vola a lapse time for the revolution which can then be translated into RPM. Using hall sensors you can use as many tacs as you like and each only needs a single port pin.· The accelerameter code I developed also to run in an interupt by studying the code developed by the· PULSIN comand as compiled by SXB.· I also run that in an interupt. Since the Accelerameter is outputting a 100 Hz signal I run the interupt at least 100_000. This will give you a word value for output.· I am actually running the interupt rate at 230_400 with a 50MHz clock because I am also using a serial output routine for debugging purposes.· The final version wil use a 4MHZ clock and run with a 100K interupt and the serial code gets removed from the interupt.· I am currently using an optical tac with a comparitor on RB0,1,2 but your hall effect sensors would work just as· well (better?)and will only require 1 pin for each. ·I would share my code but it is not finished and I have a non disclosure agreement with a friend involving this code.

    rs_jim
  • BeanBean Posts: 8,129
    edited 2009-05-17 16:03
    Bill,
    I wouldn't use the timers. They cannot be read back in a normal way.
    I would create an interrupt that monitors the status of the inputs and increments variables.
    Then you can use the interrupt to measure elapesed time also.

    Bean.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    There is a fine line between arrogance and confidence. Make sure you don't cross it...

    ·
  • Capt. QuirkCapt. Quirk Posts: 872
    edited 2009-05-19 00:02
    Bean & RSJ,

    Thanks for your responses, I need some time to consider your thoughts.

    Bean: I was planning on using the timer, in place of Pulsin command that you used in your RPM code example.http://forums.parallax.com/showthread.php?p=658530·But now I will take some time to study it further.

    RSJ: I appreciate the thought about your code. I never seem to get very far in Gunthers book, I am easily distracted. Then on a few projects, I·get obsessed. You used a question mark after the Hall Sensor, I have had exprerience with both, in the·redesign of the Performance Jet Ski Hi-performance and multi spark,·ignition systems. If I can help, let me know.



    Bill


    Post Edited (Capt. Quirk) : 5/19/2009 12:07:17 AM GMT
  • RS_JimRS_Jim Posts: 1,771
    edited 2009-05-24 04:39
    Bill,

    Here is the code I use for a timer under an interupt.· The Data is all BCD.

    '
    ' Device Settings
    '

    DEVICE········· SX28, OSC4MHZ, TURBO, STACKX, OPTIONX
    FREQ··········· 50_000_000


    '
    ' IO Pins
    '


    '
    ' Constants
    '

    '
    ' Variables
    '
    Flags·VAR Byte 'usualy ends up as $0E needs to be in global bank
    AccRun·Var Flags.7
    Timing VAR Byte(16)
    usec·Var Byte @Timing(0)
    Msec·Var Byte @timing(1)
    Hsec·Var Byte @timing(2)
    Sec·Var Byte @timing (3)
    Mins·Var Byte @timing (4)
    HRS·Var Byte @timing (5)


    '
    · INTERRUPT NOPRESERVE 234_000 'FOR 50_MHz clock and serial data out
    '

    ISR_Start:
    ASM·
    ·Bank Timing···················
    · mov w, #230···; for int - 234_000
    · 'mov w,#100···;for int=100,000
    ' mov w, #10···;for int = 10,000 won't give enough resolution for accelerameter
    · dec usec·····················
    · snz··························
    ··· mov usec,w···;reload microsec timer
    · snz··························
    ·· SETB AccRun···'tells the Accelerameter to colllect data
    · Snz
    ·inc Msec····················· ;every millisec

    ·mov w, #10·················· ;was 10
    · mov w, MSec-w················ ;Z if MSec = 10
    · snz··························
    ··· clr Msec···················
    · snz··························
    ··· inc Hsec··················· ';every 1/100 sec for 1 sec
    ·mov W,#$06
    · ADD Hsec,W
    · SB DC
    · Sub Hsec,w

    · mov w, #$A0···'Hex equivalant of 100··················
    · mov w, HSec-w················ ;Z if HSec = 100
    · snz··························
    ··· clr Hsec···················
    · snz··························
    ··· inc sec··················· ; every· sec
    ·· mov W,#$06
    · ADD sec,W
    · SB DC
    · Sub sec,w
    ·
    ·mov w, #$60···················
    · mov w, Sec,-w················ ; Z if Sec = 60
    · snz··························
    · clr sec···················
    · snz··························
    ··· inc MINs···················· ; every minute
    · mov W,#$06
    · ADD MINs,W
    · SB DC
    · Sub Mins,w

    · mov w, #$60
    ···················
    · mov w, MINS-w················· ; Z if Minutes = 60
    · snz··························
    ··· clr MINS
    ··· snz·
    ·· inc HRS···················· ; every hour
    · mov W,#$06
    · ADD HRS,W
    · SB DC
    · Sub HRS,w

    · mov w, #$24
    ···················
    · mov w, HRS-w················· ; Z if hours = 24
    · snz··························
    ··· clr HRS····················

    BANK 0
    ENDASM



    ISR_Exit:
    · RETURNINT ' {cycles}

    My accelerameter also·runs under the interupt so I have to be·concerned about the interupt rate and how often the accelerameter is sampled.· with an output of 100 Hz checking the accelerameter 100,000·times per second will give you word resolution from it.

    Have fun

    ·····················

    RS_JIM
Sign In or Register to comment.