Author Topic: mc68hc11 pwm with variable duty cycle  (Read 7877 times)

0 Members and 1 Guest are viewing this topic.

Offline legacyTopic starter

  • Super Contributor
  • ***
  • !
  • Posts: 4415
  • Country: ch
mc68hc11 pwm with variable duty cycle
« on: November 26, 2013, 12:21:00 am »
hi, guys
i am toying with this old stuff in asm, such as a mc68hc11E9 used in serial bootstrap mode.

i am looking for a good example of pwm generator with variable duty cycle, from 1% to 99% at the frequency of 5Khz f.e.

with gnu-as-11 i have realized my first led blink and uart polling, all in asm, all in serial bootstrap mode (512byte of ram for the whole, code + data + stack), anyone has played with hc11's pwm ? any good pwm code around ?
 

Offline Crazy Ape

  • Regular Contributor
  • *
  • Posts: 181
Re: mc68hc11 pwm with variable duty cycle
« Reply #1 on: November 26, 2013, 02:07:44 pm »
Attached is a pdf (Microcontroller Performance for DC Motor Speed Control System) that may give you some pointers, no code unfortunately.

There is a some ASM code on this page (Making Motors Move with PWM), but it's only partial source in screen-shot form rather than text. There may be just enough info in the screen-shot though.
http://www.science20.com/eye_brainstorm/languages_assemble-94966
 

Offline legacyTopic starter

  • Super Contributor
  • ***
  • !
  • Posts: 4415
  • Country: ch
Re: mc68hc11 pwm with variable duty cycle
« Reply #2 on: November 26, 2013, 11:23:00 pm »
it is not clear to me
- which is the frequency
- which is the duty cycle parameter
 

Offline legacyTopic starter

  • Super Contributor
  • ***
  • !
  • Posts: 4415
  • Country: ch
Re: mc68hc11 pwm with variable duty cycle
« Reply #3 on: November 26, 2013, 11:48:02 pm »
it is clear, from the documentation provided by motorola, that by changing the values of OC2hi and OC2lo you can change the period.
OC2hi should be related to Ton, and OC2lo to Toff, so, duty cycle is provided by the ratio (OC2hi)/(OC2lo + OC2hi)
 

Offline jabramo

  • Regular Contributor
  • *
  • Posts: 59
  • Country: ca
Re: mc68hc11 pwm with variable duty cycle
« Reply #4 on: November 26, 2013, 11:53:12 pm »
I have assembly that I worked on last semester that takes in a value from from 0-180 from the terminal and outputs an appropriate PWM for a servo motor and displays the angle on a HD44780. If I recall the 68HC12 only has a 8bit pwm output which is not really ideal for servo's since they take in a small duty cycle range. So my assembly uses one of the 16 bit timers to manage the PWM.

It was implemented on a on a Dragon12-Plus2 MC68HC12 board loaded with dbug12.

It's pretty specific assembly since it was for a microcomputer class assignment.

If your interested let me know and I'll PM you the code.
 

Offline legacyTopic starter

  • Super Contributor
  • ***
  • !
  • Posts: 4415
  • Country: ch
Re: mc68hc11 pwm with variable duty cycle
« Reply #5 on: November 27, 2013, 12:01:38 am »
yes, i am interested a lot, it is exactly what i am trying to do, i will arrange and adapt to hc11.
thank you a lot!
 

Offline jabramo

  • Regular Contributor
  • *
  • Posts: 59
  • Country: ca
Re: mc68hc11 pwm with variable duty cycle
« Reply #6 on: November 27, 2013, 12:10:37 am »
Sent   :)

I use a HCS12.inc it's just a peripheral bits definition file, which make's it a little easier to digest.

Anyways can be easily found if you google it
« Last Edit: November 27, 2013, 12:14:39 am by jabramo »
 

Offline flanneltron

  • Newbie
  • Posts: 4
  • Country: us
    • SynapticNulship: A Blog on AI and Interfaces
Re: mc68hc11 pwm with variable duty cycle
« Reply #7 on: November 28, 2013, 10:21:01 pm »
Attached is a pdf (Microcontroller Performance for DC Motor Speed Control System) that may give you some pointers, no code unfortunately.

There is a some ASM code on this page (Making Motors Move with PWM), but it's only partial source in screen-shot form rather than text. There may be just enough info in the screen-shot though.
http://www.science20.com/eye_brainstorm/languages_assemble-94966

The code is in fact on Github: https://github.com/SynapticNulship/68HC11
 

