make logic trigger on rising edge of a bit

More
19 Apr 2014 10:41 #46101 by jmelson
I'm trying to write a HAL component to provide the logic that my PWM brush servo amps
need to come out of their disabled state. They need a small PWM pulse in each direction.
I have this logic built into the HAL driver for my PWM controller board, but some people
want to use these amps with Mesa controllers.

So, I followed the logic in the hal component flipflop.comp but I can't get it to
trigger. The state variable stays at two, even though I can see the
delayed version of the enable lagging the enable input by one
servo cycle.

I posted my component boot.hal at
pico-systems.com/codes/boot.comp

The specific problem is at line 24, the first if statement.
If it recognizes enable is 1 but the old copy of enable is
0, then it should set newstate to 0, but it appears it
does not. Anybody have any ideas?

Thanks,

Jon

Please Log in or Create an account to join the conversation.

More
19 Apr 2014 19:57 - 19 Apr 2014 23:19 #46107 by ArcEye
Hi Jon

I can't really test it at present, but I think it is down to when and where your struct is declared.

The C code shows a void pointer _data being included into struct _comp_state{} and a #define being created
#undef data
#define data (*(boot_data*)(__comp_inst->_data))


but the pointer is never set to the boot_data struct which is only declared after this.

If you substitute 2 variables (option data is now deprecated anyway) as per the attached, the actual variables become part of struct _comp_state{}
rather than an uninitialised pointer to a struct containing them.

regards
Attachments:
Last edit: 19 Apr 2014 23:19 by ArcEye.

Please Log in or Create an account to join the conversation.

More
19 Apr 2014 23:15 #46113 by jmelson

Hi Jon

I can't really test it at present, but I think it is down to when and where your struct is declared.

The C code shows a void pointer _data being included into struct _comp_state{} and a #define being created
#undef data
#define data (*(boot_data*)(__comp_inst->_data))


but the pointer is never set to the boot_data struct which is only declared after this.

/quote]
Thanks, that explains it! The oldenable was not being saved. I copied this code from
flipflop.comp, which is quite old. I likely put a line in the wrong place.
Later I wored on it some more and got
it to work by copying syntax from some newer comps.

Jon

Please Log in or Create an account to join the conversation.

Time to create page: 0.804 seconds
Powered by Kunena Forum