Shop OBEX P1 Docs P2 Docs Learn Events
Interrupt vs If then — Parallax Forums

Interrupt vs If then

T ChapT Chap Posts: 4,223
edited 2006-09-24 17:55 in General Discussion
I am trying to learn about interrupts and have a simple application that needs either an inerrupt or and if then to halt an activity temporarily.

Here is the idea, leaving out parts of code:

SIO VAR RA.0 'receive pin
UP VAR RA.1 'motor driver inut up direction
DN VAR RA.2 'motor driver input down direction
PW VAR RA.3 'pwm out to low side of motor



serByte VAR Byte
RX_Byte SUB 0
ON CON 0
OFF CON 1

Main:

serByte = RX_byte

IF serByte = %00000001 THEN
UP = ON
PWM PW, 150, 50
UP = OFF
ENDIF

IF serByte = %00000011 THEN
DN = ON
PWM PW, 150, 50
DN = OFF
ENDIF

Goto main

This code looks for a byte from a remote control that transmits a byte in a fast loop while a button is pressed. While the button is pressed, the motor turns uninterrupted. That part is working great.

I need to add some lines in the event of a stall to prevent smoking parts. If I can make room on the board I'll add a sense circuit with logic back to the SX. In this case, would an interrupt be a better option that IF THEN for halting the output to the motors? The only other idea I can think of is IF SensePin = 1, SensePauseLoop (go to a routine, turn off motor, wait for a few seconds before returining to look for more bytes. I figure if the user notices that the thing isn't moving, they will stop presing the but rather quickly, and the pause loop will avoid the motor driver getting hot.

I am studying the 3 interrupt programs that come with the SX Key. I am stil not clear on how to set this up to look for an interrup on a pin, but will the interrupt function the same way as IF THEN on a pin?

Post Edited (originator99) : 9/24/2006 5:12:27 AM GMT

Comments

  • BeanBean Posts: 8,129
    edited 2006-09-24 15:22
    For failsafe operation, the sense circuit should prevent the PWM signal from getting to the motor driver. In otherwords, a hardware failsafe. Software is much more likely to fail (hang, etc) than hardware.

    Also the SX/B (and the BS2) PWM command is not meant for motor control. This is because it is not a single pulse for each duration. It is a series of pulses designed to be converted to an analog voltage.

    If you are using the SX48 your best bet would be to use the hardware timers to generate the PWM. Then it WILL be appropiate for a motor controller. Plus to can "set it and forget it" because the hardware timers operate on their own.

    Bean.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Cheap used 4-digit LED display with driver IC·www.hc4led.com

    Low power SD Data Logger www.sddatalogger.com
    SX-Video Display Modules www.sxvm.com

    There are only two guaranteed ways to become weathy.
    Spend less than you make.
    Make more than you spend.
    ·
  • T ChapT Chap Posts: 4,223
    edited 2006-09-24 17:55
    Thanks Bean I already used the SX for the project. I didn't look at the pwm with a scope, but it sure seems like it was dropping the speed as I reduced the duty. I had a little excess heat and was looking for a way to reduce it, and pwm command seems to have helped. The other option is a coded pwm, just toggle the pin on off per iteration with pauses to set duty.

    I am still looking for the smallest possible solution to get a logic 1 off of the sense R. I can't fit any more chips.
    638 x 474 - 62K
Sign In or Register to comment.