Offline Crazy Ape

  • Regular Contributor
  • *
  • Posts: 181
Re: mc68hc11 pwm with variable duty cycle
« Reply #8 on: November 28, 2013, 10:49:33 pm »
Attached is a pdf (Microcontroller Performance for DC Motor Speed Control System) that may give you some pointers, no code unfortunately.

There is a some ASM code on this page (Making Motors Move with PWM), but it's only partial source in screen-shot form rather than text. There may be just enough info in the screen-shot though.
http://www.science20.com/eye_brainstorm/languages_assemble-94966

The code is in fact on Github: https://github.com/SynapticNulship/68HC11

Hi Samuel,

I couldn't see a link to it on the page, perhaps I'm blind.  ;)
 

Offline flanneltron

  • Newbie
  • Posts: 4
  • Country: us
    • SynapticNulship: A Blog on AI and Interfaces
Re: mc68hc11 pwm with variable duty cycle
« Reply #9 on: November 29, 2013, 12:52:04 am »

The code is in fact on Github: https://github.com/SynapticNulship/68HC11

Hi Samuel,

I couldn't see a link to it on the page, perhaps I'm blind.  ;)

Good point. I have edited my blog post to include a link to the Github repo.
 

Offline Crazy Ape

  • Regular Contributor
  • *
  • Posts: 181
Re: mc68hc11 pwm with variable duty cycle
« Reply #10 on: November 29, 2013, 01:43:35 am »
Good point. I have edited my blog post to include a link to the Github repo.

That's much better, thanks.
 

Offline legacyTopic starter

  • Super Contributor
  • ***
  • !
  • Posts: 4415
  • Country: ch
Re: mc68hc11 pwm with variable duty cycle
« Reply #11 on: November 29, 2013, 08:30:49 pm »
with that code i got a frequency of 30 Hz, i need 1Khz at least
 

Offline dannyf

  • Super Contributor
  • ***
  • Posts: 8221
  • Country: 00
Re: mc68hc11 pwm with variable duty cycle
« Reply #12 on: November 29, 2013, 10:19:57 pm »
An AVR could have easily done that.

Or even an arduino.
================================
https://dannyelectronics.wordpress.com/
 

Offline flanneltron

  • Newbie
  • Posts: 4
  • Country: us
    • SynapticNulship: A Blog on AI and Interfaces
Re: mc68hc11 pwm with variable duty cycle
« Reply #13 on: November 30, 2013, 02:53:08 am »
You can get kilohertz output with your HC11 system. Keep in mind you don't have to use TOF. You can just use a TOC and programmatically define the period simply by how many counts high+low. E.g., see pg 35 in this document I just found by googling: http://claymore.engineer.gvsu.edu/~blaucha/68HC11/Notes/68HC11%20Notes.pdf

Note that the amount of instructions in the ISR for the TOC will affect maximum frequency.
 

Offline legacyTopic starter

  • Super Contributor
  • ***
  • !
  • Posts: 4415
  • Country: ch
Re: mc68hc11 pwm with variable duty cycle
« Reply #14 on: December 01, 2013, 12:53:18 am »
this paper is telling me about hc11 pwm used for servo purpose, so for this field is good to have a pwm frequency of 33Hz (30 msec of period)

 

Offline flanneltron

  • Newbie
  • Posts: 4
  • Country: us
    • SynapticNulship: A Blog on AI and Interfaces
Re: mc68hc11 pwm with variable duty cycle
« Reply #15 on: December 01, 2013, 02:23:13 am »
this paper is telling me about hc11 pwm used for servo purpose, so for this field is good to have a pwm frequency of 33Hz (30 msec of period)



Sure, it depend on the context. Servos are different than non-servo motors. I've done drive motor applications in the past at 5 kHz and 9kHz (using PIC micros), so it didn't surprise me that you wanted kilohertz.
 

Offline legacyTopic starter

  • Super Contributor
  • ***
  • !
  • Posts: 4415
  • Country: ch
Re: mc68hc11 pwm with variable duty cycle
« Reply #16 on: December 01, 2013, 12:45:50 pm »
for brushless motor Apps i am using MC68332 with a specific TPU that is a "Time Process Unit" which can be described as a sub CPU dedicated to time purposes. It performs well and i have 16 channels available and from the point of view of the CPU (that is a Motorola 68000 core) the TPU is a set of registers to be initialized to ask the hardware to perform a specific task, in that case "do PWM on channel X, with a frequency of Y and a duty cycle of Z", i simply pass the -do-PWM- request with {X,Y,Z} as parameters to the TPU and she performs what required !

