I bet you tried to say " it would work fine" :) But it works fine in C, just a little tight on time. With a PIC18 it would have some more time to spare. The thing is that the timing is critical only for the lower order bit or bits, the delays are much longer for the higher order ones. If you make it work for the LSB then it will work for all the others. Isaac Em 28/08/2015 14:38, Bob Ammerman escreveu: > I bet is would work find in assembly.... > > ~ Bob Ammerman > RAm Systems > >> -----Original Message----- >> From: piclist-bounces@mit.edu [mailto:piclist-bounces@mit.edu] On Behalf >> Of Isaac Marino Bavaresco >> Sent: Friday, August 28, 2015 11:02 AM >> To: Microcontroller discussion list - Public. >> Subject: Re: [PIC] XC8 Bit Technique? >> >> I just found that my BAM() routine took more cycles than the time of the >> LSB, so it messed things up. >> >> I was using 'memcpy', that took alone 390 tcy and a loop that took 182 > cycles. >> After some code changes, the routine works OK. >> >> There was another mistake that made the delay of the previous bit being >> used, instead of the current bit. >> >> Expecting a PIC16F work OK for this application may be wishing too much. >> >> >> Isaac >> >> >> >> Em 28/08/2015 10:30, Isaac Marino Bavaresco escreveu: >>> Hi Josh! >>> >>> >>> I did not know BAM, but after I read your post I found it interesting, >>> so I wrote some code to test an idea. >>> It seems to be working OK, please see the attached file. >>> >>> >>> Cheers, >>> >>> Isaac >>> >>> >>> >>> >>> >>> Em 27/08/2015 11:10, Josh Koffman escreveu: >>>> Hi all, >>>> >>>> Amongst all the other things on my plate right now, I'd like to make >>>> a small library to do Bit Angle Modulation on some of my projects. I >>>> made one years ago in assembly, but now I'd like to do it in XC8. >>>> >>>> For reference, there are some great posts on BAM on the PicBasic forum= s >> here: >>>> http://www.picbasic.co.uk/forum/showthread.php?p=3D45597 >>>> http://www.picbasic.co.uk/forum/showthread.php?t=3D10564 >>>> >>>> Because the PIC will be doing many things, I am considering using a >>>> high priority interrupt for the BAM, but keeping my high priority ISR >>>> as small as possible (which is probably a good idea regardless). To >>>> accomplish this, I want to create the 8 "slices" that I will output >>>> in my main line, so that all the BAM ISR has to do is take that >>>> variable and put it on the port. >>>> >>>> My question is, what would be the best way to handle this in C? When >>>> I did it in assembly I used a rotate (rotate right if I remember >>>> correctly), then read the carry bit. But then I was also doing it at >>>> the moment of outputting, so there was no intermediate stored >>>> variable. >>>> >>>> My current thought is to define a typedef that lets me access the >>>> individual bits, then a bunch of if/else statements that check the >>>> bit of the source value, and if it's a 1 set the bit of the >>>> corresponding "slice" variable. This would result in a lot of if >>>> statements though, so I'm wondering if there's a slicker way to do > this. >>>> I'm trying to avoid dropping into ASM to do this for a few reasons. >>>> >>>> Any thoughts? >>>> >>>> Thanks! >>>> >>>> Josh >>> > --=20 http://www.piclist.com/techref/piclist PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist .