HC08 Using PWM and RTIshared

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

HC08 Using PWM and RTIshared

3,331 Views
bespenschied
Contributor III
I am having trouble using the PWM and the RTI shared beans at the same time. I am programming an HC908JL3 with CW5.1.
 
I am using the PWM with TIM0 to generate a PWM signal to control a small dc motor. This I have working ok. I also need a shared interrupt to generate an interrupt every 10ms to handle some display and Keyboard routines. I have each of these routines working seperatly. When I try to enable the PWM and the RTIshared beans at the same time I get "Error: Peripheral is already being used by the Bean PWM1". I have the 'bean uses entire timer' set to no for both beans. I have tried many different variations and have not got it to work.
 
I have searched the manual on the JL3 and found no reference that you can not use the timer module for the PWM and RTI at the same time.
 
Does anyone have any ideas? I have been working on this problem for several weeks now and can not figure it out.
 
Thanks!
Labels (1)
0 Kudos
Reply
5 Replies

798 Views
ProcessorExpert
Senior Contributor III
In my opinion, if period 10ms is the same for both devices control, you can use the PWM bean to generate output signal to control a small motor with period 10ms. 
And then use PWM's OnEnd event to generate an interrupt every 10ms to handle some display and keyboard.
I hope this help you.
Best Regards,
Jan Pospisilik, Processor Expert Support
0 Kudos
Reply

798 Views
ProcessorExpert
Senior Contributor III
You probably use buffered signal generation, please try to switch it to Unbuffered value. After switching the timer module for the PWM (TIM0 in PWM bean) and RTI (TIM1 in RTIshared bean) at the same time should work correctly as you need.
Best Regards,
Jan Pospisilik, Processor Expert Support
0 Kudos
Reply

798 Views
bespenschied
Contributor III
I am using unbuffered mode because I never change the PWM values. I have the PWM using TCH0/PTD4 to run the motor circuit. I am using TIM0 for the PWM.
 
I have the PWM set to 10ms Period and 7ms Pulse Width. With the RTIs disabled I get no errors.
 
I have the RTIs set to use TIM1, Resolution set to 10ms. When I enable the RTIs I get the error:
      Timing setting failed because of another timing settings in High Speed mode.
No matter what I set the Resolution to I keep getting the same error in the bean. I have tried timing values from 1ms all the way up to 1000ms with no luck.
 
When I go back and check the PWM bean It only allows me to select a value for the Period that is a multiple of 13.333ms. (13, 26, 53...) Again no matter what value I put into the RTIs resolution field.
 
 
 
0 Kudos
Reply

798 Views
bigmac
Specialist III
Hello,
 
What you require to do would certainly seem feasible, but the PE beans provided might not be suitable - I do not use them personally.
 
To keep the code uncomplicated, I would assume use of unbuffered PWM.  You will need to set up the TIM module so that overflow occurs every 10 ms, or perhaps a sub-multiple of this period for a higher PWM frequency.  The PWM period will be the same as the timer overflow period.  Set this by adjusting prescale and modulus values, and also taking into account the crystal frequency.
 
The PWM channel would normally be set up to "toggle on overflow", and for each output compare event to clear the PWM output.  The channel register would contain the current pulse width value.  Once set up, unbuffered PWM output will continue without the need for any interrupts - output compare interrupts are required only when the pulse width setting needs to alter, and would be disabled at other times.
 
The timer overflow interrupt would need to be remain enabled to time your periodic processing requirements.  This ISR should remain as short as possible.  If the display and keyboard routines are lengthy, it is better to do these outside of the ISR code - simply set a "flag" within the ISR, and poll the flag from within main().
 
Regards,
Mac
 
0 Kudos
Reply

798 Views
bespenschied
Contributor III
Thanks Mac,
 
I have pretty much done what you suggested. I use the beans because It takes less time to get routines working unless something like this happens. It appears that I will have to write my own routines instead of using the Beans. Even though the bean is set to share the resources, it appears that they are stingy and don't like to share.
 
brian
 
0 Kudos
Reply