i am reading that HC12 has specific hw to perform PWM up to 4 channels, and HC16 is much more similar to 332. Nice to know, also i can use an cpld/fpga in order to have much more and faster pwm channels. It may be a good idea, i have to evaluate for the future, but now i have to run the pretty old hc11 'cause i got pretty used boards with HC11 on it and i can't replace in the short time, so i am reversing these boards and planning to replace the hc11 with a modern chip such as Atmel Xmega or STM32 (i got a Discovery F board) or Infineon XCM4500 (i got an eval board, too, plus a full licensed version of Keil SDK for ARM plus the jtag cable "j-link").

also, and not the last point, the gnu C and assembly is very very poor about hc11, i am trying Cosmic tools for hc11 and they are light-yeas ahead !

my HC11 boards are about motor injection for sportive old cars, i got the board but not the firmware on it, i am reversing the schematic.
 

Offline legacyTopic starter

  • Super Contributor
  • ***
  • !
  • Posts: 4415
  • Country: ch
Re: mc68hc11 pwm with variable duty cycle
« Reply #17 on: December 03, 2013, 04:17:41 pm »
i have changed strategy and i get success using OC3: i am able to get a 240Hz modulated PWM with a duty cycle i can change from 1% to 99%, that's good! I am also able to get a square wave of 15Khz but … it there is an other issue i have to fix first: i am using the special serial bootstrap modo (single chip + boot loader) and i also need to use pwm in expanded mode!

the problem is: if i enable the expanded mode the pwm stops to work!

the changing consists in this
Code: [Select]
ldaa #0x66 ; enabling expanded mode
sta HPRIO

any reasonable motivation and workaround for this ?
 

Offline Crazy Ape

  • Regular Contributor
  • *
  • Posts: 181
Re: mc68hc11 pwm with variable duty cycle
« Reply #18 on: December 03, 2013, 04:28:13 pm »
What port are you doing the PWM on?

"In expanded mode, the 68HC11 uses ports B and C to address, read, and write to external memory, hence the programmer can only use PORTA and PORTD."
http://controls.ame.nd.edu/microcontroller/main/node3.html
 

Offline legacyTopic starter

  • Super Contributor
  • ***
  • !
  • Posts: 4415
  • Country: ch
Re: mc68hc11 pwm with variable duty cycle
« Reply #19 on: December 03, 2013, 04:34:45 pm »
off course, i am using OC2 and OC3, that is portA (PA5 and PA6 pins)
 

Offline Crazy Ape

  • Regular Contributor
  • *
  • Posts: 181
Re: mc68hc11 pwm with variable duty cycle
« Reply #20 on: December 03, 2013, 05:06:46 pm »
off course, i am using OC2 and OC3, that is portA (PA5 and PA6 pins)

Yeah, I should have looked at the data sheet to see what port OC2 and OC3 were on. I've never played with HC11/HC12 before.

Next silly question, do you have some code for it to run on the external bus, and in the correct memory location?

According to the datasheet, the bootrom is not available in expanded mode. The first 512bytes are common in all modes, if the HC11 can run code there, that's where I'd do the switch, then jump to the external RAM/ROM.
http://www.freescale.com/files/microcontrollers/doc/data_sheet/M68HC11E.pdf#G6.3975

Are you in the boot rom when you 'sta HPRIO'? You might be pulling the rug out from under you code so to speak.

Sorry if silly questions, as said above, I've never played with the architecture.
 

Offline Crazy Ape

  • Regular Contributor
  • *
  • Posts: 181
Re: mc68hc11 pwm with variable duty cycle
« Reply #21 on: December 03, 2013, 05:25:59 pm »
This might be of interest.

Interrupts in Bootstrap Mode are different to Interrupts in Expanded Mode
If you're using interrupts, you need play with some vectors, copy to RAM, etc.

http://www.freescale.com/files/microcontrollers/doc/ref_manual/M68HC11RM.pdf#G9.9885
 

Offline legacyTopic starter

  • Super Contributor
  • ***
  • !
  • Posts: 4415
  • Country: ch
Re: mc68hc11 pwm with variable duty cycle
« Reply #22 on: December 03, 2013, 07:35:12 pm »
that's cool, i will arrange stuff this way =)

now i am writing a sort of "talker", a code that is able to put other code everywhere in ram
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf