mc68hc11 pwm with variable duty cycle - Page 1
Forum section: electronics / general

author: legacy
author_rank: Super Contributor
timestamp: November 26, 2013, 12:21:00 am
content: hi, guysi 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 ?

author: Crazy Ape
author_rank: Regular Contributor
timestamp: November 26, 2013, 02:07:44 pm
content: 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

author: legacy
author_rank: Super Contributor
timestamp: November 26, 2013, 11:23:00 pm
content: it is not clear to me- which is the frequency- which is the duty cycle parameter

author: legacy
author_rank: Super Contributor
timestamp: November 26, 2013, 11:48:02 pm
content: 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)

author: jabramo
author_rank: Regular Contributor
timestamp: November 26, 2013, 11:53:12 pm
content: 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.

author: legacy
author_rank: Super Contributor
timestamp: November 27, 2013, 12:01:38 am
content: 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!

author: jabramo
author_rank: Regular Contributor
timestamp: November 27, 2013, 12:10:37 am
content: SentI 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

author: flanneltron
author_rank: Newbie
timestamp: November 28, 2013, 10:21:01 pm
content: Quote from: Crazy Ape on November 26, 2013, 02:07:44 pmThe code is in fact on Github:https://github.com/SynapticNulship/68HC11

author: Crazy Ape
author_rank: Regular Contributor
timestamp: November 28, 2013, 10:49:33 pm
content: Quote from: flanneltron on November 28, 2013, 10:21:01 pmHi Samuel,I couldn't see a link to it on the page, perhaps I'm blind.

author: flanneltron
author_rank: Newbie
timestamp: November 29, 2013, 12:52:04 am
content: Quote from: Crazy Ape on November 28, 2013, 10:49:33 pmGood point. I have edited my blog post to include a link to the Github repo.

author: Crazy Ape
author_rank: Regular Contributor
timestamp: November 29, 2013, 01:43:35 am
content: Quote from: flanneltron on November 29, 2013, 12:52:04 amThat's much better, thanks.

author: legacy
author_rank: Super Contributor
timestamp: November 29, 2013, 08:30:49 pm
content: with that code i got a frequency of 30 Hz, i need 1Khz at least

author: dannyf
author_rank: Super Contributor
timestamp: November 29, 2013, 10:19:57 pm
content: An AVR could have easily done that.Or even an arduino.

author: flanneltron
author_rank: Newbie
timestamp: November 30, 2013, 02:53:08 am
content: 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.pdfNote that the amount of instructions in the ISR for the TOC will affect maximum frequency.

author: legacy
author_rank: Super Contributor
timestamp: December 01, 2013, 12:53:18 am
content: thispaper 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)

author: flanneltron
author_rank: Newbie
timestamp: December 01, 2013, 02:23:13 am
content: Quote from: legacy on December 01, 2013, 12:53:18 amSure, 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.

author: legacy
author_rank: Super Contributor
timestamp: December 01, 2013, 12:45:50 pm
content: for brushless motor Apps i am usingMC68332with 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 thatHC12has specific hw to perform PWM up to 4 channels, andHC16is 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 asAtmel XmegaorSTM32(i got a Discovery F board) orInfineon 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.

author: legacy
author_rank: Super Contributor
timestamp: December 03, 2013, 04:17:41 pm
content: 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 thisCode:ldaa #0x66 ; enabling expanded modesta HPRIOany reasonable motivation and workaround for this ?

author: Crazy Ape
author_rank: Regular Contributor
timestamp: December 03, 2013, 04:28:13 pm
content: 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

author: legacy
author_rank: Super Contributor
timestamp: December 03, 2013, 04:34:45 pm
content: off course, i am using OC2 and OC3, that is portA (PA5 and PA6 pins)

author: Crazy Ape
author_rank: Regular Contributor
timestamp: December 03, 2013, 05:06:46 pm
content: Quote from: legacy on December 03, 2013, 04:34:45 pmYeah, 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.3975Are 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.

author: Crazy Ape
author_rank: Regular Contributor
timestamp: December 03, 2013, 05:25:59 pm
content: This might be of interest.Interrupts in Bootstrap Mode are different to Interrupts in Expanded ModeIf 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

author: legacy
author_rank: Super Contributor
timestamp: December 03, 2013, 07:35:12 pm
content: 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